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


Python Cassette.use方法代码示例

本文整理汇总了Python中vcr.cassette.Cassette.use方法的典型用法代码示例。如果您正苦于以下问题:Python Cassette.use方法的具体用法?Python Cassette.use怎么用?Python Cassette.use使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在vcr.cassette.Cassette的用法示例。


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

示例1: test_nesting_context_managers_by_checking_references_of_http_connection

# 需要导入模块: from vcr.cassette import Cassette [as 别名]
# 或者: from vcr.cassette.Cassette import use [as 别名]
def test_nesting_context_managers_by_checking_references_of_http_connection():
    original = httplib.HTTPConnection
    with Cassette.use(path='test'):
        first_cassette_HTTPConnection = httplib.HTTPConnection
        with Cassette.use(path='test'):
            second_cassette_HTTPConnection = httplib.HTTPConnection
            assert second_cassette_HTTPConnection is not first_cassette_HTTPConnection
            with Cassette.use(path='test'):
                assert httplib.HTTPConnection is not second_cassette_HTTPConnection
                with force_reset():
                    assert httplib.HTTPConnection is original
            assert httplib.HTTPConnection is second_cassette_HTTPConnection
        assert httplib.HTTPConnection is first_cassette_HTTPConnection
开发者ID:IvanMalison,项目名称:vcrpy,代码行数:15,代码来源:test_cassettes.py

示例2: test_custom_patchers

# 需要导入模块: from vcr.cassette import Cassette [as 别名]
# 或者: from vcr.cassette.Cassette import use [as 别名]
def test_custom_patchers():
    class Test(object):
        attribute = None

    with Cassette.use(path="custom_patches", custom_patches=((Test, "attribute", VCRHTTPSConnection),)):
        assert issubclass(Test.attribute, VCRHTTPSConnection)
        assert VCRHTTPSConnection is not Test.attribute
        old_attribute = Test.attribute

        with Cassette.use(path="custom_patches", custom_patches=((Test, "attribute", VCRHTTPSConnection),)):
            assert issubclass(Test.attribute, VCRHTTPSConnection)
            assert VCRHTTPSConnection is not Test.attribute
            assert Test.attribute is not old_attribute

        assert issubclass(Test.attribute, VCRHTTPSConnection)
        assert VCRHTTPSConnection is not Test.attribute
        assert Test.attribute is old_attribute
开发者ID:teury,项目名称:vcrpy,代码行数:19,代码来源:test_cassettes.py

示例3: test_nesting_cassette_context_managers

# 需要导入模块: from vcr.cassette import Cassette [as 别名]
# 或者: from vcr.cassette.Cassette import use [as 别名]
def test_nesting_cassette_context_managers(*args):
    first_response = {"body": {"string": b"first_response"}, "headers": {}, "status": {"message": "m", "code": 200}}

    second_response = copy.deepcopy(first_response)
    second_response["body"]["string"] = b"second_response"

    with contextlib.ExitStack() as exit_stack:
        first_cassette = exit_stack.enter_context(Cassette.use(path="test"))
        exit_stack.enter_context(mock.patch.object(first_cassette, "play_response", return_value=first_response))
        assert_get_response_body_is("first_response")

        # Make sure a second cassette can supercede the first
        with Cassette.use(path="test") as second_cassette:
            with mock.patch.object(second_cassette, "play_response", return_value=second_response):
                assert_get_response_body_is("second_response")

        # Now the first cassette should be back in effect
        assert_get_response_body_is("first_response")
开发者ID:teury,项目名称:vcrpy,代码行数:20,代码来源:test_cassettes.py

示例4: test_nesting_cassette_context_managers

# 需要导入模块: from vcr.cassette import Cassette [as 别名]
# 或者: from vcr.cassette.Cassette import use [as 别名]
def test_nesting_cassette_context_managers(*args):
    first_response = {'body': {'string': b'first_response'}, 'headers': {},
                      'status': {'message': 'm', 'code': 200}}

    second_response = copy.deepcopy(first_response)
    second_response['body']['string'] = b'second_response'

    with contextlib.ExitStack() as exit_stack:
        first_cassette = exit_stack.enter_context(Cassette.use(path='test'))
        exit_stack.enter_context(mock.patch.object(first_cassette, 'play_response',
                                                    return_value=first_response))
        assert_get_response_body_is('first_response')

        # Make sure a second cassette can supercede the first
        with Cassette.use(path='test') as second_cassette:
            with mock.patch.object(second_cassette, 'play_response', return_value=second_response):
                assert_get_response_body_is('second_response')

        # Now the first cassette should be back in effect
        assert_get_response_body_is('first_response')
开发者ID:IvanMalison,项目名称:vcrpy,代码行数:22,代码来源:test_cassettes.py

示例5: test_function_decorated_with_use_cassette_can_be_invoked_multiple_times

# 需要导入模块: from vcr.cassette import Cassette [as 别名]
# 或者: from vcr.cassette.Cassette import use [as 别名]
def test_function_decorated_with_use_cassette_can_be_invoked_multiple_times(*args):
    decorated_function = Cassette.use(path='test')(make_get_request)
    for i in range(4):
         decorated_function()
开发者ID:IvanMalison,项目名称:vcrpy,代码行数:6,代码来源:test_cassettes.py

示例6: test_path_transformer_with_context_manager

# 需要导入模块: from vcr.cassette import Cassette [as 别名]
# 或者: from vcr.cassette.Cassette import use [as 别名]
def test_path_transformer_with_context_manager():
    with Cassette.use(
        path='b', path_transformer=lambda *args: 'a'
    ) as cassette:
        assert cassette._path == 'a'
开发者ID:IvanMalison,项目名称:vcrpy,代码行数:7,代码来源:test_cassettes.py

示例7: test_path_transformer_None

# 需要导入模块: from vcr.cassette import Cassette [as 别名]
# 或者: from vcr.cassette.Cassette import use [as 别名]
def test_path_transformer_None():
    with Cassette.use(
        path='a', path_transformer=None,
    ) as cassette:
        assert cassette._path == 'a'
开发者ID:koobs,项目名称:vcrpy,代码行数:7,代码来源:test_cassettes.py

示例8: test_path_transformer_with_context_manager

# 需要导入模块: from vcr.cassette import Cassette [as 别名]
# 或者: from vcr.cassette.Cassette import use [as 别名]
def test_path_transformer_with_context_manager():
    with Cassette.use(path="b", path_transformer=lambda *args: "a") as cassette:
        assert cassette._path == "a"
开发者ID:teury,项目名称:vcrpy,代码行数:5,代码来源:test_cassettes.py


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