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


Python Mock.path方法代码示例

本文整理汇总了Python中unittest.mock.Mock.path方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.path方法的具体用法?Python Mock.path怎么用?Python Mock.path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在unittest.mock.Mock的用法示例。


在下文中一共展示了Mock.path方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: download_result_mock

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import path [as 别名]
 def download_result_mock(self, path):
     dr = Mock()
     dr.artifact_attributes = {'size': 0}
     for digest_type in Artifact.DIGEST_FIELDS:
         dr.artifact_attributes[digest_type] = '1'
     dr.path = SimpleUploadedFile(name=path, content='')
     return dr
开发者ID:asmacdo,项目名称:pulp,代码行数:9,代码来源:test_handler.py

示例2: _get_fake_mprows

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import path [as 别名]
def _get_fake_mprows(type_):
    """ Returns fake instance of the MPRowsFile. """
    mprows = Mock(spec=MPRowsFile)
    mprows.reader = AttrDict({
        'columns': [{'type': type_, 'name': 'column1', 'pos': 0}]})
    mprows.path = 'tmp'
    mprows._fs = Mock()
    mprows._fs.root_path = '/tmp'
    return mprows
开发者ID:CivicKnowledge,项目名称:ambry_sources,代码行数:11,代码来源:test_sqlite.py

示例3: test_get_ext_file_document_no_extension

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import path [as 别名]
 def test_get_ext_file_document_no_extension(self):
     """Verify an extension is required on single file paths."""
     args = Mock(spec=['path'])
     args.path = 'path/to/file'
     error = Mock()
     # Act
     utilities.get_ext(args, error, '.out', '.file')
     # Assert
     self.assertNotEqual(0, error.call_count)
开发者ID:dornerworks,项目名称:doorstop,代码行数:11,代码来源:test_utilities.py

示例4: test_get_ext_file_document_to_directory

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import path [as 别名]
 def test_get_ext_file_document_to_directory(self):
     """Verify a path is required for a single document."""
     args = Mock(spec=['path'])
     args.path = 'path/to/directory'
     error = Mock()
     # Act
     utilities.get_ext(args, error, '.out', '.file')
     # Assert
     self.assertNotEqual(0, error.call_count)
开发者ID:dornerworks,项目名称:doorstop,代码行数:11,代码来源:test_utilities.py

示例5: send_test_params

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import path [as 别名]
def send_test_params(params):
    from io import BytesIO
    params_str = urlencode(params, doseq=True)
    mock_tracker = Mock()
    mock_tracker.path = "http://localhost:8000/announce?" + params_str
    mock_tracker.client_address = ("127.0.0.1", 8001)
    output_file = BytesIO()
    tracker.handle_GET(mock_tracker, output_file)
    output_file.seek(0)
    return bdecode_file(output_file)
开发者ID:MFAshby,项目名称:pybittorrent,代码行数:12,代码来源:tracker_tests.py

示例6: test_get_ext_file_tree

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import path [as 别名]
 def test_get_ext_file_tree(self):
     """Verify a specified file extension can be selected."""
     args = Mock(spec=['path'])
     args.path = 'path/to/directory'
     error = Mock()
     # Act
     ext = utilities.get_ext(args, error, '.out', '.file', whole_tree=True)
     # Assert
     self.assertEqual(0, error.call_count)
     self.assertEqual('.file', ext)
开发者ID:dornerworks,项目名称:doorstop,代码行数:12,代码来源:test_utilities.py

示例7: test_get_ext_file_document

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import path [as 别名]
 def test_get_ext_file_document(self):
     """Verify a specified file extension can be selected."""
     args = Mock(spec=['path'])
     args.path = 'path/to/file.cust'
     error = Mock()
     # Act
     ext = utilities.get_ext(args, error, '.out', '.file')
     # Assert
     self.assertEqual(0, error.call_count)
     self.assertEqual('.cust', ext)
开发者ID:dornerworks,项目名称:doorstop,代码行数:12,代码来源:test_utilities.py

示例8: test_process_request_clear

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import path [as 别名]
    def test_process_request_clear(self, redirect_mock):
        request = Mock()
        request.GET = {
            'ZZ_FEATURE_CLEAR': 1,
        }
        request.path = '/dashboard/'
        assert self.middleware.process_request(request) == redirect_mock.return_value

        redirect_mock.assert_called_once_with('/dashboard/')

        response = redirect_mock.return_value
        response.delete_cookie.assert_called_once_with(FEATURE_FLAG_COOKIE_NAME)
开发者ID:mitodl,项目名称:cookiecutter-djangoapp,代码行数:14,代码来源:middleware_test.py

示例9: test_create_script_with_path

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import path [as 别名]
    def test_create_script_with_path(self):
        temp_folder = self.get_tmp_folder()

        args = Mock()
        args.location = temp_folder
        args.app = 'console'
        args.os = 'unix'
        args.path = './path1/pth2'

        shell_script = temp_folder + os.sep + "console.sh"
        self.ensure_file_does_not_exist(shell_script)

        AdminTool.create_script(args)
        self.assertTrue(os.path.exists(shell_script))

        self.ensure_file_does_not_exist(shell_script)
开发者ID:Freiza,项目名称:program-y,代码行数:18,代码来源:test_tool.py

示例10: test_process_request_query

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import path [as 别名]
    def test_process_request_query(self, redirect_mock):
        request = Mock()
        request.GET = {
            'ZZ_FEATURE_EXAMPLE_FEATURE': 1,
        }
        request.path = '/dashboard/'
        assert self.middleware.process_request(request) == redirect_mock.return_value

        redirect_mock.assert_called_once_with('/dashboard/')

        response = redirect_mock.return_value
        response.set_signed_cookie.assert_called_once_with(
            FEATURE_FLAG_COOKIE_NAME,
            '1',
            max_age=FEATURE_FLAG_COOKIE_MAX_AGE_SECONDS,
            httponly=True,
        )
开发者ID:mitodl,项目名称:cookiecutter-djangoapp,代码行数:19,代码来源:middleware_test.py

示例11: test_get_transfer_action_returns_dict

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import path [as 别名]
    def test_get_transfer_action_returns_dict(self):
        org = Mock(id=1)

        def name(*args):
            return "Other Public Defender"

        org.__str__ = name
        request = Mock()
        request.path = '/applications/bundle/2/'
        request.user.profile.organization\
            .transfer_partners.first.return_value = org
        submission = self.get_a_sample_sub()
        expected_result = {
            'url': str(
                "/application/{}/transfer/"
                "?next=/applications/bundle/2/".format(submission.id)),
            'display': 'Other Public Defender'
        }
        self.assertDictEqual(
            submission.get_transfer_action(request),
            expected_result)
开发者ID:codeforamerica,项目名称:intake,代码行数:23,代码来源:test_form_submission.py

示例12: test_run

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import path [as 别名]
    def test_run(self, *args):
        """Test lvm format populator."""
        get_device_by_uuid = args[0]

        devicetree = DeviceTree()
        data = dict()
        device = Mock()
        device.parents = []
        device.size = Size("10g")
        devicetree._add_device(device)

        # pylint: disable=attribute-defined-outside-init
        self._pvs = blockdev.lvm.pvs
        self._vgs = blockdev.lvm.vgs
        self._lvs = blockdev.lvm.lvs
        blockdev.lvm.pvs = Mock(return_value=[])
        blockdev.lvm.vgs = Mock(return_value=[])
        blockdev.lvm.lvs = Mock(return_value=[])
        self.addCleanup(self._clean_up)

        # base case: pv format with no vg
        with patch("blivet.udev.device_get_format", return_value=self.udev_type):
            helper = self.helper_class(devicetree, data, device)
            helper.run()
            self.assertEqual(device.format.type,
                             self.blivet_type,
                             msg="Wrong format type after FormatPopulator.run on %s" % self.udev_type)

        # pv belongs to a valid vg which is already in the tree (no lvs)
        pv_info = Mock()

        pv_info.vg_name = "testvgname"
        pv_info.vg_uuid = sentinel.vg_uuid
        pv_info.pe_start = 0
        pv_info.pv_free = 0

        device.path = sentinel.pv_path

        vg_device = Mock()
        vg_device.parents = []
        vg_device.lvs = []
        get_device_by_uuid.return_value = vg_device

        with patch("blivet.static_data.lvm_info.PVsInfo.cache", new_callable=PropertyMock) as mock_pvs_cache:
            mock_pvs_cache.return_value = {sentinel.pv_path: pv_info}
            with patch("blivet.udev.device_get_format", return_value=self.udev_type):
                helper = self.helper_class(devicetree, data, device)
                self.assertFalse(device in vg_device.parents)
                helper.run()
                self.assertEqual(device.format.type,
                                 self.blivet_type,
                                 msg="Wrong format type after FormatPopulator.run on %s" % self.udev_type)

                self.assertEqual(get_device_by_uuid.call_count, 3)
                get_device_by_uuid.assert_called_with(pv_info.vg_uuid, incomplete=True)
                self.assertTrue(device in vg_device.parents)

        get_device_by_uuid.reset_mock()
        get_device_by_uuid.return_value = None

        # pv belongs to a valid vg which is not in the tree (no lvs, either)
        pv_info.vg_size = "10g"
        pv_info.vg_free = 0
        pv_info.vg_extent_size = "4m"
        pv_info.vg_extent_count = 2500
        pv_info.vg_free_count = 0
        pv_info.vg_pv_count = 1

        with patch("blivet.static_data.lvm_info.PVsInfo.cache", new_callable=PropertyMock) as mock_pvs_cache:
            mock_pvs_cache.return_value = {sentinel.pv_path: pv_info}
            with patch("blivet.udev.device_get_format", return_value=self.udev_type):
                helper = self.helper_class(devicetree, data, device)
                helper.run()
                self.assertEqual(device.format.type,
                                 self.blivet_type,
                                 msg="Wrong format type after FormatPopulator.run on %s" % self.udev_type)

                self.assertEqual(get_device_by_uuid.call_count, 2)
                get_device_by_uuid.assert_called_with(pv_info.vg_uuid, incomplete=True)
                vg_device = devicetree.get_device_by_name(pv_info.vg_name)
                self.assertTrue(vg_device is not None)
                devicetree._remove_device(vg_device)

        get_device_by_uuid.reset_mock()

        # pv belongs to a valid vg not in the tree with two lvs
        lv1 = Mock()
        lv1.vg_name = pv_info.vg_name
        lv1.lv_name = "testlv1"
        lv1.uuid = sentinel.lv1_uuid
        lv1.attr = "-wi-ao----"
        lv1.size = "2g"
        lv1.segtype = "linear"
        lv1_name = "%s-%s" % (pv_info.vg_name, lv1.lv_name)

        lv2 = Mock()
        lv2.vg_name = pv_info.vg_name
        lv2.lv_name = "testlv2"
        lv2.uuid = sentinel.lv2_uuid
        lv2.attr = "-wi-ao----"
#.........这里部分代码省略.........
开发者ID:afamilyman,项目名称:blivet,代码行数:103,代码来源:populator_test.py

示例13: request

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import path [as 别名]
def request(app):
    request = Mock(name='request')
    request.app = app
    request.path = '/'
    return request
开发者ID:zzzsochi,项目名称:aiohttp_traversal,代码行数:7,代码来源:test_router.py

示例14: test_schema

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import path [as 别名]
        resp = self.client.get(self.url)
        self.assertEqual(200, resp.status_code)

    def test_schema(self):
        resp = self.client.get(self.url)
        data = json.loads(resp.getvalue().decode('utf-8'))
        assert set(['name', 'description', 'repository']).issubset(data.keys())


class _MockJinjaEnvironment(object):
    def __init__(self):
        self.globals = {}


MockStorageInstance = Mock()
MockStorageInstance.path = Mock(return_value='foo')
MockStorageInstance.hashed_files = {"foo": "bar"}
MockStorage = Mock(return_value=MockStorageInstance)


class TestPilotJinjaExtensionTests(TestCase):

    def setUp(self):
        self.environment = _MockJinjaEnvironment()
        self.extension = TestPilotExtension(self.environment)

    def test_hash_content(self):
        content = """
            Beard irony cold-pressed, venmo chicharrones PBR&B banh mi
            meditation. Forage street art meh artisan, tattooed
            gochujang pinterest fixie skateboard kombucha crucifix viral.
开发者ID:30mps,项目名称:testpilot,代码行数:33,代码来源:tests.py


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