本文整理汇总了Python中unittest.mock.Mock.parent方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.parent方法的具体用法?Python Mock.parent怎么用?Python Mock.parent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.mock.Mock
的用法示例。
在下文中一共展示了Mock.parent方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_find_rlinks
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import parent [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_validate_both
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import parent [as 别名]
def test_validate_both(self):
"""Verify an item can be checked against both."""
def mock_iter(seq):
"""Creates a mock __iter__ method."""
def _iter(self): # pylint: disable=W0613
"""Mock __iter__method."""
yield from seq
return _iter
mock_item = Mock()
mock_item.links = [self.item.uid]
mock_document = Mock()
mock_document.parent = 'BOTH'
mock_document.prefix = 'BOTH'
mock_document.__iter__ = mock_iter([mock_item])
mock_tree = Mock()
mock_tree.__iter__ = mock_iter([mock_document])
self.item.document = mock_document
self.item.tree = mock_tree
self.assertTrue(self.item.validate())
示例3: test_validate_document_with_bad_link_uids
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import parent [as 别名]
def test_validate_document_with_bad_link_uids(self):
"""Verify an item can be checked against a document w/ bad links."""
self.item.link('invalid')
mock_document = Mock()
mock_document.parent = 'fake'
self.item.document = mock_document
self.assertFalse(self.item.validate())
示例4: test_validate_document_with_links
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import parent [as 别名]
def test_validate_document_with_links(self):
"""Verify an item can be checked against a document with links."""
self.item.link('unknown1')
mock_document = Mock()
mock_document.parent = 'fake'
self.item.document = mock_document
self.assertTrue(self.item.validate())
示例5: mock_iter
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import parent [as 别名]
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
示例6: test_find_child_objects
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import parent [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: test_valid_document_with_bad_link_IDs
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import parent [as 别名]
def test_valid_document_with_bad_link_IDs(self):
"""Verify an item can be checked against a document w/ bad link IDs."""
self.item.add_link('invalid')
mock_document = Mock()
mock_document.parent = 'fake'
self.assertFalse(self.item.valid(document=mock_document))
示例8: test_valid_document
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import parent [as 别名]
def test_valid_document(self):
"""Verify an item can be checked against a document."""
mock_document = Mock()
mock_document.parent = 'fake'
self.assertTrue(self.item.valid(document=mock_document))
示例9: test_returns_none_on_exception
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import parent [as 别名]
def test_returns_none_on_exception(self, mock_post):
mock_post = Mock()
mock_post.parent = False
entity = make_federable_content(mock_post)
self.assertIsNone(entity)