本文整理汇总了Python中unittest.mock.Mock.version方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.version方法的具体用法?Python Mock.version怎么用?Python Mock.version使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.mock.Mock
的用法示例。
在下文中一共展示了Mock.version方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_dir_from_spec
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import version [as 别名]
def test_dir_from_spec(self):
mock = Mock(spec=unittest.TestCase)
testcase_attrs = set(dir(unittest.TestCase))
attrs = set(dir(mock))
self.assertEqual(set(), testcase_attrs - attrs)
mock.version = 3
self.assertEqual(dir(mock).count('version'), 1)
示例2: make_mocks
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import version [as 别名]
def make_mocks():
descriptor = Mock()
descriptor.version = (4, 0, 0)
descriptor.mode.transports = TRANSPORT.CCID
driver = Mock()
driver.key_type = YUBIKEY.YK4
driver.mode = Mode.from_code(1)
driver.read_config.return_value = b'\5\5\3\0\0\0'
return descriptor, driver
示例3: test_addon_not_found
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import version [as 别名]
def test_addon_not_found(self):
class MockVersion:
@property
def addon(self):
raise ObjectDoesNotExist
file = Mock()
file.version = MockVersion()
self.assertRaises(http.Http404, allowed, self.request, file)
示例4: test_too_fresh_requirement
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import version [as 别名]
def test_too_fresh_requirement(self, getDistributionMock):
requirement = 'package==0.1.2'
moduleMock = Mock()
moduleMock.version = '0.1.3'
getDistributionMock.return_value = moduleMock
self.assertRaisesRegex(IncorrectPackageVersionError,
re.escape("'package 0.1.3' version mismatch (==0.1.2)"), verify_packages, requirement)
示例5: test_outdated_requirement
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import version [as 别名]
def test_outdated_requirement(self, getDistributionMock):
requirement = 'package>=0.1'
moduleMock = Mock()
moduleMock.version = '0.0.9'
getDistributionMock.return_value = moduleMock
self.assertRaisesRegex(IncorrectPackageVersionError,
re.escape("'package 0.0.9' version mismatch (>=0.1)"), verify_packages, requirement)
示例6: test_dir_from_spec
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import version [as 别名]
def test_dir_from_spec(self):
mock = Mock(spec=unittest.TestCase)
testcase_attrs = set(dir(unittest.TestCase))
attrs = set(dir(mock))
# all attributes from the spec are included
self.assertEqual(set(), testcase_attrs - attrs)
# shadow a sys attribute
mock.version = 3
self.assertEqual(dir(mock).count('version'), 1)
示例7: test_correct_package_versions
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import version [as 别名]
def test_correct_package_versions(self, getDistributionMock):
requirement = 'package==0.1.2\n' \
'package>0.1\n' \
'package>=0.1'
moduleMock = Mock()
moduleMock.version = '0.1.2'
getDistributionMock.return_value = moduleMock
verify_packages(requirement)
getDistributionMock.assert_called_with('package')
self.assertEqual(3, len(getDistributionMock.call_args_list))
示例8: Mock
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import version [as 别名]
import os
import sys
import pytest
from unittest.mock import Mock
# mocking sublime
mocked_sublime = Mock()
mocked_sublime.version = Mock(return_value=3001)
sys.modules['sublime'] = mocked_sublime
# adding lib folder to syspath
directory = os.path.dirname(os.path.realpath(__file__))
libs_path = os.path.join(directory, '..', 'codeformatter', 'lib')
if libs_path not in sys.path:
sys.path.append(libs_path)
@pytest.fixture
def php_view():
mview = Mock()
mview.return_value.settings = Mock(return_value={'syntax': 'Packages/User/PHP.sublime-syntax'})
mview.return_value.file_name = Mock(return_value='php_file_name')
return mview()
@pytest.fixture
def invalid_syntax_view():
mview = Mock()
mview.return_value.settings = Mock(return_value={'syntax': 'invalid_syntax'})
mview.return_value.file_name = Mock(return_value='invalid_file_name')
return mview()