本文整理汇总了Python中unittest.mock.Mock.find_item方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.find_item方法的具体用法?Python Mock.find_item怎么用?Python Mock.find_item使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.mock.Mock
的用法示例。
在下文中一共展示了Mock.find_item方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_find_rlinks
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import find_item [as 别名]
def test_find_rlinks(self):
"""Verify an item's reverse links can be found."""
mock_document_p = Mock()
mock_document_p.prefix = 'RQ'
mock_document_c = Mock()
mock_document_c.parent = 'RQ'
mock_item = Mock()
mock_item.id = 'TST001'
mock_item.links = ['RQ001']
def mock_iter(self): # pylint: disable=W0613
"""Mock Tree.__iter__ to yield a mock Document."""
def mock_iter2(self): # pylint: disable=W0613
"""Mock Document.__iter__ to yield a mock Item."""
yield mock_item
mock_document_c.__iter__ = mock_iter2
yield mock_document_c
self.item.add_link('fake1')
mock_tree = Mock()
mock_tree.__iter__ = mock_iter
mock_tree.find_item = lambda identifier: Mock(id='fake1')
rlinks, childrem = self.item.find_rlinks(mock_document_p, mock_tree)
self.assertEqual(['TST001'], rlinks)
self.assertEqual([mock_document_c], childrem)
示例2: test_valid_both_no_reverse_links
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import find_item [as 别名]
def test_valid_both_no_reverse_links(self):
"""Verify an item can be checked against both (no reverse links)."""
def mock_iter(self): # pylint: disable=W0613
"""Mock Tree.__iter__ to yield a mock Document."""
mock_document = Mock()
mock_document.parent = 'RQ'
def mock_iter2(self): # pylint: disable=W0613
"""Mock Document.__iter__ to yield a mock Item."""
mock_item = Mock()
mock_item.id = 'TST001'
mock_item.links = []
yield mock_item
mock_document.__iter__ = mock_iter2
yield mock_document
self.item.add_link('fake1')
mock_document = Mock()
mock_document.prefix = 'RQ'
mock_tree = Mock()
mock_tree.__iter__ = mock_iter
mock_tree.find_item = lambda identifier: Mock(id='fake1')
self.assertTrue(self.item.valid(document=mock_document,
tree=mock_tree))
示例3: test_validate_tree
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import find_item [as 别名]
def test_validate_tree(self):
"""Verify an item can be checked against a tree."""
def mock_iter(self): # pylint: disable=W0613
"""Mock Tree.__iter__ to yield a mock Document."""
mock_document = Mock()
mock_document.parent = 'RQ'
def mock_iter2(self): # pylint: disable=W0613
"""Mock Document.__iter__ to yield a mock Item."""
mock_item = Mock()
mock_item.uid = 'TST001'
mock_item.links = ['RQ001']
yield mock_item
mock_document.__iter__ = mock_iter2
yield mock_document
self.item.link('fake1')
mock_tree = Mock()
mock_tree.__iter__ = mock_iter
mock_tree.find_item = lambda uid: Mock(uid='fake1')
self.item.tree = mock_tree
self.assertTrue(self.item.validate())
示例4: test_file_yml
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import find_item [as 别名]
def test_file_yml(self, mock_add_item):
"""Verify a YAML file can be imported."""
path = os.path.join(FILES, 'exported.yml')
mock_document = Mock()
mock_document.find_item = Mock(side_effect=DoorstopError)
# Act
importer._file_yml(path, mock_document) # pylint: disable=W0212
# Assert
self.assertEqual(5, mock_add_item.call_count)
示例5: test_parent_items_unknown
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import find_item [as 别名]
def test_parent_items_unknown(self):
"""Verify 'parent_items' can handle unknown items."""
mock_tree = Mock()
mock_tree.find_item = Mock(side_effect=DoorstopError)
self.item.tree = mock_tree
self.item.links = ['mock_uid']
# Act
items = self.item.parent_items
# Assert
self.assertIsInstance(items[0], UnknownItem)
示例6: test_parent_items
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import find_item [as 别名]
def test_parent_items(self):
"""Verify 'parent_items' exists to mirror the child behavior."""
mock_tree = Mock()
mock_tree.find_item = Mock(return_value='mock_item')
self.item.tree = mock_tree
self.item.links = ['mock_uid']
# Act
items = self.item.parent_items
# Assert
self.assertEqual(['mock_item'], items)
示例7: test_itemize_replace_existing
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import find_item [as 别名]
def test_itemize_replace_existing(self, mock_add_item):
"""Verify item data can replace existing items."""
header = ['uid', 'text', 'links', 'ext1']
data = [['req1', 'text1', '', 'val1'],
['req2', 'text2', 'sys1,sys2', None]]
mock_document = Mock()
mock_document.find_item = Mock(side_effect=DoorstopError)
# Act
importer._itemize(header, data, mock_document) # pylint: disable=W0212
# Assert
self.assertEqual(2, mock_add_item.call_count)
示例8: test_reorder_from_index
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import find_item [as 别名]
def test_reorder_from_index(self):
"""Verify items can be reordered from an index."""
mock_items = []
def mock_find_item(uid):
"""Return a mock item and store it."""
mock_item = MagicMock()
if uid == 'bb':
mock_item.level = Level('3.2')
elif uid == 'bab':
raise DoorstopError("unknown UID: bab")
mock_item.uid = uid
mock_items.append(mock_item)
return mock_item
mock_document = Mock()
mock_document.find_item = mock_find_item
data = {'initial': 2.0,
'outline': [
{'a': None},
{'b': [
{'ba': [
{'baa': None},
{'bab': None},
{'bac': None}]},
{'bb': None}]},
{'c': None}]}
expected = [Level('2'),
Level('3.0'),
Level('3.1.0'),
Level('3.1.1'),
Level('3.1.3'),
Level('3.2'),
Level('4')]
# Act
with patch('doorstop.common.read_text') as mock_read_text:
with patch('doorstop.common.load_yaml', Mock(return_value=data)):
Document._reorder_from_index(mock_document, 'mock_path')
# Assert
mock_read_text.assert_called_once_with('mock_path')
actual = [item.level for item in mock_items]
self.assertListEqual(expected, actual)
示例9: test_find_child_objects
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import find_item [as 别名]
def test_find_child_objects(self):
"""Verify an item's child objects can be found."""
mock_document_p = Mock()
mock_document_p.prefix = 'RQ'
mock_document_c = Mock()
mock_document_c.parent = 'RQ'
mock_item = Mock()
mock_item.uid = 'TST001'
mock_item.links = ['RQ001']
def mock_iter(self): # pylint: disable=W0613
"""Mock Tree.__iter__ to yield a mock Document."""
def mock_iter2(self): # pylint: disable=W0613
"""Mock Document.__iter__ to yield a mock Item."""
yield mock_item
mock_document_c.__iter__ = mock_iter2
yield mock_document_c
self.item.link('fake1')
mock_tree = Mock()
mock_tree.__iter__ = mock_iter
mock_tree.find_item = lambda uid: Mock(uid='fake1')
self.item.tree = mock_tree
self.item.document = mock_document_p
links = self.item.find_child_links()
items = self.item.find_child_items()
documents = self.item.find_child_documents()
self.assertEqual(['TST001'], links)
self.assertEqual([mock_item], items)
self.assertEqual([mock_document_c], documents)