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


Python MagicMock.name方法代码示例

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


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

示例1: test_modify_trump_duration_with_filter

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import name [as 别名]
def test_modify_trump_duration_with_filter(player):  # noqa: F811
    player._revert_to_default = MagicMock()
    tower = MagicMock()
    tower.name = 'Tower'
    tower.duration = 2
    tower.temporary = False
    blizzard = MagicMock()
    blizzard.name = 'Blizzard'
    blizzard.duration = 4
    blizzard.temporary = False
    ram = MagicMock()
    ram.name = 'Ram'
    ram.duration = 0
    ram.temporary = True
    # Note: the trump that modifies the durations in in the affecting trumps list
    player._affecting_trumps = [tower, blizzard, ram]

    player.modify_affecting_trump_durations(-2, filter_=lambda trump: trump.name == 'Tower')

    assert tower.duration == 0
    assert blizzard.duration == 4
    assert player._affecting_trumps == [blizzard]
    assert player._revert_to_default.called
    # The tower is not available any more
    assert not tower.affect.called
    assert blizzard.affect.called
    # The ram must not be enabled again or we will enter an infinite loop that will call
    # player.modify_affecting_trump_durations again.
    assert not ram.affect.called
开发者ID:arenaoftitans,项目名称:arena-of-titans-api,代码行数:31,代码来源:test_player.py

示例2: test_images

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import name [as 别名]
def test_images(monkeypatch):
    image = MagicMock()
    image.id = "ami-123"
    image.name = "BrandNewImage"
    image.creationDate = datetime.datetime.utcnow().isoformat("T") + "Z"

    old_image_still_used = MagicMock()
    old_image_still_used.id = "ami-456"
    old_image_still_used.name = "OldImage"
    old_image_still_used.creationDate = (datetime.datetime.utcnow() - datetime.timedelta(days=30)).isoformat("T") + "Z"

    instance = MagicMock()
    instance.id = "i-777"
    instance.image_id = "ami-456"
    instance.tags = {"aws:cloudformation:stack-name": "mystack"}

    ec2 = MagicMock()
    ec2.get_all_images.return_value = [image, old_image_still_used]
    ec2.get_only_instances.return_value = [instance]
    monkeypatch.setattr("boto.cloudformation.connect_to_region", lambda x: MagicMock())
    monkeypatch.setattr("boto.ec2.connect_to_region", lambda x: ec2)
    monkeypatch.setattr("boto.iam.connect_to_region", lambda x: MagicMock())

    runner = CliRunner()

    with runner.isolated_filesystem():
        result = runner.invoke(cli, ["images", "--region=myregion"], catch_exceptions=False)

    assert "ami-123" in result.output
    assert "ami-456" in result.output
    assert "mystack" in result.output
开发者ID:twz123,项目名称:senza,代码行数:33,代码来源:test_cli.py

示例3: test_modify_trump_duration

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import name [as 别名]
def test_modify_trump_duration(player):  # noqa: F811
    player._revert_to_default = MagicMock()
    tower = MagicMock()
    tower.name = 'Tower'
    tower.duration = 2
    tower.temporary = False
    blizzard = MagicMock()
    blizzard.name = 'Blizzard'
    blizzard.duration = 4
    blizzard.temporary = False
    ram = MagicMock()
    ram.name = 'Ram'
    ram.duration = 0
    ram.temporary = True
    # Note: the trump that modifies the durations in in the affecting trumps list
    player._affecting_trumps = [tower, blizzard, ram]

    player.modify_affecting_trump_durations(-2)

    assert tower.duration == 0
    assert blizzard.duration == 2
    assert player.affecting_trumps == (blizzard,)
    # Trumps must be disabled then re-enabled to take into account the changes.
    assert player._revert_to_default.called
    # The tower is not available any more
    assert not tower.affect.called
    assert blizzard.affect.called
    # The ram must not be enabled again or we will enter an infinite loop that will call
    # player.modify_affecting_trump_durations again.
    assert not ram.affect.called
开发者ID:arenaoftitans,项目名称:arena-of-titans-api,代码行数:32,代码来源:test_player.py

示例4: test_print_auto

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import name [as 别名]
def test_print_auto(monkeypatch):
    images = [MagicMock(name='Taupage-AMI-123', id='ami-123')]

    zone = MagicMock()
    zone.name = 'zo.ne'
    cert = {'server_certificate_name': 'zo-ne', 'arn': 'arn:aws:123'}
    cert_response = {
        'list_server_certificates_response': {'list_server_certificates_result': {'server_certificate_metadata_list': [
            cert
        ]}}}

    sg = MagicMock()
    sg.name = 'app-sg'
    sg.id = 'sg-007'

    monkeypatch.setattr('boto.cloudformation.connect_to_region', lambda x: MagicMock())
    monkeypatch.setattr('boto.vpc.connect_to_region', lambda x: MagicMock())
    monkeypatch.setattr('boto.iam.connect_to_region', lambda x: MagicMock(list_server_certs=lambda: cert_response))
    monkeypatch.setattr('boto.route53.connect_to_region', lambda x: MagicMock(get_zones=lambda: [zone]))
    monkeypatch.setattr('boto.ec2.connect_to_region', lambda x: MagicMock(get_all_images=lambda filters: images,
                                                                          get_all_security_groups=lambda: [sg]))

    sns = MagicMock()
    topic = {'TopicArn': 'arn:123:mytopic'}
    sns.get_all_topics.return_value = {'ListTopicsResponse': {'ListTopicsResult': {'Topics': [topic]}}}
    monkeypatch.setattr('boto.sns.connect_to_region', MagicMock(return_value=sns))

    data = {'SenzaInfo': {'StackName': 'test',
                          'OperatorTopicId': 'mytopic',
                          'Parameters': [{'ImageVersion': {'Description': ''}}]},
            'SenzaComponents': [{'Configuration': {'Type': 'Senza::StupsAutoConfiguration'}},
                                {'AppServer': {'Type': 'Senza::TaupageAutoScalingGroup',
                                               'ElasticLoadBalancer': 'AppLoadBalancer',
                                               'InstanceType': 't2.micro',
                                               'TaupageConfig': {'runtime': 'Docker',
                                                                 'source': 'foo/bar:{{Arguments.ImageVersion}}'},
                                               'IamRoles': ['app-myrole'],
                                               'SecurityGroups': ['app-sg', 'sg-123'],
                                               'AutoScaling':
                                                   {'Minimum': 1,
                                                    'Maximum': 10,
                                                    'MetricType': 'CPU'}}},
                                {'AppLoadBalancer': {'Type': 'Senza::WeightedDnsElasticLoadBalancer',
                                                     'HTTPPort': 8080,
                                                     'SecurityGroups': ['app-sg']}}]}

    runner = CliRunner()

    with runner.isolated_filesystem():
        with open('myapp.yaml', 'w') as fd:
            yaml.dump(data, fd)

        result = runner.invoke(cli, ['print', 'myapp.yaml', '--region=myregion', '123', '1.0-SNAPSHOT'],
                               catch_exceptions=False)

    assert 'AWSTemplateFormatVersion' in result.output
    assert 'subnet-123' in result.output
    assert 'source: foo/bar:1.0-SNAPSHOT' in result.output
    assert '"HealthCheckType": "ELB"' in result.output
开发者ID:a1exsh,项目名称:senza,代码行数:61,代码来源:test_cli.py

示例5: setup_class

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import name [as 别名]
    def setup_class(cls):
        service1 = MagicMock()
        service1.name = "service1"

        service1.fleet_service_instances = {"[email protected]": None, "[email protected]": None}
        service2 = MagicMock()
        service2.name = "service2"

        service2.fleet_service_instances = {"[email protected]": None, "[email protected]": None, "[email protected]": None}
        cls.service_dict = {"service1": service1, "service2": service2}
开发者ID:oezs,项目名称:dynamite,代码行数:12,代码来源:test_RunningServicesRegistry.py

示例6: product_with_images

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import name [as 别名]
def product_with_images(product_type, default_category):
    product = Product.objects.create(
        name='Test product', price=Money('10.00', 'USD'),
        product_type=product_type, category=default_category)
    file_mock_0 = MagicMock(spec=File, name='FileMock0')
    file_mock_0.name = 'image0.jpg'
    file_mock_1 = MagicMock(spec=File, name='FileMock1')
    file_mock_1.name = 'image1.jpg'
    product.images.create(image=file_mock_0)
    product.images.create(image=file_mock_1)
    return product
开发者ID:zach-luman,项目名称:saleor,代码行数:13,代码来源:conftest.py

示例7: test_is_agent

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import name [as 别名]
def test_is_agent():
    someclass = SomeClass("agent smith")
    assert someclass.name == "agent smith"
    assert app.is_agent(someclass) == True

    # try using mock
    mock = MagicMock()
    mock.name = "agent brown"
    bad_mock = MagicMock()
    bad_mock.name = "tom brown"
    assert mock.name == "agent brown"
    assert app.is_agent(mock) == True
    assert bad_mock.name == "tom brown"
    assert app.is_agent(bad_mock) == False
开发者ID:oliveryuen,项目名称:Experiments,代码行数:16,代码来源:test_app.py

示例8: test_loop

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import name [as 别名]
    def test_loop(self):
        group1 = MagicMock()
        group1.name = "group1"
        group2 = MagicMock()
        group2.name = "group2"
        group3 = MagicMock()
        group3.name = "group3"

        group3.subgroups = [group2]
        group2.subgroups = [group1]
        group1.subgroups = [group3]

        with self.assertRaises(RuntimeError):
            _flatten_group_hierarchy([group1, group2, group3])
开发者ID:bkendinibilir,项目名称:bundlewrap,代码行数:16,代码来源:node_tests.py

示例9: test_reorder_short_chain

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import name [as 别名]
    def test_reorder_short_chain(self):
        group1 = MagicMock()
        group1.name = "group1"
        group2 = MagicMock()
        group2.name = "group2"
        group3 = MagicMock()
        group3.name = "group3"

        group3.subgroups = [group2]
        group2.subgroups = []
        group1.subgroups = []

        order = _flatten_group_hierarchy([group1, group2, group3])
        self.assertTrue(order.index("group3") < order.index("group2"))
开发者ID:bkendinibilir,项目名称:bundlewrap,代码行数:16,代码来源:node_tests.py

示例10: test_affect_modify_affecting_trump_durations_with_filter_

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import name [as 别名]
def test_affect_modify_affecting_trump_durations_with_filter_(player):  # noqa: F811
    trump = ModifyTrumpDurations(delta_duration=-1, duration=1, trump_names=['Tower'])
    tower = MagicMock()
    tower.name = 'Tower'
    tower.duration = 1
    blizzard = MagicMock()
    blizzard.name = 'Blizzard'
    blizzard.duration = 1
    player._affecting_trumps = [tower, blizzard]

    trump.affect(player)

    assert tower.duration == 0
    assert blizzard.duration == 1
    assert player._affecting_trumps == [blizzard]
开发者ID:arenaoftitans,项目名称:arena-of-titans-api,代码行数:17,代码来源:test_trumps.py

示例11: test_affect_modify_card_number_moves_with_filter_

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import name [as 别名]
def test_affect_modify_card_number_moves_with_filter_(player):  # noqa: F811
    player.modify_card_number_moves = MagicMock()
    trump = ModifyCardNumberMoves(delta_moves=1, duration=1, card_names=['Queen'])
    queen = MagicMock()
    queen.name = 'Queen'
    king = MagicMock()
    king.name = 'King'

    trump.affect(player)

    assert player.modify_card_number_moves.called
    assert player.modify_card_number_moves.call_args[0][0] == 1
    assert callable(player.modify_card_number_moves.call_args[1]['filter_'])
    filter_ = player.modify_card_number_moves.call_args[1]['filter_']
    assert filter_(queen)
    assert not filter_(king)
开发者ID:arenaoftitans,项目名称:arena-of-titans-api,代码行数:18,代码来源:test_trumps.py

示例12: test_store_retrieve

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import name [as 别名]
def test_store_retrieve():
    fake_gun = MagicMock()
    fake_gun.name = 'fakegun'
    inv = inventory.Inventory()
    inv.store(fake_gun)
    retrieved_gun = inv.retrieve('fakegun')
    assert fake_gun is retrieved_gun
开发者ID:asm-products,项目名称:spaceship-build,代码行数:9,代码来源:test_inventory.py

示例13: test_update_projector_overlay

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import name [as 别名]
    def test_update_projector_overlay(self, mock_ProjectorSocketHandler,
                                      mock_get_overlays):
        mock_overlay = MagicMock()
        mock_overlay.name = 'mock_overlay_name'
        mock_overlay.get_projector_html.return_value = 'mock_html_code'
        mock_overlay.get_javascript.return_value = 'mock_javascript'
        mock_get_overlays.return_value = {'mock_overlay': mock_overlay}

        # Test with active overlay
        mock_overlay.is_active.return_value = False
        projector_api.update_projector_overlay(None)
        mock_ProjectorSocketHandler.send_updates.assert_called_with(
            {'overlays': {'mock_overlay_name': None}})

        # Test with active overlay
        mock_overlay.is_active.return_value = True
        projector_api.update_projector_overlay(None)
        expected_data = {'overlays': {'mock_overlay_name': {
            'html': 'mock_html_code',
            'javascript': 'mock_javascript'}}}
        mock_ProjectorSocketHandler.send_updates.assert_called_with(expected_data)

        # Test with overlay name as argument
        projector_api.update_projector_overlay('mock_overlay')
        mock_ProjectorSocketHandler.send_updates.assert_called_with(expected_data)

        # Test with overlay object as argument
        projector_api.update_projector_overlay(mock_overlay)
        mock_ProjectorSocketHandler.send_updates.assert_called_with(expected_data)
开发者ID:DebVortex,项目名称:OpenSlides,代码行数:31,代码来源:test_api.py

示例14: test_get_overlays_inactive

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import name [as 别名]
 def test_get_overlays_inactive(self, mock_projector_overlays):
     mock_overlay = MagicMock()
     mock_overlay.name = 'mock_overlay_2'
     mock_overlay.is_active.return_value = False
     mock_projector_overlays.send.return_value = ((None, mock_overlay), )
     value = projector_api.get_overlays(only_active=True)
     self.assertNotEqual(value, {'mock_overlay_2': mock_overlay})
开发者ID:DebVortex,项目名称:OpenSlides,代码行数:9,代码来源:test_api.py

示例15: test_print_account_info

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import name [as 别名]
def test_print_account_info(monkeypatch):
    sg = MagicMock()
    sg.name = 'app-master-mind'
    sg.id = 'sg-007'

    boto3 = MagicMock()
    boto3.get_user.return_value = {'User': {'Arn': 'arn:aws:iam::0123456789:user/admin'}}
    boto3.list_account_aliases.return_value = {'AccountAliases': ['org-dummy']}

    monkeypatch.setattr('boto3.client', MagicMock(return_value=boto3))
    monkeypatch.setattr('boto.cloudformation.connect_to_region', lambda x: MagicMock())
    monkeypatch.setattr('boto.ec2.connect_to_region', lambda x: MagicMock(get_all_security_groups=lambda: [sg]))
    monkeypatch.setattr('boto.iam.connect_to_region', lambda x: MagicMock())
    data = {'SenzaComponents': [{'Configuration': {'ServerSubnets': {'eu-west-1': ['subnet-123']},
                                                   'Type': 'Senza::Configuration'}},
                                {'AppServer': {'Image': 'AppImage-{{AccountInfo.TeamID}}-{{AccountInfo.AccountID}}',
                                               'InstanceType': 't2.micro',
                                               'TaupageConfig': {'runtime': 'Docker',
                                                                 'source': 'foo/bar'},
                                               'Type': 'Senza::TaupageAutoScalingGroup'}}],
            'SenzaInfo': {'StackName': 'test-{{AccountInfo.Region}}'}}

    runner = CliRunner()

    with runner.isolated_filesystem():
        with open('myapp.yaml', 'w') as fd:
            yaml.dump(data, fd)

        result = runner.invoke(cli, ['print', 'myapp.yaml', '--region=myregion', '123'],
                               catch_exceptions=False)
    assert 'test-myregion' in result.output
    assert 'AppImage-dummy-0123456789' in result.output
开发者ID:ehartung,项目名称:senza,代码行数:34,代码来源:test_cli.py


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