• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python trivial.assert_raises函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中nose.tools.trivial.assert_raises函数的典型用法代码示例。如果您正苦于以下问题:Python assert_raises函数的具体用法?Python assert_raises怎么用?Python assert_raises使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了assert_raises函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:indera,项目名称:flask-easymode,代码行数:26,代码来源:test_decorators.py


示例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'))))
开发者ID:rtrwalker,项目名称:geotecha,代码行数:8,代码来源:test_mp_laplace.py


示例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)
开发者ID:rtrwalker,项目名称:geotecha,代码行数:8,代码来源:test_inputoutput.py


示例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') ))
开发者ID:rtrwalker,项目名称:geotecha,代码行数:11,代码来源:test_mp_laplace.py


示例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])))        
开发者ID:rtrwalker,项目名称:piecewisefns,代码行数:11,代码来源:test_piecewise_linear_1d.py


示例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)
开发者ID:mikyes,项目名称:geotecha,代码行数:13,代码来源:test_one_d.py


示例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))
开发者ID:rtrwalker,项目名称:geotecha,代码行数:13,代码来源:test_mp_laplace.py


示例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())
开发者ID:rtrwalker,项目名称:geotecha,代码行数:14,代码来源:test_inputoutput.py


示例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]])
开发者ID:rtrwalker,项目名称:geotecha,代码行数:16,代码来源:test_inputoutput.py


示例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)))
开发者ID:mikyes,项目名称:geotecha,代码行数:17,代码来源:test_one_d.py


示例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])))
开发者ID:rtrwalker,项目名称:piecewisefns,代码行数:17,代码来源:test_piecewise_linear_1d.py


示例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)
开发者ID:rtrwalker,项目名称:geotecha,代码行数:19,代码来源:test_inputoutput.py


示例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'))
开发者ID:rtrwalker,项目名称:geotecha,代码行数:21,代码来源:test_inputoutput.py


示例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)
开发者ID:rtrwalker,项目名称:geotecha,代码行数:21,代码来源:test_inputoutput.py


示例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)
开发者ID:agapow,项目名称:py-konval,代码行数:16,代码来源:test_konval.py


示例16: test_s_n_unequal_len

 def test_s_n_unequal_len(self):
     assert_raises(ValueError, u_piecewise_constant, [2,4], [1],1)
开发者ID:mikyes,项目名称:geotecha,代码行数:2,代码来源:test_smear_zones.py


示例17: test_kap_less_than_zero

 def test_kap_less_than_zero(self):
     assert_raises(ValueError, u_piecewise_constant,[1.5,1.6,2], [-2,1,1],1)
开发者ID:mikyes,项目名称:geotecha,代码行数:2,代码来源:test_smear_zones.py


示例18: test_s_less_than_one

 def test_s_less_than_one(self):
     assert_raises(ValueError, u_piecewise_constant,[0.5,1,2], [1,1,1],1 )
开发者ID:mikyes,项目名称:geotecha,代码行数:2,代码来源:test_smear_zones.py


示例19: test_s_increasing

 def test_s_increasing(self):
     assert_raises(ValueError, u_piecewise_constant,[1.5,1,2], [1,1,1],1 )
开发者ID:mikyes,项目名称:geotecha,代码行数:2,代码来源:test_smear_zones.py


示例20: test_si_less_than_1

 def test_si_less_than_1(self):
     assert_raises(ValueError, u_piecewise_constant, [2, 4],[2,1], 0.5)
开发者ID:mikyes,项目名称:geotecha,代码行数:2,代码来源:test_smear_zones.py



注:本文中的nose.tools.trivial.assert_raises函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python trivial.eq_函数代码示例发布时间:2022-05-27
下一篇:
Python trivial.assert_equal函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap