当前位置: 首页>>代码示例>>Python>>正文


Python test.mock函数代码示例

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


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

示例1: test_list_of_aspects

def test_list_of_aspects():
    with aspectlib.weave(module_func, [mock('foobar'), record]):
        assert module_func(1, 2, 3) == 'foobar'
        assert module_func.calls == [(None, (1, 2, 3), {})]

    with aspectlib.weave(module_func, [mock('foobar', call=True), record]):
        raises(TypeError, module_func, 1, 2, 3)
        assert module_func.calls == [(None, (1, 2, 3), {})]
开发者ID:ionelmc,项目名称:python-aspectlib,代码行数:8,代码来源:test_aspectlib.py

示例2: test_fixture_2

def test_fixture_2(weave):
    assert Foo().bar() == 1

    with weave(Foo.bar, test.mock(2)):
        assert Foo().bar() == 2

    assert Foo().bar() == 1
开发者ID:ionelmc,项目名称:python-aspectlib,代码行数:7,代码来源:test_pytestsupport.py

示例3: test_weave_str_class_meth_target

def test_weave_str_class_meth_target():
    with aspectlib.weave('test_pkg1.test_pkg2.test_mod.Stuff.meth', mock('foobar')):
        from test_pkg1.test_pkg2.test_mod import Stuff
        assert Stuff().meth() == 'foobar'

    from test_pkg1.test_pkg2.test_mod import Stuff
    assert Stuff().meth() is None
开发者ID:ionelmc,项目名称:python-aspectlib,代码行数:7,代码来源:test_aspectlib.py

示例4: test_weave_class_meth_no_aliases_unsupported_on_py3

def test_weave_class_meth_no_aliases_unsupported_on_py3():
    with aspectlib.weave(Global.meth, mock("stuff")):
        assert Global().meth() == "stuff"
        assert Global2().meth() == "stuff"

    assert Global().meth() == "base"
    assert Global2().meth() == "base"
开发者ID:nedbat,项目名称:python-aspectlib,代码行数:7,代码来源:test_aspectlib.py

示例5: test_weave_old_style_method_no_warn_patch_module

def test_weave_old_style_method_no_warn_patch_module():
    calls = []
    with aspectlib.weave('warnings.warn', record(calls=calls)):
        with aspectlib.weave('test_aspectlib.LegacyTestClass.foobar', mock('stuff')):
            assert LegacyTestClass().foobar() == 'stuff'

    assert calls == []
开发者ID:ionelmc,项目名称:python-aspectlib,代码行数:7,代码来源:test_aspectlib.py

示例6: test_weave_multiple

def test_weave_multiple():
    with aspectlib.weave((module_func, module_func2), mock('foobar')):
        assert module_func() == 'foobar'
        assert module_func2() == 'foobar'

    assert module_func() is None
    assert module_func2() is None
开发者ID:ionelmc,项目名称:python-aspectlib,代码行数:7,代码来源:test_aspectlib.py

示例7: test_weave_str_target

def test_weave_str_target():
    with aspectlib.weave('test_pkg1.test_pkg2.test_mod.target', mock('foobar')):
        from test_pkg1.test_pkg2.test_mod import target
        assert target() == 'foobar'

    from test_pkg1.test_pkg2.test_mod import target
    assert target() is None
开发者ID:ionelmc,项目名称:python-aspectlib,代码行数:7,代码来源:test_aspectlib.py

示例8: test_weave_missing_global

def test_weave_missing_global(cls=Global):
    global Global
    Global = 'crap'
    try:
        raises(AssertionError, aspectlib.weave, cls, mock('stuff'), lazy=True)
    finally:
        Global = cls
开发者ID:ionelmc,项目名称:python-aspectlib,代码行数:7,代码来源:test_aspectlib.py

示例9: test_weave_no_aliases

def test_weave_no_aliases():
    with aspectlib.weave(module_func2, mock('stuff'), aliases=False):
        assert module_func2() == 'stuff'
        assert module_func2 is not module_func3
        assert module_func3() is None

    assert module_func2() is None
    assert module_func3() is None
    assert module_func2 is module_func3
开发者ID:ionelmc,项目名称:python-aspectlib,代码行数:9,代码来源:test_aspectlib.py

示例10: test_weave_class_meth_no_aliases

def test_weave_class_meth_no_aliases():
    with aspectlib.weave(Global.meth, mock("stuff"), aliases=False, lazy=True):
        assert Global().meth() == "stuff"
        assert Global2 is not Global
        assert Global2().meth() == "base"

    assert Global().meth() == "base"
    assert Global2 is Global
    assert Global2().meth() == "base"
开发者ID:nedbat,项目名称:python-aspectlib,代码行数:9,代码来源:test_aspectlib.py

示例11: test_weave_class_no_aliases

def test_weave_class_no_aliases():
    with aspectlib.weave(Global, mock('stuff'), aliases=False, lazy=True):
        assert Global().meth() == 'stuff'
        assert Global2 is not Global
        assert Global2().meth() == 'base'

    assert Global().meth() == 'base'
    assert Global2 is Global
    assert Global2().meth() == 'base'
开发者ID:ionelmc,项目名称:python-aspectlib,代码行数:9,代码来源:test_aspectlib.py

示例12: test_weave_wrong_module

def test_weave_wrong_module():
    calls = []
    with aspectlib.weave('warnings.warn', record(calls=calls)):
        aspectlib.weave(AliasedGlobal, mock('stuff'), lazy=True)
    assert calls == [
        (None,
         ("Setting test_aspectlib.MissingGlobal to <class 'test_aspectlib.MissingGlobal'>. "
          "There was no previous definition, probably patching the wrong module.",),
         {})
    ]
开发者ID:ionelmc,项目名称:python-aspectlib,代码行数:10,代码来源:test_aspectlib.py

示例13: test_fork

def test_fork():
    with aspectlib.weave('os.fork', mock('foobar')):
        pid = os.fork()
        if not pid:
            os._exit(0)
        assert pid == 'foobar'

    pid = os.fork()
    if not pid:
        os._exit(0)
    assert pid != 'foobar'
开发者ID:ionelmc,项目名称:python-aspectlib,代码行数:11,代码来源:test_integrations.py

示例14: test_invalid_string_target

def test_invalid_string_target():
    raises(SyntaxError, aspectlib.weave, "inva lid", mock(None))
    raises(SyntaxError, aspectlib.weave, "os.inva lid", mock(None))
    raises(SyntaxError, aspectlib.weave, "os.2invalid", mock(None))
    raises(SyntaxError, aspectlib.weave, "os.some,junk", mock(None))
    raises(SyntaxError, aspectlib.weave, "os.some?junk", mock(None))
    raises(SyntaxError, aspectlib.weave, "os.some*junk", mock(None))

    with aspectlib.weave("test_aspectlib._internal", mock("stuff")):
        assert _internal() == "stuff"
开发者ID:nedbat,项目名称:python-aspectlib,代码行数:10,代码来源:test_aspectlib.py

示例15: test_weave_bad_args5

def test_weave_bad_args5():
    raises(TypeError, aspectlib.weave, Sub, mock('stuff'), methods=False)
开发者ID:ionelmc,项目名称:python-aspectlib,代码行数:2,代码来源:test_aspectlib.py


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