mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
'test_builtins'
This commit is contained in:
parent
cc9d558e75
commit
2f2f1622c9
3 changed files with 46 additions and 45 deletions
|
@ -17,11 +17,6 @@ test_aliases.py
|
|||
- migrate TestWhich
|
||||
|
||||
|
||||
test_builtins.py
|
||||
----------------
|
||||
- Env fixture
|
||||
|
||||
|
||||
test_dirstack.py
|
||||
----------------
|
||||
- better way for chdir contextmanager?
|
||||
|
|
|
@ -18,38 +18,36 @@ from tools import skip_if_on_windows
|
|||
HOME_PATH = os.path.expanduser('~')
|
||||
|
||||
|
||||
def test_reglob_tests():
|
||||
testfiles = reglob('test_.*')
|
||||
for f in testfiles:
|
||||
assert (f.startswith('test_'))
|
||||
@pytest.mark.parametrize('testfile', [*reglob('test_.*')])
|
||||
def test_reglob_tests(testfile):
|
||||
assert (testfile.startswith('test_'))
|
||||
|
||||
# @pytest.fixture
|
||||
# def env():
|
||||
# e = Env(HOME=os.path.expanduser('~'))
|
||||
# built_ins.ENV = e
|
||||
# return e
|
||||
|
||||
@pytest.fixture
|
||||
def home_env(xonsh_builtins):
|
||||
xonsh_builtins.__xonsh_env__ = Env(HOME=HOME_PATH)
|
||||
return xonsh_builtins
|
||||
|
||||
|
||||
@skip_if_on_windows
|
||||
@pytest.mark.parametrize('xenv', [Env(HOME=HOME_PATH)])
|
||||
def test_repath_backslash(xonsh_env):
|
||||
def test_repath_backslash(home_env):
|
||||
exp = os.listdir(HOME_PATH)
|
||||
exp = {p for p in exp if re.match(r'\w\w.*', p)}
|
||||
exp = {os.path.join(HOME_PATH, p) for p in exp}
|
||||
obs = set(pathsearch(regexsearch, r'~/\w\w.*'))
|
||||
assert exp == obs
|
||||
|
||||
|
||||
@skip_if_on_windows
|
||||
@pytest.mark.parametrize('xenv', [Env(HOME=os.path.expanduser('~'))])
|
||||
def test_repath_HOME_PATH_itself(xonsh_env):
|
||||
def test_repath_HOME_PATH_itself(home_env):
|
||||
exp = HOME_PATH
|
||||
obs = pathsearch(regexsearch, '~')
|
||||
assert 1 == len(obs)
|
||||
assert exp == obs[0]
|
||||
|
||||
|
||||
@skip_if_on_windows
|
||||
@pytest.mark.parametrize('xenv', [Env(HOME=os.path.expanduser('~'))])
|
||||
def test_repath_HOME_PATH_contents(xonsh_env):
|
||||
def test_repath_HOME_PATH_contents(home_env):
|
||||
exp = os.listdir(HOME_PATH)
|
||||
exp = {os.path.join(HOME_PATH, p) for p in exp}
|
||||
obs = set(pathsearch(regexsearch, '~/.*'))
|
||||
|
@ -57,49 +55,60 @@ def test_repath_HOME_PATH_contents(xonsh_env):
|
|||
|
||||
|
||||
@skip_if_on_windows
|
||||
@pytest.mark.parametrize('xenv', [Env(HOME=os.path.expanduser('~'))])
|
||||
def test_repath_HOME_PATH_var(xonsh_env):
|
||||
def test_repath_HOME_PATH_var(home_env):
|
||||
exp = HOME_PATH
|
||||
obs = pathsearch(regexsearch, '$HOME')
|
||||
assert 1 == len(obs)
|
||||
assert exp == obs[0]
|
||||
|
||||
|
||||
@skip_if_on_windows
|
||||
@pytest.mark.parametrize('xenv', [Env(HOME=os.path.expanduser('~'))])
|
||||
def test_repath_HOME_PATH_var_brace(xonsh_env):
|
||||
def test_repath_HOME_PATH_var_brace(home_env):
|
||||
exp = HOME_PATH
|
||||
obs = pathsearch(regexsearch, '${"HOME"}')
|
||||
assert 1 == len(obs)
|
||||
assert exp == obs[0]
|
||||
|
||||
|
||||
def test_helper_int(xonsh_env):
|
||||
def test_helper_int(home_env):
|
||||
helper(int, 'int')
|
||||
|
||||
def test_helper_helper(xonsh_env):
|
||||
def test_helper_helper(home_env):
|
||||
helper(helper, 'helper')
|
||||
|
||||
def test_helper_env(xonsh_env):
|
||||
def test_helper_env(home_env):
|
||||
helper(Env, 'Env')
|
||||
|
||||
def test_superhelper_int(xonsh_env):
|
||||
def test_superhelper_int(home_env):
|
||||
superhelper(int, 'int')
|
||||
|
||||
def test_superhelper_helper(xonsh_env):
|
||||
def test_superhelper_helper(home_env):
|
||||
superhelper(helper, 'helper')
|
||||
|
||||
def test_superhelper_env(xonsh_env):
|
||||
def test_superhelper_env(home_env):
|
||||
superhelper(Env, 'Env')
|
||||
|
||||
def test_ensure_list_of_strs():
|
||||
cases = [(['yo'], 'yo'), (['yo'], ['yo']), (['42'], 42), (['42'], [42])]
|
||||
for exp, inp in cases:
|
||||
obs = ensure_list_of_strs(inp)
|
||||
assert exp == obs
|
||||
|
||||
def test_list_of_strs_or_callables():
|
||||
f = lambda x: 20
|
||||
cases = [(['yo'], 'yo'), (['yo'], ['yo']), (['42'], 42), (['42'], [42]),
|
||||
([f], f), ([f], [f])]
|
||||
for exp, inp in cases:
|
||||
obs = list_of_strs_or_callables(inp)
|
||||
assert exp == obs
|
||||
@pytest.mark.parametrize('exp, inp', [
|
||||
(['yo'], 'yo'),
|
||||
(['yo'], ['yo']),
|
||||
(['42'], 42),
|
||||
(['42'], [42])
|
||||
])
|
||||
def test_ensure_list_of_strs(exp, inp):
|
||||
obs = ensure_list_of_strs(inp)
|
||||
assert exp == obs
|
||||
|
||||
|
||||
f = lambda x: 20
|
||||
@pytest.mark.parametrize('exp, inp', [
|
||||
(['yo'], 'yo'),
|
||||
(['yo'], ['yo']),
|
||||
(['42'], 42),
|
||||
(['42'], [42]),
|
||||
([f], f),
|
||||
([f], [f])
|
||||
])
|
||||
def test_list_of_strs_or_callables(exp, inp):
|
||||
obs = list_of_strs_or_callables(inp)
|
||||
assert exp == obs
|
||||
|
|
|
@ -25,10 +25,7 @@ def chdir(adir):
|
|||
os.chdir(old_dir)
|
||||
|
||||
|
||||
# @pytest.mark.skip(reason='BUG')
|
||||
def test_simple(xonsh_builtins):
|
||||
# load_builtins()
|
||||
# with xonsh_env(Env(CDPATH=PARENT, PWD=PARENT)):
|
||||
xonsh_builtins.__xonsh_env__ = Env(CDPATH=PARENT, PWD=PARENT)
|
||||
with chdir(PARENT):
|
||||
assert os.getcwd() != HERE
|
||||
|
|
Loading…
Add table
Reference in a new issue