本文整理匯總了Python中six.assertRaisesRegex方法的典型用法代碼示例。如果您正苦於以下問題:Python six.assertRaisesRegex方法的具體用法?Python six.assertRaisesRegex怎麽用?Python six.assertRaisesRegex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類six
的用法示例。
在下文中一共展示了six.assertRaisesRegex方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_validate_params
# 需要導入模塊: import six [as 別名]
# 或者: from six import assertRaisesRegex [as 別名]
def test_validate_params(self):
"""Test that `KerasImageFileEstimator._validateParams` method works as expected"""
kifest = KerasImageFileEstimator()
# should raise an error to define required parameters
# assuming at least one param without default value
six.assertRaisesRegex(self, ValueError, 'defined', kifest._validateParams, {})
kifest.setParams(imageLoader=_load_image_from_uri, inputCol='c1', labelCol='c2')
kifest.setParams(modelFile='/path/to/file.ext')
# should raise an error to define or tune parameters
# assuming at least one tunable param without default value
six.assertRaisesRegex(self, ValueError, 'tuned', kifest._validateParams, {})
kifest.setParams(kerasOptimizer='adam', kerasLoss='mse', kerasFitParams={})
kifest.setParams(outputCol='c3', outputMode='vector')
# should raise an error to not override
six.assertRaisesRegex(
self, ValueError, 'not tuned', kifest._validateParams, {kifest.imageLoader: None})
# should pass test on supplying all parameters
self.assertTrue(kifest._validateParams({}))
示例2: test_get_pull_request
# 需要導入模塊: import six [as 別名]
# 或者: from six import assertRaisesRegex [as 別名]
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",
)
示例3: test_get_obj_from_path
# 需要導入模塊: import six [as 別名]
# 或者: from six import assertRaisesRegex [as 別名]
def test_get_obj_from_path(self):
"""Tests for get_obj_from_path."""
# Simple issue case.
result = pss.get_obj_from_path("/test/issue/1")
self.assertEqual(result.id, 1)
# Simple PR case.
result = pss.get_obj_from_path("/test/pull-request/3")
self.assertEqual(result.id, 3)
# Non-existent repo.
six.assertRaisesRegex(
self,
PagureEvException,
r"Project 'foo' not found",
pss.get_obj_from_path,
"/foo/issue/1",
)
# NOTE: we cannot test the 'Invalid object provided' exception
# as it's a backup (current code will never hit it)
示例4: testParseBadEnumValue
# 需要導入模塊: import six [as 別名]
# 或者: from six import assertRaisesRegex [as 別名]
def testParseBadEnumValue(self, message_module):
message = message_module.TestAllTypes()
text = 'optional_nested_enum: BARR'
six.assertRaisesRegex(self,
text_format.ParseError,
(r'1:23 : Enum type "\w+.TestAllTypes.NestedEnum" '
r'has no value named BARR.'),
text_format.Parse, text, message)
message = message_module.TestAllTypes()
text = 'optional_nested_enum: 100'
six.assertRaisesRegex(self,
text_format.ParseError,
(r'1:23 : Enum type "\w+.TestAllTypes.NestedEnum" '
r'has no value with number 100.'),
text_format.Parse, text, message)
示例5: check_type_mismatch
# 需要導入模塊: import six [as 別名]
# 或者: from six import assertRaisesRegex [as 別名]
def check_type_mismatch(self, x_data, retain):
xp = backend.get_array_module(x_data)
class DummyFunction(chainer.Function):
label = 'dummy_function'
def forward(self, inputs):
if not retain:
self.retain_inputs(())
return xp.array(1, np.float32),
def backward(self, inputs, grads):
return [1]
x = chainer.Variable(x_data)
y = DummyFunction()(x)
with six.assertRaisesRegex(self, TypeError, 'dummy_function'):
y.backward()
示例6: check_dtype_mismatch
# 需要導入模塊: import six [as 別名]
# 或者: from six import assertRaisesRegex [as 別名]
def check_dtype_mismatch(self, x_data, retain):
xp = backend.get_array_module(x_data)
class DummyFunction(chainer.Function):
label = 'dummy_function'
def forward(self, inputs):
if not retain:
self.retain_inputs(())
return xp.array(1, np.float32),
def backward(self, inputs, grads):
return xp.array([1], np.int32),
x = chainer.Variable(x_data)
y = DummyFunction()(x)
with six.assertRaisesRegex(self, TypeError, 'dummy_function'):
y.backward()
示例7: check_shape_mismatch
# 需要導入模塊: import six [as 別名]
# 或者: from six import assertRaisesRegex [as 別名]
def check_shape_mismatch(self, x_data, retain):
xp = backend.get_array_module(x_data)
class DummyFunction(chainer.Function):
label = 'dummy_function'
def forward(self, inputs):
if not retain:
self.retain_inputs(())
return xp.array(1, np.float32),
def backward(self, inputs, grads):
return xp.array([1, 2], np.float32),
x = chainer.Variable(x_data)
y = DummyFunction()(x)
with six.assertRaisesRegex(self, ValueError, 'dummy_function'):
y.backward()
示例8: test_do_not_create_insecure_secret_keys
# 需要導入模塊: import six [as 別名]
# 或者: from six import assertRaisesRegex [as 別名]
def test_do_not_create_insecure_secret_keys(self, mocks, mock_consul):
"""
Test that if we have a brand-new instance with no appservers, we refuse to create insecure
keys for those appservers if we don't have a secure secret key for the instance.
"""
instance = OpenEdXInstanceFactory()
instance.secret_key_b64encoded = ''
instance.save()
expected_error_string = re.escape(
'Attempted to create secret key for instance {}, but no master key present.'.format(instance)
)
# Six provides a compatibility method for assertRaisesRegex, since the method
# is named differently between Py2k and Py3k.
with six.assertRaisesRegex(self, ValueError, expected_error_string):
instance.spawn_appserver()
示例9: test_quit_problems
# 需要導入模塊: import six [as 別名]
# 或者: from six import assertRaisesRegex [as 別名]
def test_quit_problems(self):
comm.start_cluster('127.0.0.1', 7100)
comm.join_cluster('127.0.0.1', 7100, '127.0.0.1', 7101)
comm.replicate('127.0.0.1', 7100, '127.0.0.1', 7102)
time.sleep(1)
rc = StrictRedisCluster(
startup_nodes=[{
'host': '127.0.0.1',
'port': 7100
}],
decode_responses=True)
for i in range(20):
rc.set('key_%s' % i, 'value_%s' % i)
for i in range(20):
self.assertEqual('value_%s' % i, rc.get('key_%s' % i))
nodes = base.list_nodes('127.0.0.1', 7100)
self.assertEqual(3, len(nodes))
self.assertEqual(
list(range(8192)), nodes[('127.0.0.1', 7101)].assigned_slots)
self.assertEqual(
list(range(8192, 16384)), nodes[('127.0.0.1',
7100)].assigned_slots)
for i in range(20):
rc.delete('key_%s' % i)
six.assertRaisesRegex(self, ValueError,
'^The master still has slaves$',
comm.quit_cluster, '127.0.0.1', 7100)
comm.quit_cluster('127.0.0.1', 7102)
comm.quit_cluster('127.0.0.1', 7101)
six.assertRaisesRegex(self, ValueError, '^This is the last node',
comm.quit_cluster, '127.0.0.1', 7100)
comm.shutdown_cluster('127.0.0.1', 7100)
示例10: test_get_issue
# 需要導入模塊: import six [as 別名]
# 或者: from six import assertRaisesRegex [as 別名]
def test_get_issue(self):
"""Tests for _get_issue."""
# Simple case: get the existing issue from the existing repo.
result = pss._get_issue(self.repo, "1")
self.assertEqual(result.id, 1)
# Issue that doesn't exist.
six.assertRaisesRegex(
self,
PagureEvException,
r"Issue '3' not found",
pss._get_issue,
self.repo,
"3",
)
# Private issue (for now we don't handle auth).
six.assertRaisesRegex(
self,
PagureEvException,
r"issue is private",
pss._get_issue,
self.repo,
"2",
)
# Issue from a project with no issue tracker.
six.assertRaisesRegex(
self,
PagureEvException,
r"No issue tracker found",
pss._get_issue,
self.repo2,
"1",
)
示例11: test_compute_create_time_fail
# 需要導入模塊: import six [as 別名]
# 或者: from six import assertRaisesRegex [as 別名]
def test_compute_create_time_fail(self, unused_name, age):
del unused_name
with six.assertRaisesRegex(self, ValueError, 'Unable to parse age string'):
_ = param_util.age_to_create_time(age)
示例12: test_timeout_in_seconds_fail
# 需要導入模塊: import six [as 別名]
# 或者: from six import assertRaisesRegex [as 別名]
def test_timeout_in_seconds_fail(self, unused_name, timeout):
del unused_name
with six.assertRaisesRegex(self, ValueError, 'Unable to parse interval'):
_ = param_util.timeout_in_seconds(timeout)
示例13: test_log_interval_in_seconds_fail
# 需要導入模塊: import six [as 別名]
# 或者: from six import assertRaisesRegex [as 別名]
def test_log_interval_in_seconds_fail(self, unused_name, log_interval):
del unused_name
with six.assertRaisesRegex(self, ValueError, 'Unable to parse interval'):
_ = param_util.log_interval_in_seconds(log_interval)
示例14: test_output_val_err
# 需要導入模塊: import six [as 別名]
# 或者: from six import assertRaisesRegex [as 別名]
def test_output_val_err(self, unused_name, recursive, uri, regex):
del unused_name
file_param_util = param_util.OutputFileParamUtil('output')
with six.assertRaisesRegex(self, ValueError, regex):
file_param_util.parse_uri(uri, recursive)
示例15: test_file_provider_err
# 需要導入模塊: import six [as 別名]
# 或者: from six import assertRaisesRegex [as 別名]
def test_file_provider_err(self, unused_name, uri, regex):
del unused_name
file_param_util = param_util.OutputFileParamUtil('output')
with six.assertRaisesRegex(self, ValueError, regex):
file_param_util.parse_file_provider(uri)