本文整理汇总了Python中nose.tools.trivial.assert_raises函数的典型用法代码示例。如果您正苦于以下问题:Python assert_raises函数的具体用法?Python assert_raises怎么用?Python assert_raises使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了assert_raises函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_inject
def test_inject():
em, app = _setup()
em.enable_xhr(app)
em.enable_injection(app)
em.add_injectable(InjectableClass)
with app.test_client() as c:
r = c.get('/inject/joe-slug')
assert_in('joe-slug', r.data)
r = c.get('/inject-as-arg/joe-slug')
assert_in('joe-slug', r.data)
with assert_raises(RuntimeError):
r = c.get('/inject-non-injectable/here-comes-an-error')
em.add_injectable(NonInjectableClass)
with assert_raises(RuntimeError):
r = c.get('/inject-non-injectable/still-going-to-fail')
with assert_raises(AttributeError):
r = c.get('/inject-skip-by-default')
r = c.get('/inject-list-denoting/apples')
assert_equals(r.status_code, 200)
示例2: test_talbot_dps_fail
def test_talbot_dps_fail():
"test for Talbot numerical inverse Laplace with mpmath insufficient dps"
a = Talbot(f=f1, n=200, shift=0.0, dps=None)
#t=0 raise error:
assert_raises(ValueError, a, 0)
#single value of t:
ok_(not mpallclose(a(1), mpmath.exp(mpmath.mpf('-1.0'))))
示例3: test_check_zero_or_all
def test_check_zero_or_all(self):
a = InputFileLoaderCheckerSaver()
a.a=4
a.b=6
a.c=None
a._zero_or_all = ['a b c'.split()]
assert_raises(ValueError, a.check_input_attributes)
示例4: test_talbot_dps_precision
def test_talbot_dps_precision():
"""test for Talbot numerical inverse Laplace with mpmath high precision"""
a = Talbot(f=f1, n=200, shift=0.0, dps=95)
#t=0 raise error:
assert_raises(ValueError, a, 0)
#single value of t:
ok_(mpallclose(a(1),
mpmath.exp(mpmath.mpf('-1.0')),
atol=mpmath.mpf('1e-80'),
rtol=mpmath.mpf('1e-40') ))
示例5: test_force_non_decreasing
def test_force_non_decreasing(self):
"""test force_non_decreasing"""
x, y = force_non_decreasing(self.two_ramps_two_steps['x'], self.two_ramps_two_steps['y'])
ok_(np.all(x==np.array(self.two_ramps_two_steps['x'])))
ok_(np.all(y==np.array(self.two_ramps_two_steps['y'])))
assert_raises(ValueError, force_non_decreasing, self.switch_back['x'])
x, y = force_non_decreasing(self.two_ramps_two_steps_reverse['x'], self.two_ramps_two_steps_reverse['y'])
ok_(np.all(x==np.array([-3, -3, -2.5, -1, -0.4, -0.4, 0])))
ok_(np.all(y==np.array(self.two_ramps_two_steps['y'][::-1])))
示例6: test_rgb_shade
def test_rgb_shade():
"""some tests for rgb_shade"""
# rgb_shade(rgb, factor=1, scaled=True)
ok_(np.allclose(rgb_shade((0.4, 0.8, 0.2)), (0.4, 0.8, 0.2)))
ok_(np.allclose(rgb_shade((0.4, 0.8, 0.2), factor=0.5),
(0.2, 0.4, 0.1)))
ok_(np.allclose(rgb_shade((0.4, 0.8, 0.2, 0.8), factor=0.5),
(0.2, 0.4, 0.1,0.8)))
# assert_equal(rgb_shade((0.4, 0.8, 0.2)), (0.4, 0.8, 0.2))
assert_raises(ValueError, rgb_shade,(0.5,0.5,0.5),factor=1.5)
assert_raises(ValueError, rgb_shade,(0.5,0.5,0.5),factor=-0.5)
示例7: test_talbot
def test_talbot():
"""test for Talbot numerical inverse Laplace with mpmath"""
a = Talbot(f=f1, n=24, shift=0.0, dps=None)
#t=0 raise error:
assert_raises(ValueError, a, 0)
#single value of t:
ok_(mpallclose(a(1), mpmath.exp(mpmath.mpf('-1.0'))))
#2 values of t:
ans = np.array([mpmath.exp(mpmath.mpf('-1.0')),
mpmath.exp(mpmath.mpf('-2.0'))])
ok_(mpallclose(a([1,2]),ans))
示例8: test_make_module_from_text
def test_make_module_from_text():
"""test for make_module_from_text function"""
#make_module_from_text(reader)
reader = textwrap.dedent("""\
a = 2
""")
ok_(isinstance(make_module_from_text(reader), type(textwrap)))
assert_equal(make_module_from_text(reader).a, 2)
assert_raises(SyntaxError,make_module_from_text,
reader,
syntax_checker=SyntaxChecker())
示例9: test_check_attribute_is_list
def test_check_attribute_is_list():
"""test for check_attribute_is_list function"""
#check_attribute_is_list(obj, attributes=[], force_list=False)
a = EmptyClass()
a.a = 2
a.b = 4
a.c = [8]
a.d = [6,7]
assert_raises(ValueError, check_attribute_is_list, a, attributes=['a','b','c'], force_list=False)
check_attribute_is_list(a, attributes=['a','b','c'], force_list=True)
assert_equal([a.a,a.b,a.c,a.d], [[2],[4],[8], [6,7]])
示例10: test_rgb_tint
def test_rgb_tint():
"""some tests for rgb_tint"""
# rgb_tint(rgb, factor=1, scaled=True)
ok_(np.allclose(rgb_tint((0.4, 0.8, 0.2)), (0.4, 0.8, 0.2)))
ok_(np.allclose(rgb_tint((0.4, 0.8, 0.2), factor=0.5),
(0.7, 0.9, 0.6)))
# assert_equal(rgb_tint((0.4, 0.8, 0.2)), (0.4, 0.8, 0.2))
assert_raises(ValueError, rgb_tint,(0.5,0.5,0.5),factor=1.5)
assert_raises(ValueError, rgb_tint,(0.5,0.5,0.5),factor=-0.5)
ok_(np.allclose(rgb_tint((155, 205, 55), factor=0.5, scaled=False),
(205, 230, 155)))
ok_(np.allclose(rgb_tint((155, 205, 55, 0.5), factor=0.5, scaled=False),
(205, 230, 155, 0.5)))
示例11: test_force_strictly_increasing
def test_force_strictly_increasing(self):
"""test force_strictly_increasing"""
x, y = force_strictly_increasing(self.two_ramps['x'], eps=0.01)
ok_(np.all(x==np.array(self.two_ramps['x'])))
assert_raises(ValueError, force_strictly_increasing, self.switch_back['x'])
x, y = force_strictly_increasing(self.two_ramps_two_steps['x'], self.two_ramps_two_steps['y'], keep_end_points = True, eps=0.01)
ok_(np.allclose(x, np.array([0, 0.38, 0.4, 1, 2.5, 2.99, 3])))
ok_(np.allclose(y, np.array(self.two_ramps_two_steps['y'])))
x, y = force_strictly_increasing(self.two_ramps_two_steps['x'], self.two_ramps_two_steps['y'], keep_end_points = False, eps=0.01)
ok_(np.allclose(x, np.array([0, 0.4, 0.41, 1, 2.5, 3, 3.02])))
x, y = force_strictly_increasing(self.two_ramps_two_steps_reverse['x'], self.two_ramps_two_steps_reverse['y'], keep_end_points = False, eps=0.01)
ok_(np.allclose(x, np.array([-3, -2.99, -2.5, -1, -0.4, -0.38, 0])))
ok_(np.allclose(y, np.array(self.two_ramps_two_steps['y'][::-1])))
示例12: test_check_attribute_PolyLines_have_same_x_limits
def test_check_attribute_PolyLines_have_same_x_limits():
"""test for check_attribute_PolyLines_have_same_x_limits function"""
#check_attribute_PolyLines_have_same_x_limits(obj, attributes=[])
a = EmptyClass()
a.a = None
a.b = PolyLine([0,4],[4,5])
a.c = [PolyLine([0,4],[6,3]), PolyLine([0,5],[6,3])]
a.d = PolyLine([0,2,4], [3,2,4])
assert_raises(ValueError, check_attribute_PolyLines_have_same_x_limits, a,
attributes=[['a','b','c','d']])
assert_raises(ValueError, check_attribute_PolyLines_have_same_x_limits, a,
attributes=[['c']])
assert_equal(check_attribute_PolyLines_have_same_x_limits(a,
attributes=[['a','b','d']]), None)
示例13: test_SyntaxChecker
def test_SyntaxChecker():
"""test for SytaxChecker class"""
syntax_checker=SyntaxChecker(['ast','builtin','numpy','PolyLine'])
assert_raises(SyntaxError, syntax_checker.visit,
ast.parse('import math', mode='exec'))
assert_raises(SyntaxError, syntax_checker.visit,
ast.parse('from math import cos', mode='exec'))
assert_raises(SyntaxError, syntax_checker.visit,
ast.parse('eval(44*2)', mode='exec'))
assert_raises(SyntaxError, syntax_checker.visit,
ast.parse('exec("a=34")', mode='exec'))
assert_raises(SyntaxError, syntax_checker.visit,
ast.parse("""[x for x in ().__class__.__bases__[0].__subclasses__()
if x.__name__ == 'Popen'][0](['ls', '-la']).wait()""", mode='exec'))
示例14: test_check_attribute_pairs_have_equal_length
def test_check_attribute_pairs_have_equal_length():
"""test for check_attribute_pairs_have_equal_length function"""
#check_attribute_pairs_have_equal_length(obj, attributes=[])
a = EmptyClass()
a.a = None
a.b = [7, 8]
a.c = [8]
a.d = [6,7]
a.e = 8
# assert_raises(ValueError, check_attribute_pairs_have_equal_length, a,
# attributes=[['a','b']])
assert_raises(ValueError, check_attribute_pairs_have_equal_length, a,
attributes=[['b','c']])
assert_raises(TypeError, check_attribute_pairs_have_equal_length, a,
attributes=[['b','e']])
assert_equal(check_attribute_pairs_have_equal_length(a,
attributes=[['b','d']]), None)
示例15: test_or
def test_or():
string_validator = konval.types.IsType(str)
success_validator = konval.Konvalidator()
or_validator = konval.Or((string_validator, success_validator))
numerical_value = 123
assert_true(or_validator.validate(numerical_value))
assert_equal(or_validator.validate(numerical_value), numerical_value)
size_validator = konval.numbers.Minimum(200)
or_validator = konval.Or((string_validator, size_validator))
with assert_raises(konval.KonvalError):
or_validator(numerical_value)