本文整理汇总了Python中unittest.mock.MagicMock.find_item方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.find_item方法的具体用法?Python MagicMock.find_item怎么用?Python MagicMock.find_item使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.find_item方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_validate_tree_error
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import find_item [as 别名]
def test_validate_tree_error(self):
"""Verify an item can be checked against a tree with errors."""
self.item.link('fake1')
mock_tree = MagicMock()
mock_tree.find_item = Mock(side_effect=DoorstopError)
self.item.tree = mock_tree
self.assertFalse(self.item.validate())
示例2: test_valid_link_to_nonnormative
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import find_item [as 别名]
def test_valid_link_to_nonnormative(self):
"""Verify a link to an non-normative item can be checked."""
mock_item = Mock()
mock_item.normative = False
mock_tree = MagicMock()
mock_tree.find_item = Mock(return_value=mock_item)
self.item.links = ['a']
self.assertTrue(self.item.valid(tree=mock_tree))
示例3: test_validate_link_to_inactive
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import find_item [as 别名]
def test_validate_link_to_inactive(self):
"""Verify a link to an inactive item can be checked."""
mock_item = Mock()
mock_item.active = False
mock_tree = MagicMock()
mock_tree.find_item = Mock(return_value=mock_item)
self.item.links = ['a']
self.item.tree = mock_tree
self.assertTrue(self.item.validate())
示例4: test_validate_cleared
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import find_item [as 别名]
def test_validate_cleared(self):
"""Verify that checking a cleared link updates the stamp."""
mock_item = Mock()
mock_item.stamp = Mock(return_value=Stamp('abc123'))
mock_tree = MagicMock()
mock_tree.find_item = Mock(return_value=mock_item)
self.item.tree = mock_tree
self.item.links = [{'mock_uid': True}]
self.assertTrue(self.item.validate())
self.assertEqual('abc123', self.item.links[0].stamp) # pylint: disable=E1101
示例5: test_validate_cleared_new
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import find_item [as 别名]
def test_validate_cleared_new(self):
"""Verify that new links are stamped automatically."""
mock_item = Mock()
mock_item.stamp = Mock(return_value=Stamp('abc123'))
mock_tree = MagicMock()
mock_tree.find_item = Mock(return_value=mock_item)
self.item.tree = mock_tree
self.item.links = [{'mock_uid': None}]
self.assertTrue(self.item.validate())
self.assertEqual('abc123', self.item.links[0].stamp)
示例6: test_cleared
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import find_item [as 别名]
def test_cleared(self):
"""Verify an item's suspect link status can be set and read."""
mock_item = Mock()
mock_item.uid = 'mock_uid'
mock_item.stamp = Mock(return_value=Stamp('abc123'))
mock_tree = MagicMock()
mock_tree.find_item = Mock(return_value=mock_item)
self.item.tree = mock_tree
self.item.link('mock_uid')
self.item.cleared = 1 # updates each stamp
self.assertTrue(self.item.cleared)
self.item.cleared = 0 # sets each stamp to None
self.assertFalse(self.item.cleared)
示例7: test_clear
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import find_item [as 别名]
def test_clear(self):
"""Verify an item's links can be cleared as suspect."""
mock_item = Mock()
mock_item.uid = 'mock_uid'
mock_item.stamp = Mock(return_value=Stamp('abc123'))
mock_tree = MagicMock()
mock_tree.find_item = Mock(return_value=mock_item)
self.item.tree = mock_tree
self.item.link('mock_uid')
self.assertFalse(self.item.cleared)
self.assertEqual(None, self.item.links[0].stamp) # pylint: disable=E1101
# Act
self.item.clear()
# Assert
self.assertTrue(self.item.cleared)
self.assertEqual('abc123', self.item.links[0].stamp) # pylint: disable=E1101
示例8: test_valid_tree_error
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import find_item [as 别名]
def test_valid_tree_error(self):
"""Verify an item can be checked against a tree with errors."""
self.item.add_link('fake1')
tree = MagicMock()
tree.find_item = Mock(side_effect=DemoError)
self.assertFalse(self.item.valid(tree=tree))
示例9: TestDocumentReorder
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import find_item [as 别名]
class TestDocumentReorder(unittest.TestCase):
"""Unit tests for the Document class."""
def setUp(self):
def mock_find_item(uid):
"""Return a mock item and store it."""
if uid == 'bb':
mock_item = self.document.add_item(level=Level('3.2'), uid=uid)
elif uid == 'new':
raise DoorstopError("unknown UID: bab")
else:
mock_item = self.document.add_item(uid=uid)
return mock_item
def mock_add_item(level=None, reorder=False, uid=None):
"""Return a mock item and store it."""
mock_item = MagicMock()
mock_item.level = level
mock_item.text = ''
if uid:
mock_item.uid = uid
else:
mock_item.uid = self.next_uid
self.next_uid += 1
self.document.items.append(mock_item)
return mock_item
self.next_uid = 1
self.document = MagicMock()
self.document.items = []
self.document.find_item = mock_find_item
self.document.add_item = mock_add_item
def test_add_item(self):
self.assertEqual(self.document.items, [])
item = self.document.add_item(Level('1'), False)
self.assertEqual(item.level, Level('1'))
self.assertEqual(self.document.items, [item])
def test_find_missing_item(self):
self.assertRaises(DoorstopError, self.document.find_item, 'new')
def test_find_item(self):
item = self.document.find_item('c')
self.assertEqual(self.document.items, [item])
def test_reorder_from_index(self):
"""Verify items can be reordered from an index."""
data = {'initial': 2.0,
'outline': [
{'a': None},
{'b': [
{'ba': [
{'baa': None},
{'bac': None}]},
{'bb': [
{'new': None}]}]},
{'c': None}]}
expected = [Level('2'),
Level('3.0'),
Level('3.1.0'),
Level('3.1.1'),
Level('3.1.2'),
Level('3.2.0'),
Level('3.2.1'),
Level('4')]
# Act
self.document._read_index = MagicMock(return_value=data)
Document._reorder_from_index(self.document, 'mock_path')
# Assert
self.document._read_index.assert_called_once_with('mock_path')
print(self.document._items)
actual = [item.level for item in self.document.items]
self.assertListEqual(expected, actual)
self.assertEqual(self.document.items[-2].text, '')
def test_reorder_from_index_add(self):
"""Verify items can be added when reordering from an index."""
data = {'initial': 2.0,
'outline': [
{'a': None},
{'b': [
{'ba': [
{'baa': None},
{'new': None},
{'bac': None}]},
{'bb': [
{'new': [{'text': 'item_text'}]}]}]},
{'c': None}]}
expected = [Level('2'),
Level('3.0'),
Level('3.1.0'),
Level('3.1.1'),
Level('3.1.2'),
Level('3.1.3'),
Level('3.2.0'),
Level('3.2.1'),
Level('4')]
#.........这里部分代码省略.........