本文整理汇总了Python中unittest.mock.Mock.prefix方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.prefix方法的具体用法?Python Mock.prefix怎么用?Python Mock.prefix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.mock.Mock
的用法示例。
在下文中一共展示了Mock.prefix方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_valid_both_no_reverse_links
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import prefix [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))
示例2: test_validate_both
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import prefix [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_find_rlinks
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import prefix [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)
示例4: setUp
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import prefix [as 别名]
def setUp(self):
# Create default item attributes
self.uid = 'PREFIX-00042'
# Ensure the tree is reloaded
mock_document = Mock()
mock_document.root = self.root
mock_document.prefix = self.prefix
self.mock_tree = Tree(mock_document)
_set_tree(self.mock_tree)
示例5: test_itemize_blank_column
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import prefix [as 别名]
def test_itemize_blank_column(self, mock_add_item):
"""Verify item data can include invalid values."""
header = ['id', 'text', None, 'links', 'ext1'] # test 'id' is accepted
data = [['req1', 'text1', 'blank', '', 'val1']]
mock_document = Mock()
mock_document.prefix = 'prefix'
importer._itemize(header, data, mock_document) # pylint: disable=W0212
expected_attrs = {'links': [], 'ext1': 'val1', 'text': 'text1'}
mock_add_item.assert_called_once_with(mock_document.prefix, 'req1',
attrs=expected_attrs,
document=mock_document)
示例6: test_itemize_explicit_inactive
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import prefix [as 别名]
def test_itemize_explicit_inactive(self, mock_add_item):
"""Verify item data can be converted to items (explicit inactive)."""
header = ['uid', 'text', 'links', 'ext1', 'active']
data = [['req2', '', '', False, False]]
mock_document = Mock()
mock_document.prefix = 'PREFIX'
# Act
importer._itemize(header, data, mock_document) # pylint: disable=W0212
# Assert
args, kwargs = mock_add_item.call_args
self.assertEqual('PREFIX', args[0])
self.assertEqual('req2', args[1])
expected_attrs = {'active': False,
'ext1': False,
'links': [],
'text': ''}
self.assertEqual(expected_attrs, kwargs['attrs'])
示例7: test_itemize
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import prefix [as 别名]
def test_itemize(self, mock_add_item):
"""Verify item data can be converted to items."""
header = ['uid', 'text', 'links', 'ext1']
data = [['req1', 'text1', '', 'val1'],
['req2', '', 'sys1,sys2', False]]
mock_document = Mock()
mock_document.prefix = 'PREFIX'
# Act
importer._itemize(header, data, mock_document) # pylint: disable=W0212
# Assert
self.assertEqual(2, mock_add_item.call_count)
args, kwargs = mock_add_item.call_args
self.assertEqual('PREFIX', args[0])
self.assertEqual('req2', args[1])
expected_attrs = {'ext1': False,
'links': ['sys1', 'sys2'],
'text': ''}
self.assertEqual(expected_attrs, kwargs['attrs'])
self.assertIs(mock_document, kwargs['document'])
示例8: test_itemize_new_rows
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import prefix [as 别名]
def test_itemize_new_rows(self, mock_add_item):
"""Verify items can be added from item data blank UIDs."""
header = ['uid', 'text', 'links', 'ext1']
data = [
['req1', 'text1', '', 'val1'],
['req2', '', 'sys1,sys2', False],
[None, 'A new item.', '', ''], # blank UID: None
['', 'A new item.', '', ''], # blank UID: empty
[' ', 'A new item.', '', ''], # blank UID: whitespace
['', '', '', ''], # skipped
['...', 'Another new item.', '', ''], # placeholder UID
]
mock_document = Mock()
mock_document.prefix = 'PREFIX'
mock_document.next_number = 3
mock_document.digits = 3
# Act
importer._itemize(header, data, mock_document) # pylint: disable=W0212
# Assert
self.assertEqual(6, mock_add_item.call_count)
示例9: test_find_child_objects
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import prefix [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)
示例10: _mock_metric
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import prefix [as 别名]
def _mock_metric(self, prefix=None, suffix=None, precision=None):
mock_metric = Mock()
mock_metric.prefix = prefix
mock_metric.suffix = suffix
mock_metric.precision = precision
return mock_metric