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


Python MagicMock.assert_any_call方法代码示例

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


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

示例1: test_resolve_categories_for_rooms

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_any_call [as 别名]
   def test_resolve_categories_for_rooms(self):

      should_be_called  = MagicMock(return_value = True)
      all_rooms         = self.generate_rooms_with_text("Some text")
      with patch("__main__.DXFRoomCatsResolver._resolve_category_for_room", should_be_called):
         r = DXFRoomCatsResolver._resolve_categories_for_rooms(
            all_rooms,
            self.cats
         )

         # 3 matches
         self.assertEqual(r, 3)

         for r in all_rooms:
            MagicMock.assert_any_call(
               should_be_called,
               r,
               self.cats
            )

         self.assertEqual(should_be_called.call_count, len(all_rooms))

      # Now we ensure it counts correctly the amount of rooms matched
      should_be_called  = MagicMock(side_effect = [True, False, False])
      with patch("__main__.DXFRoomCatsResolver._resolve_category_for_room", should_be_called):
         r = DXFRoomCatsResolver._resolve_categories_for_rooms(
            all_rooms,
            self.cats
         )

         # 1 match
         self.assertEqual(r, 1)
开发者ID:khamusa,项目名称:spazi-unimi,代码行数:34,代码来源:dxf_room_cats_resolver_test.py

示例2: test_allowed_user_convert

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_any_call [as 别名]
    def test_allowed_user_convert(self, users, previous_users, expected_users):
        key_str = 'allowed_users_str'
        key = 'allowed_users'

        # Configure mock
        name_validator = MagicMock()
        conv_val.toolkit.get_validator = MagicMock(return_value=name_validator)
        
        # Fullfill the data dictionary
        # * list should be included in the allowed_users filed
        # * strings should be included in the allowed_users_str field
        if isinstance(users, basestring):
            data_key = key_str
        else:
            data_key = key

        data = {(data_key,): users}

        for i in range(0, previous_users):
            data[(key, i)] = i

        # Call the function
        context = {'user': 'test', 'auth_obj_id': {'id': 1}}
        conv_val.allowed_users_convert((key,), data, {}, context)

        # Check that the users are set properly
        for i in range(previous_users, previous_users + len(expected_users)):
            name_validator.assert_any_call(expected_users[i - previous_users], context)
            self.assertEquals(expected_users[i - previous_users], data[(key, i)])
开发者ID:Aaron-M,项目名称:ckanext-privatedatasets,代码行数:31,代码来源:test_converters_validators.py

示例3: test_resolve_room_categories

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_any_call [as 别名]
   def test_resolve_room_categories(self):
      a_floor = MagicMock()

      should_be_called  = MagicMock(return_value = True)
      cats              = MagicMock(return_value = "cats_result")
      class_ns          = "__main__.DXFRoomCatsResolver"

      with patch(class_ns+".get_room_categories_dict", cats):
         with patch(class_ns+"._resolve_room_categories_for_floor", should_be_called):
            # Chiamata 1 - un solo floor, passato come parametro
            r = DXFRoomCatsResolver.resolve_room_categories(MagicMock(), a_floor)

            self.assertEqual(r, 1)
            MagicMock.assert_called_once_with(cats)

            MagicMock.assert_called_once_with(
               should_be_called,
               a_floor,
               "cats_result",
            )

            MagicMock.reset_mock(should_be_called)
            b = {
               "dxf": { "floors": ["firstfloor", "secondfloor", "thirdfloor"] }
            }
            r = DXFRoomCatsResolver.resolve_room_categories(b)

            for f in b["dxf"]["floors"]:
               MagicMock.assert_any_call(
                  should_be_called,
                  f,
                  "cats_result"
            )

            self.assertEqual(r, 3)
开发者ID:khamusa,项目名称:spazi-unimi,代码行数:37,代码来源:dxf_room_cats_resolver_test.py

示例4: test_check_if_command_exits_when_fixture_path_does_not_exist

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_any_call [as 别名]
    def test_check_if_command_exits_when_fixture_path_does_not_exist(
            self, os_path_exists_mock: MagicMock) -> None:
        os_path_exists_mock.return_value = False

        with self.assertRaises(SystemExit):
            call_command(self.COMMAND_NAME, fixture=self.fixture_path, url=self.url)

        os_path_exists_mock.assert_any_call(os.path.join(settings.DEPLOY_ROOT, self.fixture_path))
开发者ID:BakerWang,项目名称:zulip,代码行数:10,代码来源:test_management_commands.py

示例5: test_parallel_execution_without_arguments

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_any_call [as 别名]
    def test_parallel_execution_without_arguments(self):
        # Fixture
        func = MagicMock()

        # Test
        self.sut.parallel(func)

        # Assert
        for uri, mock in self.factory.mocks.items():
            func.assert_any_call(mock)
开发者ID:bitcraze,项目名称:crazyflie-lib-python,代码行数:12,代码来源:test_swarm.py

示例6: file_import_test

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_any_call [as 别名]
    def file_import_test(self):
        """
        Test the actual import of real song files and check that the imported data is correct.
        """

        # GIVEN: Test files with a mocked out SongImport class, a mocked out "manager", a mocked out "import_wizard",
        #       and mocked out "author", "add_copyright", "add_verse", "finish" methods.
        with patch('openlp.plugins.songs.lib.ewimport.SongImport'), \
            patch('openlp.plugins.songs.lib.ewimport.retrieve_windows_encoding') as mocked_retrieve_windows_encoding:
            mocked_retrieve_windows_encoding.return_value = 'cp1252'
            mocked_manager = MagicMock()
            mocked_import_wizard = MagicMock()
            mocked_add_author = MagicMock()
            mocked_add_verse = MagicMock()
            mocked_finish = MagicMock()
            mocked_title = MagicMock()
            mocked_finish.return_value = True
            importer = EasyWorshipSongImportLogger(mocked_manager)
            importer.import_wizard = mocked_import_wizard
            importer.stop_import_flag = False
            importer.addAuthor = mocked_add_author
            importer.addVerse = mocked_add_verse
            importer.title = mocked_title
            importer.finish = mocked_finish
            importer.topics = []

            # WHEN: Importing each file
            importer.import_source = os.path.join(TEST_PATH, 'Songs.DB')

            # THEN: doImport should return none, the song data should be as expected, and finish should have been
            #       called.
            self.assertIsNone(importer.doImport(), 'doImport should return None when it has completed')
            for song_data in SONG_TEST_DATA:
                print mocked_title.mocked_calls()
                title = song_data['title']
                author_calls = song_data['authors']
                song_copyright = song_data['copyright']
                ccli_number = song_data['ccli_number']
                add_verse_calls = song_data['verses']
                verse_order_list = song_data['verse_order_list']
                self.assertIn(title, importer._title_assignment_list, 'title for %s should be "%s"' % (title, title))
                for author in author_calls:
                    mocked_add_author.assert_any_call(author)
                if song_copyright:
                    self.assertEqual(importer.copyright, song_copyright)
                if ccli_number:
                    self.assertEquals(importer.ccliNumber, ccli_number, 'ccliNumber for %s should be %s'
                                                                        % (title, ccli_number))
                for verse_text, verse_tag in add_verse_calls:
                    mocked_add_verse.assert_any_call(verse_text, verse_tag)
                if verse_order_list:
                    self.assertEquals(importer.verseOrderList, verse_order_list, 'verseOrderList for %s should be %s'
                                                                   % (title, verse_order_list))
                mocked_finish.assert_called_with()
开发者ID:marmyshev,项目名称:item_title,代码行数:56,代码来源:test_ewimport.py

示例7: test_scan

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_any_call [as 别名]
 def test_scan(self, connect_mock, tpl_mock):
     self.maxDiff = None
     now = '2013-09-20 11:48:33'
     tpl_mock.return_value = {
         'status': 'unknown',
         'date': now,
         'plugin': 'ssh_cisco_asa',
         'messages': [],
     }
     ip = '10.10.10.10'
     asa_ssh_mock = MagicMock()
     command_mock = MagicMock()
     asa_ssh_mock.asa_command = command_mock
     command_mock.side_effect = cisco_asa_ssh_mock
     connect_mock.return_value = asa_ssh_mock
     correct_ret = {
         'status': 'success',
         'plugin': 'ssh_cisco_asa',
         'messages': [],
         'device': {
             'model_name': 'Cisco SOME_ASA_MODEL',
             'type': 'firewall',
             'serial_number': 'SOME-SN',
             'mac_addresses': [
                 u'AB12BC235556',
                 u'AB12BC235558',
                 u'DEF113DE4567',
                 u'DEF113DE4566',
                 u'DEF113DE5677',
                 u'DEF113DE5676',
                 u'DEF113DE6785',
                 u'DEF113DE6784',
             ],
             'boot_firmware': 'SOME-BOOT-FIRMWARE',
             'management_ip_addresses': [ip, ],
             'memory': [{
                 'size': 12288,
             }],
             'processors': [{
                 'family': 'AMD Opteron',
                 'model_name': 'AMD Opteron',
                 'speed': 2600,
             }],
         },
     }
     ret = ssh_cisco_asa.scan_address(ip, snmp_name='Cisco Software:UCOS')
     correct_ret['date'] = ret['date']  # assuming datetime is working.
     self.assertEqual(ret, correct_ret)
     command_mock.assert_any_call(
         "show version | grep (^Hardware|Boot microcode|^Serial|address is)",
     )
     self.assertEqual(command_mock.call_count, 1)
开发者ID:4i60r,项目名称:ralph,代码行数:54,代码来源:test_ssh_cisco_asa.py

示例8: test_delAttr

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_any_call [as 别名]
    def test_delAttr(self):
        """
        You can delete attributes.
        """
        ev = MagicMock()
        world = World(ev)
        obj = world.create('foo')
        world.setAttr(obj['id'], 'foo', 'bar')
        ev.reset_mock()

        world.delAttr(obj['id'], 'foo')
        ev.assert_any_call(AttrDel(obj['id'], 'foo'))
        self.assertNotIn('foo', world.get(obj['id']))
开发者ID:iffy,项目名称:xatrobots,代码行数:15,代码来源:test_world.py

示例9: test_setAttr

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_any_call [as 别名]
    def test_setAttr(self):
        """
        You can set the value of an attribute.
        """
        ev = MagicMock()
        world = World(ev)
        obj = world.create('foo')

        ev.reset_mock()
        world.setAttr(obj['id'], 'foo', 'bar')

        ev.assert_any_call(AttrSet(obj['id'], 'foo', 'bar'))
        obj = world.get(obj['id'])
        self.assertEqual(obj['foo'], 'bar')
开发者ID:iffy,项目名称:xatrobots,代码行数:16,代码来源:test_world.py

示例10: test_log_call_accepts_callable

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_any_call [as 别名]
    def test_log_call_accepts_callable(self, logging):
        """flog.flog.log_sensitive_call: Accepts a callable and calls it as if it were a logger function"""

        my_logger = MagicMock()

        randoa = random.randint(0, 500)
        randob = random.randint(0, 500)
        randoc = random.randint(0, 500)

        # SUT
        flog.log_sensitive_call(my_logger)(my_fun)(randoa, randob, randoc, random_frippery_scale=32)

        my_logger.assert_any_call("test_log_call.my_fun: args: *XXXXXX, kwargs: **XXXXXXX")
        my_logger.assert_any_call("test_log_call.my_fun: returns: XXXXXXXXXX")
开发者ID:mitgr81,项目名称:flog,代码行数:16,代码来源:test_log_call.py

示例11: test_snapshot

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_any_call [as 别名]
 def test_snapshot(self):
     pvc_driver = self._driver
     pvc_driver._service.snapshot = MagicMock()
     context = MagicMock()
     instance = 1
     image_id = 1
     update_task_state = MagicMock()
     pvc_driver.snapshot(context, instance, image_id,
                         update_task_state)
     update_task_state.assert_any_call(
                         task_state=task_states.IMAGE_PENDING_UPLOAD)
     update_task_state.assert_any_call(
                         task_state=task_states.IMAGE_UPLOADING,
                         expected_state=task_states.IMAGE_PENDING_UPLOAD)
开发者ID:gpanda,项目名称:powervc-driver,代码行数:16,代码来源:test_driver.py

示例12: test_filter_trace

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_any_call [as 别名]
    def test_filter_trace(self):
        mock_filter = MagicMock()
        self.mf.filter = mock_filter
        mock_filter.side_effect = cycle([[sentinel.filtered_even] * 2,
                                         [sentinel.filtered_odd] * 2,
                                         [sentinel.filtered_recombined]])
        trace_segment = [sentinel.trace_even, sentinel.trace_odd]

        filtered_trace = self.mf.filter_trace(trace_segment * 4)

        self.assertEqual(filtered_trace, [sentinel.filtered_recombined])
        mock_filter.assert_any_call([sentinel.trace_even] * 4)
        mock_filter.assert_any_call([sentinel.trace_odd] * 4)
        mock_filter.assert_called_with([sentinel.filtered_even, sentinel.filtered_odd] * 2)
开发者ID:HiSPARC,项目名称:sapphire,代码行数:16,代码来源:test_process_traces.py

示例13: test_removeItem

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_any_call [as 别名]
    def test_removeItem(self):
        """
        You can remove items from a list
        """
        ev = MagicMock()
        world = World(ev)
        obj = world.create('foo')
        world.addItem(obj['id'], 'foo', 'bar')
        
        ev.reset_mock()
        world.removeItem(obj['id'], 'foo', 'bar')

        ev.assert_any_call(ItemRemoved(obj['id'], 'foo', 'bar'))
        self.assertEqual(world.get(obj['id'])['foo'], [])
开发者ID:iffy,项目名称:xatrobots,代码行数:16,代码来源:test_world.py

示例14: test_validator_call

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_any_call [as 别名]
 def test_validator_call(self):
     validator = MagicMock()
     attr_val = {
         'attr1': validator,
         'attr2': validator,
     }
     with patch('bundlewrap.items.symlinks.ATTRIBUTE_VALIDATORS', new=attr_val):
         symlinks.Symlink.validate_attributes(
             MagicMock(),
             "symlink:/foo",
             {'attr1': 1, 'attr2': 2},
         )
     validator.assert_any_call("symlink:/foo", 1)
     validator.assert_any_call("symlink:/foo", 2)
     self.assertEqual(validator.call_count, 2)
开发者ID:mfriedenhagen,项目名称:bundlewrap,代码行数:17,代码来源:symlinks_tests.py

示例15: test_addItem

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_any_call [as 别名]
    def test_addItem(self):
        """
        You can add items to a list
        """
        ev = MagicMock()
        world = World(ev)
        obj = world.create('foo')

        ev.reset_mock()
        world.addItem(obj['id'], 'foo', 'bar')

        ev.assert_any_call(ItemAdded(obj['id'], 'foo', 'bar'))

        obj = world.get(obj['id'])
        self.assertEqual(obj['foo'], ['bar'])
开发者ID:iffy,项目名称:xatrobots,代码行数:17,代码来源:test_world.py


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