本文整理汇总了Python中six.assertRaisesRegex函数的典型用法代码示例。如果您正苦于以下问题:Python assertRaisesRegex函数的具体用法?Python assertRaisesRegex怎么用?Python assertRaisesRegex使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了assertRaisesRegex函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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'))
示例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'})
示例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, '')
示例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'))
示例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)
示例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))
示例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)
示例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)
示例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)
示例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)
示例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)
示例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
示例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()
示例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)