当前位置: 首页>>代码示例>>Python>>正文


Python Mock.prefix方法代码示例

本文整理汇总了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))
开发者ID:jacebrowning,项目名称:doorstop-demo,代码行数:31,代码来源:test_item.py

示例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())
开发者ID:PeterDaveHello,项目名称:doorstop,代码行数:27,代码来源:test_item.py

示例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)
开发者ID:jacebrowning,项目名称:doorstop-demo,代码行数:32,代码来源:test_item.py

示例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)
开发者ID:jkloo,项目名称:doorstop,代码行数:11,代码来源:test_importer.py

示例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)
开发者ID:jkloo,项目名称:doorstop,代码行数:13,代码来源:test_importer.py

示例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'])
开发者ID:jkloo,项目名称:doorstop,代码行数:19,代码来源:test_importer.py

示例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'])
开发者ID:jkloo,项目名称:doorstop,代码行数:21,代码来源:test_importer.py

示例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)
开发者ID:jkloo,项目名称:doorstop,代码行数:22,代码来源:test_importer.py

示例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)
开发者ID:PeterDaveHello,项目名称:doorstop,代码行数:38,代码来源:test_item.py

示例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
开发者ID:kayak,项目名称:fireant,代码行数:8,代码来源:test_datatables.py


注:本文中的unittest.mock.Mock.prefix方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。