mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
windows: clarify that regex globbing with backslashes unavailable on windows. Add test to verify it on non-windows.
This commit is contained in:
parent
10b84320c7
commit
1b0c1f291f
2 changed files with 18 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
|||
"""Tests the xonsh lexer."""
|
||||
from __future__ import unicode_literals, print_function
|
||||
import os
|
||||
import re
|
||||
|
||||
import nose
|
||||
from nose.tools import assert_equal, assert_true, assert_not_in
|
||||
|
@ -8,6 +9,7 @@ from nose.tools import assert_equal, assert_true, assert_not_in
|
|||
from xonsh import built_ins
|
||||
from xonsh.built_ins import Env, reglob, regexpath, helper, superhelper, \
|
||||
ensure_list_of_strs
|
||||
from xonsh.tools import ON_WINDOWS
|
||||
|
||||
def test_env_normal():
|
||||
env = Env(VAR='wakka')
|
||||
|
@ -42,6 +44,15 @@ def test_reglob_tests():
|
|||
for f in testfiles:
|
||||
assert_true(f.startswith('test_'))
|
||||
|
||||
if not ON_WINDOWS:
|
||||
def test_repath_backslash():
|
||||
home = os.path.expanduser('~')
|
||||
exp = os.listdir(home)
|
||||
exp = {p for p in exp if re.match(r'\w\w.*', p)}
|
||||
exp = {os.path.join(home, p) for p in exp}
|
||||
obs = set(regexpath(r'~/\w\w.*'))
|
||||
assert_equal(exp, obs)
|
||||
|
||||
def test_repath_home_itself():
|
||||
exp = os.path.expanduser('~')
|
||||
obs = regexpath('~')
|
||||
|
|
|
@ -17,7 +17,7 @@ from collections import Sequence, MutableMapping, Iterable, namedtuple, \
|
|||
MutableSequence, MutableSet
|
||||
|
||||
from xonsh.tools import string_types, redirect_stdout, redirect_stderr
|
||||
from xonsh.tools import suggest_commands, XonshError, ON_POSIX
|
||||
from xonsh.tools import suggest_commands, XonshError, ON_POSIX, ON_WINDOWS
|
||||
from xonsh.inspectors import Inspector
|
||||
from xonsh.environ import default_env
|
||||
from xonsh.aliases import DEFAULT_ALIASES, bash_aliases
|
||||
|
@ -273,7 +273,12 @@ def reglob(path, parts=None, i=None):
|
|||
base = ''
|
||||
elif len(parts) > 1:
|
||||
i += 1
|
||||
regex = re.compile(os.path.join(base, parts[i]).replace('\\', '\\\\'))
|
||||
regex = os.path.join(base, parts[i])
|
||||
if ON_WINDOWS:
|
||||
# currently unable to access regex backslash sequences
|
||||
# on Windows due to paths using \.
|
||||
regex = regex.replace('\\', '\\\\')
|
||||
regex = re.compile(regex)
|
||||
files = os.listdir(subdir)
|
||||
files.sort()
|
||||
paths = []
|
||||
|
|
Loading…
Add table
Reference in a new issue