本文整理汇总了Python中six.assertRaisesRegex函数的典型用法代码示例。如果您正苦于以下问题:Python assertRaisesRegex函数的具体用法?Python assertRaisesRegex怎么用?Python assertRaisesRegex使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了assertRaisesRegex函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_add_device
def test_add_device(self, *args): # pylint: disable=unused-argument
dt = DeviceTree()
dev1 = StorageDevice("dev1", exists=False, uuid=sentinel.dev1_uuid, parents=[])
self.assertEqual(dt.devices, list())
# things are called, updated as expected when a device is added
with patch("blivet.devicetree.callbacks") as callbacks:
dt._add_device(dev1)
self.assertTrue(callbacks.device_added.called)
self.assertEqual(dt.devices, [dev1])
self.assertTrue(dev1 in dt.devices)
self.assertTrue(dev1.name in dt.names)
self.assertTrue(dev1.add_hook.called) # pylint: disable=no-member
# adding an already-added device fails
six.assertRaisesRegex(self, ValueError, "already in tree", dt._add_device, dev1)
dev2 = StorageDevice("dev2", exists=False, parents=[])
dev3 = StorageDevice("dev3", exists=False, parents=[dev1, dev2])
# adding a device with one or more parents not already in the tree fails
six.assertRaisesRegex(self, DeviceTreeError, "parent.*not in tree", dt._add_device, dev3)
self.assertFalse(dev2 in dt.devices)
self.assertFalse(dev2.name in dt.names)
dt._add_device(dev2)
self.assertTrue(dev2 in dt.devices)
self.assertTrue(dev2.name in dt.names)
dt._add_device(dev3)
self.assertTrue(dev3 in dt.devices)
self.assertTrue(dev3.name in dt.names)
开发者ID:rhinstaller,项目名称:blivet,代码行数:35,代码来源:devicetree_test.py
示例2: testThreeLetters
def testThreeLetters(self):
"""
An argument that has three letters must result in a ValueError.
"""
error = ("^btop string 'ABC' has a trailing query letter 'C' with no "
"corresponding subject letter$")
assertRaisesRegex(self, ValueError, error, list, parseBtop('ABC'))
开发者ID:bamueh,项目名称:dark-matter,代码行数:7,代码来源:test_btop.py
示例3: testSettingValidation
def testSettingValidation(self):
# Mounting and unmounting test valid use, so this just tests invalid
# values.
with six.assertRaisesRegex(self, ValidationException, 'must be a dict'):
Setting().set(SettingKey.GIRDER_MOUNT_INFORMATION, 'not a dict')
with six.assertRaisesRegex(self, ValidationException, 'with the "path" key'):
Setting().set(SettingKey.GIRDER_MOUNT_INFORMATION, {'no path': 'key'})
开发者ID:data-exp-lab,项目名称:girder,代码行数:7,代码来源:mount_test.py
示例4: testEmptyString
def testEmptyString(self):
"""
An empty string must produce an empty set of indices.
"""
error = ("^Illegal range ''. Ranges must single numbers or "
"number-number\\.$")
assertRaisesRegex(self, ValueError, error, parseRangeString, '')
开发者ID:acorg,项目名称:dark-matter,代码行数:7,代码来源:test_utils.py
示例5: testOneLetter
def testOneLetter(self):
"""
An argument with just one letter must result in a ValueError.
"""
error = ("^btop string 'F' has a trailing query letter 'F' with no "
"corresponding subject letter$")
assertRaisesRegex(self, ValueError, error, list, parseBtop('F'))
开发者ID:bamueh,项目名称:dark-matter,代码行数:7,代码来源:test_btop.py
示例6: test_fsm_illegal_strict_event
def test_fsm_illegal_strict_event(self):
six.assertRaisesRegex(self, utils.NodeStateInvalidEvent,
'no defined transition',
self.node_info.fsm_event,
istate.Events.finish, strict=True)
self.assertIn('no defined transition', self.node_info.error)
self.assertEqual(self.node_info.state, istate.States.error)
开发者ID:aarefiev22,项目名称:ironic-inspector,代码行数:7,代码来源:test_node_cache.py
示例7: test_material_set_properties
def test_material_set_properties(self):
bad_absorb = '-1'
bad_scattering = 0
good_absorb = '1'
good_scattering = 2.0
material_obj = sample_details._Material(chemical_formula='V')
with assertRaisesRegex(self, ValueError, "absorption_cross_section was: -1 which is impossible for a physical "
"object"):
material_obj.set_material_properties(abs_cross_sect=bad_absorb, scattering_cross_sect=good_scattering)
# Check the immutability flag has not been set on a failure
self.assertFalse(material_obj._is_material_props_set)
with assertRaisesRegex(self, ValueError, "scattering_cross_section was: 0"):
material_obj.set_material_properties(abs_cross_sect=good_absorb, scattering_cross_sect=bad_scattering)
# Check nothing has been set yet
self.assertIsNone(material_obj.absorption_cross_section)
self.assertIsNone(material_obj.scattering_cross_section)
# Set the object this time
material_obj.set_material_properties(abs_cross_sect=good_absorb, scattering_cross_sect=good_scattering)
self.assertTrue(material_obj._is_material_props_set)
self.assertEqual(material_obj.absorption_cross_section, float(good_absorb))
self.assertEqual(material_obj.scattering_cross_section, float(good_scattering))
# Check we cannot set it twice and fields do not change
with assertRaisesRegex(self, RuntimeError, "The material properties have already been set"):
material_obj.set_material_properties(abs_cross_sect=999, scattering_cross_sect=999)
self.assertEqual(material_obj.absorption_cross_section, float(good_absorb))
self.assertEqual(material_obj.scattering_cross_section, float(good_scattering))
开发者ID:mantidproject,项目名称:mantid,代码行数:33,代码来源:ISISPowderSampleDetailsTest.py
示例8: test_json_field
def test_json_field(self):
schema = [
{'name': 'big_dict', 'type': 'basic:json:'}
]
# json not saved in `Storage`
instance = {'big_dict': {'foo': 'bar'}}
with six.assertRaisesRegex(self, ValidationError, 'is not valid'):
validate_schema(instance, schema)
with patch('resolwe.flow.models.Storage') as storage_mock:
filter_mock = MagicMock()
filter_mock.exists.return_value = True
storage_mock.objects.filter.return_value = filter_mock
instance = {'big_dict': 5}
validate_schema(instance, schema)
self.assertEqual(filter_mock.exists.call_count, 1)
# non existing `Storage`
with patch('resolwe.flow.models.Storage') as storage_mock:
filter_mock = MagicMock()
filter_mock.exists.return_value = False
storage_mock.objects.filter.return_value = filter_mock
instance = {'big_dict': 5}
with six.assertRaisesRegex(self, ValidationError, '`Storage` object does not exist'):
validate_schema(instance, schema)
self.assertEqual(filter_mock.exists.call_count, 1)
开发者ID:hadalin,项目名称:resolwe,代码行数:31,代码来源:test_validation.py
示例9: test_run_number_not_found_gives_sane_err
def test_run_number_not_found_gives_sane_err(self):
expected_val = "yamlParserTest"
file_handle = self.get_temp_file_handle()
file_handle.write("10-20:\n")
file_handle.write(" test_key: '" + expected_val + "'\n")
file_handle.write("21-:\n")
file_handle.write(" test_key: '" + expected_val + "'\n")
file_path = file_handle.name
file_handle.close()
# Test a value in the middle of 1-10
with assertRaisesRegex(self, ValueError, "Run number 5 not recognised in cycle mapping file"):
yaml_parser.get_run_dictionary(run_number_string="5", file_path=file_path)
# Check on edge of invalid numbers
with assertRaisesRegex(self, ValueError, "Run number 9 not recognised in cycle mapping file"):
yaml_parser.get_run_dictionary(run_number_string=9, file_path=file_path)
# What about a range of numbers
with assertRaisesRegex(self, ValueError, "Run number 2 not recognised in cycle mapping file"):
yaml_parser.get_run_dictionary(run_number_string="2-8", file_path=file_path)
# Check valid number still works
returned_dict = yaml_parser.get_run_dictionary(run_number_string="10", file_path=file_path)
self.assertEqual(returned_dict["test_key"], expected_val)
开发者ID:mantidproject,项目名称:mantid,代码行数:26,代码来源:ISISPowderYamlParserTest.py
示例10: test_date_field
def test_date_field(self):
schema = [
{'name': 'date', 'type': 'basic:date:'},
]
instance = {'date': '2000-12-31'}
validate_schema(instance, schema)
instance = {'date': '2000/01/01'}
with six.assertRaisesRegex(self, ValidationError, 'is not valid'):
validate_schema(instance, schema)
instance = {'date': '31 04 2000'}
with six.assertRaisesRegex(self, ValidationError, 'is not valid'):
validate_schema(instance, schema)
instance = {'date': '21.06.2000'}
with six.assertRaisesRegex(self, ValidationError, 'is not valid'):
validate_schema(instance, schema)
instance = {'date': '2000-1-1'}
with six.assertRaisesRegex(self, ValidationError, 'is not valid'):
validate_schema(instance, schema)
instance = {'date': '2000 apr 8'}
with six.assertRaisesRegex(self, ValidationError, 'is not valid'):
validate_schema(instance, schema)
开发者ID:hadalin,项目名称:resolwe,代码行数:27,代码来源:test_validation.py
示例11: test_datetime_field
def test_datetime_field(self):
schema = [
{'name': 'date', 'type': 'basic:datetime:'},
]
instance = {'date': '2000-06-21 00:00'}
validate_schema(instance, schema)
instance = {'date': '2000 06 21 24:00'}
with self.assertRaises(ValidationError):
validate_schema(instance, schema)
instance = {'date': '2000/06/21 2:03'}
with six.assertRaisesRegex(self, ValidationError, 'is not valid'):
validate_schema(instance, schema)
instance = {'date': '2000-06-21 2:3'} # XXX: Is this ok?
validate_schema(instance, schema)
instance = {'date': '2000-06-21'}
with six.assertRaisesRegex(self, ValidationError, 'is not valid'):
validate_schema(instance, schema)
instance = {'date': '2000-06-21 12pm'}
with six.assertRaisesRegex(self, ValidationError, 'is not valid'):
validate_schema(instance, schema)
开发者ID:hadalin,项目名称:resolwe,代码行数:26,代码来源:test_validation.py
示例12: test_check_db_fails
def test_check_db_fails(self):
with assertRaisesRegex(self, ValueError, 'no database'):
dbcore.Model()._check_db()
with assertRaisesRegex(self, ValueError, 'no id'):
TestModel1(self.db)._check_db()
dbcore.Model(self.db)._check_db(need_id=False)
开发者ID:JDLH,项目名称:beets,代码行数:7,代码来源:test_dbcore.py
示例13: test_mdraid_array_device_methods
def test_mdraid_array_device_methods(self):
"""Test for method calls on initialized MDRaidDevices."""
with six.assertRaisesRegex(self, DeviceError, "invalid"):
self.dev7.level = "junk"
with six.assertRaisesRegex(self, DeviceError, "invalid"):
self.dev7.level = None
开发者ID:rhinstaller,项目名称:blivet,代码行数:7,代码来源:device_properties_test.py
示例14: test_duplicate_keys
def test_duplicate_keys(self):
output_file = six.StringIO()
utility = CSVJSON(['-k', 'a', 'examples/dummy3.csv'], output_file)
six.assertRaisesRegex(self, ValueError,
'Value True is not unique in the key column.',
utility.run)
output_file.close()
开发者ID:datamade,项目名称:csvkit,代码行数:7,代码来源:test_csvjson.py
示例15: test_rebin_workspace_list_x_start_end
def test_rebin_workspace_list_x_start_end(self):
new_start_x = 1
new_end_x = 5
new_bin_width = 0.5
number_of_ws = 10
ws_bin_widths = [new_bin_width] * number_of_ws
start_x_list = [new_start_x] * number_of_ws
end_x_list = [new_end_x] * number_of_ws
ws_list = []
for i in range(number_of_ws):
out_name = "test_rebin_workspace_list_defaults_" + str(i)
ws_list.append(mantid.CreateSampleWorkspace(OutputWorkspace=out_name, Function='Flat background',
NumBanks=1, BankPixelWidth=1, XMax=10, BinWidth=1))
# Are the lengths checked
incorrect_length = [1] * (number_of_ws - 1)
with assertRaisesRegex(self, ValueError, "The number of starting bin values"):
common.rebin_workspace_list(workspace_list=ws_list, bin_width_list=ws_bin_widths,
start_x_list=incorrect_length, end_x_list=end_x_list)
with assertRaisesRegex(self, ValueError, "The number of ending bin values"):
common.rebin_workspace_list(workspace_list=ws_list, bin_width_list=ws_bin_widths,
start_x_list=start_x_list, end_x_list=incorrect_length)
output_list = common.rebin_workspace_list(workspace_list=ws_list, bin_width_list=ws_bin_widths,
start_x_list=start_x_list, end_x_list=end_x_list)
self.assertEqual(len(output_list), number_of_ws)
for ws in output_list:
self.assertEqual(ws.readX(0)[0], new_start_x)
self.assertEqual(ws.readX(0)[-1], new_end_x)
mantid.DeleteWorkspace(ws)
开发者ID:mantidproject,项目名称:mantid,代码行数:32,代码来源:ISISPowderCommonTest.py
示例16: test_get_pull_request
def test_get_pull_request(self):
"""Tests for _get_pull_request."""
# Simple case: get the existing PR from the existing repo.
result = pss._get_pull_request(self.repo, "3")
self.assertEqual(result.id, 3)
# PR that doesn't exist.
six.assertRaisesRegex(
self,
PagureEvException,
r"Pull-Request '2' not found",
pss._get_pull_request,
self.repo,
"2",
)
# PR from a project with no PR tracker.
six.assertRaisesRegex(
self,
PagureEvException,
r"No pull-request tracker found",
pss._get_pull_request,
self.repo2,
"1",
)
开发者ID:pypingou,项目名称:pagure,代码行数:25,代码来源:test_stream_server.py
示例17: test_bad_descriptor_input
def test_bad_descriptor_input(self, resolwe_mock):
# Raise error is only one of deswcriptor/descriptor_schema is given:
message = "Set both or neither descriptor and descriptor_schema."
with six.assertRaisesRegex(self, ValueError, message):
Resolwe.run(resolwe_mock, descriptor="a")
with six.assertRaisesRegex(self, ValueError, message):
Resolwe.run(resolwe_mock, descriptor_schema="a")
开发者ID:tjanez,项目名称:resolwe-bio-py,代码行数:7,代码来源:test_resolwe.py
示例18: testSetContentDisposition
def testSetContentDisposition(self):
with six.assertRaisesRegex(
self, rest.RestException,
'Error: Content-Disposition \(.*\) is not a recognized value.'):
rest.setContentDisposition('filename', 'unknown', False)
with six.assertRaisesRegex(
self, rest.RestException, 'Error: Content-Disposition filename is empty.'):
rest.setContentDisposition('', setHeader=False)
self.assertEqual(rest.setContentDisposition(
'filename', setHeader=False),
'attachment; filename="filename"')
self.assertEqual(rest.setContentDisposition(
'filename', 'inline', setHeader=False),
'inline; filename="filename"')
self.assertEqual(rest.setContentDisposition(
'filename', 'form-data; name="chunk"', setHeader=False),
'form-data; name="chunk"; filename="filename"')
self.assertEqual(rest.setContentDisposition(
'file "name"', setHeader=False),
'attachment; filename="file \\"name\\""')
self.assertEqual(rest.setContentDisposition(
'file\\name', setHeader=False),
'attachment; filename="file\\\\name"')
self.assertEqual(rest.setContentDisposition(
u'\u043e\u0431\u0440\u0430\u0437\u0435\u0446', setHeader=False),
'attachment; filename=""; filename*=UTF-8\'\''
'%D0%BE%D0%B1%D1%80%D0%B0%D0%B7%D0%B5%D1%86')
self.assertEqual(rest.setContentDisposition(
u'\U0001f603', setHeader=False),
'attachment; filename=""; filename*=UTF-8\'\'%F0%9F%98%83')
开发者ID:adsorensen,项目名称:girder,代码行数:30,代码来源:rest_util_test.py
示例19: test
def test(self):
with six.assertRaisesRegex(self, AssertionError, '^Foo'):
raise AssertionError('Foo')
with self.assertRaises(AssertionError):
with six.assertRaisesRegex(self, AssertionError, r'^Foo'):
raise AssertionError('Bar')
开发者ID:Givemore,项目名称:fjord,代码行数:7,代码来源:test_six.py
示例20: test_metrics_raises
def test_metrics_raises(self):
sp0 = _pos_neg_block([])
spn = _pos_neg_block([2])
block = {'foo': sp0, 'bar:': spn} >> tdb.Concat()
six.assertRaisesRegex(
self, TypeError, 'Metric [a-z]+tive has incompatible types',
tdc.Compiler.create, block)
开发者ID:wangbosdqd,项目名称:fold,代码行数:7,代码来源:metrics_test.py
注:本文中的six.assertRaisesRegex函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论