• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python tools.mock_xonsh_env函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tools.mock_xonsh_env函数的典型用法代码示例。如果您正苦于以下问题:Python mock_xonsh_env函数的具体用法?Python mock_xonsh_env怎么用?Python mock_xonsh_env使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了mock_xonsh_env函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_env_path

def test_env_path():
    def expand(path):
        return os.path.expanduser(os.path.expandvars(path))

    getitem_cases = [
        ('xonsh_dir', 'xonsh_dir'),
        ('.', '.'),
        ('../', '../'),
        ('~/', '~/'),
        (b'~/../', '~/../'),
    ]
    with mock_xonsh_env(TOOLS_ENV):
        for inp, exp in getitem_cases:
            obs = EnvPath(inp)[0] # call to __getitem__
            assert expand(exp) == obs

    with mock_xonsh_env(ENCODE_ENV_ONLY):
        for inp, exp in getitem_cases:
            obs = EnvPath(inp)[0] # call to __getitem__
            assert exp == obs

    # cases that involve path-separated strings
    multipath_cases = [
        (os.pathsep.join(['xonsh_dir', '../', '.', '~/']),
         ['xonsh_dir', '../', '.', '~/']),
        ('/home/wakka' + os.pathsep + '/home/jakka' + os.pathsep + '~/',
         ['/home/wakka', '/home/jakka', '~/'])
    ]
    with mock_xonsh_env(TOOLS_ENV):
        for inp, exp in multipath_cases:
            obs = [i for i in EnvPath(inp)]
            assert [expand(i) for i in exp] == obs

    with mock_xonsh_env(ENCODE_ENV_ONLY):
        for inp, exp in multipath_cases:
            obs = [i for i in EnvPath(inp)]
            assert [i for i in exp] == obs

    # cases that involve pathlib.Path objects
    pathlib_cases = [
        (pathlib.Path('/home/wakka'), ['/home/wakka'.replace('/', os.sep)]),
        (pathlib.Path('~/'), ['~']),
        (pathlib.Path('.'), ['.']),
        (['/home/wakka', pathlib.Path('/home/jakka'), '~/'],
         ['/home/wakka', '/home/jakka'.replace('/', os.sep), '~/']),
        (['/home/wakka', pathlib.Path('../'), '../'],
         ['/home/wakka', '..', '../']),
        (['/home/wakka', pathlib.Path('~/'), '~/'],
         ['/home/wakka', '~', '~/']),
    ]

    with mock_xonsh_env(TOOLS_ENV):
        for inp, exp in pathlib_cases:
            # iterate over EnvPath to acquire all expanded paths
            obs = [i for i in EnvPath(inp)]
            assert [expand(i) for i in exp] == obs
开发者ID:BlaXpirit,项目名称:xonsh,代码行数:56,代码来源:test_tools.py


示例2: test_login_shell

def test_login_shell():
    def Shell(*args, **kwargs):
        pass

    with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}):
        xonsh.main.premain([])
        assert_false(builtins.__xonsh_env__.get('XONSH_LOGIN'))

    with patch('xonsh.main.Shell', Shell), mock_xonsh_env({}):
        xonsh.main.premain(['-l'])
        assert_true(builtins.__xonsh_env__.get('XONSH_LOGIN'))
开发者ID:blink1073,项目名称:xonsh,代码行数:11,代码来源:test_main.py


示例3: test_repath_home_var_brace

def test_repath_home_var_brace():
    exp = os.path.expanduser('~')
    env = Env(HOME=exp)
    with mock_xonsh_env(env):
        obs = pathsearch(regexsearch, '${"HOME"}')
        assert 1 ==  len(obs)
        assert exp ==  obs[0]
开发者ID:BlaXpirit,项目名称:xonsh,代码行数:7,代码来源:test_builtins.py


示例4: test_histcontrol

def test_histcontrol():
    """Test HISTCONTROL=ignoredups,ignoreerr"""
    FNAME = 'xonsh-SESSIONID.json'
    FNAME += '.append'
    hist = History(filename=FNAME, here='yup', **HIST_TEST_KWARGS)

    with mock_xonsh_env({'HISTCONTROL': 'ignoredups,ignoreerr'}):
        assert len(hist.buffer) == 0

        # An error, buffer remains empty
        hist.append({'inp': 'ls foo', 'rtn': 2})
        assert len(hist.buffer) == 0

        # Success
        hist.append({'inp': 'ls foobazz', 'rtn': 0})
        assert len(hist.buffer) == 1
        assert 'ls foobazz' == hist.buffer[-1]['inp']
        assert 0 == hist.buffer[-1]['rtn']

        # Error
        hist.append({'inp': 'ls foo', 'rtn': 2})
        assert len(hist.buffer) == 1
        assert 'ls foobazz' == hist.buffer[-1]['inp']
        assert 0 == hist.buffer[-1]['rtn']

        # File now exists, success
        hist.append({'inp': 'ls foo', 'rtn': 0})
        assert len(hist.buffer) == 2
        assert 'ls foo' == hist.buffer[-1]['inp']
        assert 0 == hist.buffer[-1]['rtn']

        # Success
        hist.append({'inp': 'ls', 'rtn': 0})
        assert len(hist.buffer) == 3
        assert 'ls' == hist.buffer[-1]['inp']
        assert 0 == hist.buffer[-1]['rtn']

        # Dup
        hist.append({'inp': 'ls', 'rtn': 0})
        assert len(hist.buffer) == 3

        # Success
        hist.append({'inp': '/bin/ls', 'rtn': 0})
        assert len(hist.buffer) == 4
        assert '/bin/ls' == hist.buffer[-1]['inp']
        assert 0 == hist.buffer[-1]['rtn']

        # Error
        hist.append({'inp': 'ls bazz', 'rtn': 1})
        assert len(hist.buffer) == 4
        assert '/bin/ls' == hist.buffer[-1]['inp']
        assert 0 == hist.buffer[-1]['rtn']

        # Error
        hist.append({'inp': 'ls bazz', 'rtn': -1})
        assert len(hist.buffer) == 4
        assert '/bin/ls' == hist.buffer[-1]['inp']
        assert 0 == hist.buffer[-1]['rtn']

    os.remove(FNAME)
开发者ID:BlaXpirit,项目名称:xonsh,代码行数:60,代码来源:test_history.py


示例5: test_iglobpath

def test_iglobpath():
    with TemporaryDirectory() as test_dir:
        # Create files 00.test to 99.test in unsorted order
        num = 18
        for _ in range(100):
            s = str(num).zfill(2)
            path = os.path.join(test_dir, s + '.test')
            with open(path, 'w') as file:
                file.write(s + '\n')
            num = (num + 37) % 100

        # Create one file not matching the '*.test'
        with open(os.path.join(test_dir, '07'), 'w') as file:
            file.write('test\n')

        with mock_xonsh_env(Env(EXPAND_ENV_VARS=False)):
            builtins.__xonsh_expand_path__ = expand_path

            paths = list(iglobpath(os.path.join(test_dir, '*.test'),
                                   ignore_case=False, sort_result=False))
            assert len(paths) == 100
            paths = list(iglobpath(os.path.join(test_dir, '*'),
                                   ignore_case=True, sort_result=False))
            assert len(paths) == 101

            paths = list(iglobpath(os.path.join(test_dir, '*.test'),
                                   ignore_case=False, sort_result=True))
            assert len(paths) == 100
            assert paths == sorted(paths)
            paths = list(iglobpath(os.path.join(test_dir, '*'),
                                   ignore_case=True, sort_result=True))
            assert len(paths) == 101
            assert paths == sorted(paths)
开发者ID:BlaXpirit,项目名称:xonsh,代码行数:33,代码来源:test_tools.py


示例6: test_histcontrol

def test_histcontrol():
    """Test HISTCONTROL=ignoredups,ignoreerr"""
    FNAME = 'xonsh-SESSIONID.json'
    FNAME += '.append'
    hist = History(filename=FNAME, here='yup', **HIST_TEST_KWARGS)

    with mock_xonsh_env({'HISTCONTROL': 'ignoredups,ignoreerr'}):
        yield assert_equal, len(hist.buffer), 0

        # An error, buffer remains empty
        hist.append({'inp': 'ls foo', 'rtn': 2})
        yield assert_equal, len(hist.buffer), 0

        # Success
        hist.append({'inp': 'ls foobazz', 'rtn': 0})
        yield assert_equal, len(hist.buffer), 1
        yield assert_equal, 'ls foobazz', hist.buffer[-1]['inp']
        yield assert_equal, 0, hist.buffer[-1]['rtn']

        # Error
        hist.append({'inp': 'ls foo', 'rtn': 2})
        yield assert_equal, len(hist.buffer), 1
        yield assert_equal, 'ls foobazz', hist.buffer[-1]['inp']
        yield assert_equal, 0, hist.buffer[-1]['rtn']

        # File now exists, success
        hist.append({'inp': 'ls foo', 'rtn': 0})
        yield assert_equal, len(hist.buffer), 2
        yield assert_equal, 'ls foo', hist.buffer[-1]['inp']
        yield assert_equal, 0, hist.buffer[-1]['rtn']

        # Success
        hist.append({'inp': 'ls', 'rtn': 0})
        yield assert_equal, len(hist.buffer), 3
        yield assert_equal, 'ls', hist.buffer[-1]['inp']
        yield assert_equal, 0, hist.buffer[-1]['rtn']

        # Dup
        hist.append({'inp': 'ls', 'rtn': 0})
        yield assert_equal, len(hist.buffer), 3

        # Success
        hist.append({'inp': '/bin/ls', 'rtn': 0})
        yield assert_equal, len(hist.buffer), 4
        yield assert_equal, '/bin/ls', hist.buffer[-1]['inp']
        yield assert_equal, 0, hist.buffer[-1]['rtn']

        # Error
        hist.append({'inp': 'ls bazz', 'rtn': 1})
        yield assert_equal, len(hist.buffer), 4
        yield assert_equal, '/bin/ls', hist.buffer[-1]['inp']
        yield assert_equal, 0, hist.buffer[-1]['rtn']

        # Error
        hist.append({'inp': 'ls bazz', 'rtn': -1})
        yield assert_equal, len(hist.buffer), 4
        yield assert_equal, '/bin/ls', hist.buffer[-1]['inp']
        yield assert_equal, 0, hist.buffer[-1]['rtn']

    os.remove(FNAME)
开发者ID:SEV007,项目名称:xonsh,代码行数:60,代码来源:test_history.py


示例7: test_eval_recursive_callable_partial

def test_eval_recursive_callable_partial():
    if ON_WINDOWS:
        raise SkipTest
    built_ins.ENV = Env(HOME=os.path.expanduser('~'))
    with mock_xonsh_env(built_ins.ENV):
        assert_equal(ALIASES.get('indirect_cd')(['arg2', 'arg3']),
                     ['..', 'arg2', 'arg3'])
开发者ID:terrycloth,项目名称:xonsh,代码行数:7,代码来源:test_aliases.py


示例8: test_man_completion

def test_man_completion():
    if ON_WINDOWS:
        raise SkipTest
    with mock_xonsh_env({}):
        man_completer = ManCompleter()
        completions = man_completer.option_complete('--', 'yes')
    assert_true('--version' in completions)
    assert_true('--help' in completions)
开发者ID:DNSGeek,项目名称:xonsh,代码行数:8,代码来源:test_man.py


示例9: check_load_static_config

def check_load_static_config(s, exp, loaded):
    env = {'XONSH_SHOW_TRACEBACK': False}
    with tempfile.NamedTemporaryFile() as f, mock_xonsh_env(env):
        f.write(s)
        f.flush()
        conf = load_static_config(env, f.name)
    assert_equal(exp, conf)
    assert_equal(env['LOADED_CONFIG'], loaded)
开发者ID:kirbyfan64,项目名称:xonsh,代码行数:8,代码来源:test_environ.py


示例10: test_repath_home_contents

def test_repath_home_contents():
    home = os.path.expanduser('~')
    env = Env(HOME=home)
    with mock_xonsh_env(env):
        exp = os.listdir(home)
        exp = {os.path.join(home, p) for p in exp}
        obs = set(pathsearch(regexsearch, '~/.*'))
        assert exp ==  obs
开发者ID:BlaXpirit,项目名称:xonsh,代码行数:8,代码来源:test_builtins.py


示例11: test_man_completion

def test_man_completion():
    if ON_WINDOWS:
        raise SkipTest
    with tempfile.TemporaryDirectory() as tempdir:
        with mock_xonsh_env({'XONSH_DATA_DIR': tempdir}):
            completions = complete_from_man('--', 'yes --', 4, 6, __xonsh_env__)
        assert_true('--version' in completions)
        assert_true('--help' in completions)
开发者ID:DangerOnTheRanger,项目名称:xonsh,代码行数:8,代码来源:test_man.py


示例12: check_xonsh_ast

def check_xonsh_ast(xenv, inp, run=True, mode='eval'):
    with mock_xonsh_env(xenv):
        obs = PARSER.parse(inp, debug_level=DEBUG_LEVEL)
        if obs is None:
            return  # comment only
        bytecode = compile(obs, '<test-xonsh-ast>', mode)
        if run:
            exec(bytecode)
开发者ID:CJ-Wright,项目名称:xonsh,代码行数:8,代码来源:test_parser.py


示例13: test_repath_home_var

def test_repath_home_var():
    if ON_WINDOWS:
        raise SkipTest
    exp = os.path.expanduser('~')
    built_ins.ENV = Env(HOME=exp)
    with mock_xonsh_env(built_ins.ENV):
        obs = pathsearch(regexsearch, '$HOME')
        assert_equal(1, len(obs))
        assert_equal(exp, obs[0])
开发者ID:DangerOnTheRanger,项目名称:xonsh,代码行数:9,代码来源:test_builtins.py


示例14: test_repath_backslash

def test_repath_backslash():
    home = os.path.expanduser('~')
    env = Env(HOME=home)
    with mock_xonsh_env(env):
        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(pathsearch(regexsearch, r'~/\w\w.*'))
        assert exp ==  obs
开发者ID:BlaXpirit,项目名称:xonsh,代码行数:9,代码来源:test_builtins.py


示例15: test_repath_home_var_brace

def test_repath_home_var_brace():
    if ON_WINDOWS:
        raise SkipTest
    exp = os.path.expanduser('~')
    built_ins.ENV = Env(HOME=exp)
    with mock_xonsh_env(built_ins.ENV):
        obs = regexpath('${"HOME"}')
        assert_equal(1, len(obs))
        assert_equal(exp, obs[0])
开发者ID:CJ-Wright,项目名称:xonsh,代码行数:9,代码来源:test_builtins.py


示例16: test_repath_home_contents

def test_repath_home_contents():
    if ON_WINDOWS:
        raise SkipTest
    home = os.path.expanduser('~')
    built_ins.ENV = Env(HOME=home)
    with mock_xonsh_env(built_ins.ENV):
        exp = os.listdir(home)
        exp = {os.path.join(home, p) for p in exp}
        obs = set(regexpath('~/.*'))
        assert_equal(exp, obs)
开发者ID:CJ-Wright,项目名称:xonsh,代码行数:10,代码来源:test_builtins.py


示例17: test_login_shell

def test_login_shell():
    def Shell(*args, **kwargs):
        pass

    with patch("xonsh.main.Shell", Shell), mock_xonsh_env({}):
        xonsh.main.premain([])
        assert_true(builtins.__xonsh_env__.get("XONSH_LOGIN"))

    with patch("xonsh.main.Shell", Shell), mock_xonsh_env({}):
        xonsh.main.premain(["-l", "-c", 'echo "hi"'])
        assert_true(builtins.__xonsh_env__.get("XONSH_LOGIN"))

    with patch("xonsh.main.Shell", Shell), mock_xonsh_env({}):
        xonsh.main.premain(["-c", 'echo "hi"'])
        assert_false(builtins.__xonsh_env__.get("XONSH_LOGIN"))

    with patch("xonsh.main.Shell", Shell), mock_xonsh_env({}):
        xonsh.main.premain(["-l"])
        assert_true(builtins.__xonsh_env__.get("XONSH_LOGIN"))
开发者ID:asmeurer,项目名称:xonsh,代码行数:19,代码来源:test_main.py


示例18: test_hist_append

def test_hist_append():
    """Verify appending to the history works."""
    FNAME = 'xonsh-SESSIONID.json'
    FNAME += '.append'
    hist = History(filename=FNAME, here='yup', **HIST_TEST_KWARGS)
    with mock_xonsh_env({'HISTCONTROL': set()}):
        hf = hist.append({'joco': 'still alive'})
    yield assert_is_none, hf
    yield assert_equal, 'still alive', hist.buffer[0]['joco']
    os.remove(FNAME)
开发者ID:SEV007,项目名称:xonsh,代码行数:10,代码来源:test_history.py


示例19: check_load_static_config

def check_load_static_config(s, exp, loaded):
    env = Env({'XONSH_SHOW_TRACEBACK': False})
    f = tempfile.NamedTemporaryFile(delete=False)
    with mock_xonsh_env(env):
        f.write(s)
        f.close()
        conf = load_static_config(env, f.name)
    os.unlink(f.name)
    assert_equal(exp, conf)
    assert_equal(env['LOADED_CONFIG'], loaded)
开发者ID:cryzed,项目名称:xonsh,代码行数:10,代码来源:test_environ.py


示例20: test_repath_backslash

def test_repath_backslash():
    if ON_WINDOWS:
        raise SkipTest
    home = os.path.expanduser('~')
    built_ins.ENV = Env(HOME=home)
    with mock_xonsh_env(built_ins.ENV):
        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)
开发者ID:CJ-Wright,项目名称:xonsh,代码行数:11,代码来源:test_builtins.py



注:本文中的tools.mock_xonsh_env函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python tools.new_node函数代码示例发布时间:2022-05-27
下一篇:
Python tools.mkdir函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap