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


Python Munch.copy方法代码示例

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


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

示例1: test_copy

# 需要导入模块: from munch import Munch [as 别名]
# 或者: from munch.Munch import copy [as 别名]
def test_copy():
    m = Munch(urmom=Munch(sez=Munch(what='what')))
    c = m.copy()
    assert c is not m
    assert c.urmom is not m.urmom
    assert c.urmom.sez is not m.urmom.sez
    assert c.urmom.sez.what == 'what'
    assert c == m
开发者ID:Infinidat,项目名称:munch,代码行数:10,代码来源:test_munch.py

示例2: test_full_cycle_adapt_balance

# 需要导入模块: from munch import Munch [as 别名]
# 或者: from munch.Munch import copy [as 别名]
def test_full_cycle_adapt_balance(
        session: Session,
        api_endpoint_address: str,
        token_address: str,
        channel_manager_address: str,
        receiver_address: str
):
    # Simulate a lost balance signature.
    client = session.client
    channel = client.get_suitable_channel(receiver_address, 10, initial_deposit=lambda x: 2 * x)
    channel.create_transfer(3)
    lost_balance_sig = channel.balance_sig
    channel.update_balance(0)

    with requests_mock.mock(real_http=True) as server_mock:
        headers1 = Munch()
        headers1.token_address = token_address
        headers1.contract_address = channel_manager_address
        headers1.receiver_address = receiver_address
        headers1.price = '7'

        headers2 = headers1.copy()
        headers2.invalid_amount = '1'
        headers2.sender_balance = '3'
        headers2.balance_signature = encode_hex(lost_balance_sig)

        headers3 = Munch()
        headers3.cost = '7'

        headers1 = HTTPHeaders.serialize(headers1)
        headers2 = HTTPHeaders.serialize(headers2)
        headers3 = HTTPHeaders.serialize(headers3)

        url = 'http://{}/something'.format(api_endpoint_address)
        server_mock.get(url, [
            {'status_code': 402, 'headers': headers1},
            {'status_code': 402, 'headers': headers2},
            {'status_code': 200, 'headers': headers3, 'text': 'success'}
        ])

        response = session.get(url)

    # Filter out any requests made to the ethereum node.
    request_history = [request for request in server_mock.request_history if request.port == 5000]

    # First cycle, request price.
    request = request_history[0]
    assert request.path == '/something'
    assert request.method == 'GET'
    assert request.headers['RDN-Contract-Address'] == channel_manager_address

    # Second cycle, pay price based on outdated balance.
    request = request_history[1]
    assert request.path == '/something'
    assert request.method == 'GET'
    assert request.headers['RDN-Contract-Address'] == channel_manager_address
    assert request.headers['RDN-Balance'] == '7'
    assert request.headers['RDN-Balance-Signature']

    # Third cycle, adapt new balance and pay price again.
    request = request_history[2]
    assert request.path == '/something'
    assert request.method == 'GET'
    assert request.headers['RDN-Contract-Address'] == channel_manager_address
    assert request.headers['RDN-Balance'] == '10'

    assert session.channel.balance == 10
    balance_sig_hex = encode_hex(session.channel.balance_sig)
    assert request.headers['RDN-Balance-Signature'] == balance_sig_hex
    assert session.channel.balance_sig
    assert response.text == 'success'
开发者ID:AlphaX-IBS,项目名称:microraiden,代码行数:73,代码来源:test_session.py

示例3: test_copy

# 需要导入模块: from munch import Munch [as 别名]
# 或者: from munch.Munch import copy [as 别名]
def test_copy():
    m = Munch(urmom=Munch(sez=Munch(what='what')))
    c = m.copy()
    assert c.urmom.sez.what == 'what'
开发者ID:scls19fr,项目名称:munch,代码行数:6,代码来源:test_munch.py


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