本文整理汇总了Python中unittest.mock.Mock.uid方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.uid方法的具体用法?Python Mock.uid怎么用?Python Mock.uid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.mock.Mock
的用法示例。
在下文中一共展示了Mock.uid方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_index_tree
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import uid [as 别名]
def test_index_tree(self):
"""Verify an HTML index can be created with a tree."""
path = os.path.join(FILES, 'index2.html')
mock_tree = MagicMock()
mock_tree.documents = []
for prefix in ('SYS', 'HLR', 'LLR', 'HLT', 'LLT'):
mock_document = MagicMock()
mock_document.prefix = prefix
mock_tree.documents.append(mock_document)
mock_tree.draw = lambda: "(mock tree structure)"
mock_item = Mock()
mock_item.uid = 'KNOWN-001'
mock_item.document = Mock()
mock_item.document.prefix = 'KNOWN'
mock_item.header = None
mock_item_unknown = Mock(spec=['uid'])
mock_item_unknown.uid = 'UNKNOWN-002'
mock_trace = [
(None, mock_item, None, None, None),
(None, None, None, mock_item_unknown, None),
(None, None, None, None, None),
]
mock_tree.get_traceability = lambda: mock_trace
# Act
publisher._index(FILES, index="index2.html", tree=mock_tree)
# Assert
self.assertTrue(os.path.isfile(path))
示例2: test_issues_duplicate_level
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import uid [as 别名]
def test_issues_duplicate_level(self):
"""Verify duplicate item levels are detected."""
mock_item1 = Mock()
mock_item1.uid = 'HLT001'
mock_item1.level = Level('4.2')
mock_item2 = Mock()
mock_item2.uid = 'HLT002'
mock_item2.level = Level('4.2')
mock_items = [mock_item1, mock_item2]
expected = DoorstopWarning("duplicate level: 4.2 (HLT001, HLT002)")
issue = list(self.document._get_issues_level(mock_items))[0]
self.assertIsInstance(issue, type(expected))
self.assertEqual(expected.args, issue.args)
示例3: test_issues_skipped_level_out_over
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import uid [as 别名]
def test_issues_skipped_level_out_over(self):
"""Verify skipped (out and over) item levels are detected."""
mock_item1 = Mock()
mock_item1.uid = 'HLT001'
mock_item1.level = Level('1.1')
mock_item2 = Mock()
mock_item2.uid = 'HLT002'
mock_item2.level = Level('2.2')
mock_items = [mock_item1, mock_item2]
expected = DoorstopWarning("skipped level: 1.1 (HLT001), 2.2 (HLT002)")
issues = list(self.document._get_issues_level(mock_items))
self.assertEqual(1, len(issues))
self.assertIsInstance(issues[0], type(expected))
self.assertEqual(expected.args, issues[0].args)
示例4: test_cleared
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import uid [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)
示例5: test_clear
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import uid [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
示例6: test_find_child_objects
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import uid [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)
示例7: mock_iter2
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import uid [as 别名]
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 = []
yield mock_item