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

Python pytest.raises_regexp函数代码示例

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

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



在下文中一共展示了raises_regexp函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_int_in_list_in_dict_in_list_in_dict

    def test_int_in_list_in_dict_in_list_in_dict(self):
        spec = translate({'foo': [{'bar': [int]}]})

        with raises_regexp(ValidationError,
            "'foo' value must be list"):
            spec({'foo': None})

        with raises_regexp(ValidationError,
            "'foo' value item #0: 'bar' value must be list"):
            spec({'foo': [{'bar': None}]})

        with raises_regexp(ValidationError,
            "'foo' value lacks item: must be dict"):
            spec({'foo': []})

        with raises_regexp(ValidationError,
           "'foo' value item #0: 'bar' value lacks item: must be int"):
            spec({'foo': [{'bar': []}]})

        spec({'foo': [{'bar': [1]}]})
        spec({'foo': [{'bar': [1, 2]}]})

        with raises_regexp(ValidationError,
            "'foo' value item #0: 'bar' value item #1: must be int"):
            spec({'foo': [{'bar': [1, 'bogus']}]})
开发者ID:neithere,项目名称:monk,代码行数:25,代码来源:validation_tests.py


示例2: test_custom_validators_in_dict_keys

    def test_custom_validators_in_dict_keys(self):
        # FIXME this is one of those cases where "human-readable" errors
        #       are much less readable than "mechanical" ones (as before).
        #       Can we do anything?

        day_note_schema = translate({
            InRange(2000, 2020): {
                InRange(1, 12): {
                    InRange(1, 31): str,
                },
            },
        })
        good_note = {2013: {12: {9:  'it is a good day today'}}}
        bad_note1 = {1999: {12: {9:  'wrong year: below min'}}}
        bad_note2 = {2013: {13: {9:  'wrong month: above max'}}}
        bad_note3 = {2013: {12: {40: 'wrong day of month: above max'}}}

        day_note_schema(good_note)

        #with raises_regexp(InvalidKeys, '^1999$'):
        with raises_regexp(ValidationError,
                           "^must not have keys like 1999$"):
            day_note_schema(bad_note1)

        #with raises_regexp(InvalidKeys, '^2013: 13$'):
        with raises_regexp(ValidationError,
                           "^2013 value must not have keys like 13$"):
            day_note_schema(bad_note2)

        #with raises_regexp(InvalidKeys, '^2013: 12: 40$'):
        with raises_regexp(ValidationError,
                           "^in 2013 \(12 value must not have keys like 40\)$"):
            day_note_schema(bad_note3)
开发者ID:neithere,项目名称:monk,代码行数:33,代码来源:validation_tests.py


示例3: test_int_in_list

    def test_int_in_list(self):
        spec = ListOf(int)

        # outer value is missing

        with raises_regexp(ValidationError, 'must be list'):
            spec(None)

        # outer value is present, inner value is missing

        with raises_regexp(ValidationError, 'lacks item: must be int'):
            spec([])

        # outer value is present, inner optional value is missing

        relaxed_spec = ListOf(int) | None
        relaxed_spec([])

        # inner value is present but is None

        with raises_regexp(ValidationError, 'item #0: must be int'):
            spec([None])

        # inner value is present

        spec([123])

        # multiple inner values are present

        spec([123, 456])

        # one of the inner values is of a wrong type

        with raises_regexp(ValidationError, 'item #1: must be int'):
            spec([123, 'bogus'])
开发者ID:neithere,项目名称:monk,代码行数:35,代码来源:validation_tests.py


示例4: test_schemed_dict_in_list

    def test_schemed_dict_in_list(self):
        spec = ListOf({'foo': int})

        # dict in list: missing key

        with raises(ValidationError):
            spec([{}])

        with raises_regexp(ValidationError, "item #1: must have keys: 'foo'"):
            spec([{'foo': 123}, {}])

        # dict in list: missing value

        with raises_regexp(ValidationError, "item #0: 'foo' value must be int"):
            spec([{'foo': None}])

        with raises_regexp(ValidationError, "item #1: 'foo' value must be int"):
            spec([{'foo': 123}, {'foo': None}])

        # multiple innermost values are present

        spec([{'foo': 123}])
        spec([{'foo': 123}, {'foo': 456}])

        # one of the innermost values is of a wrong type

        with raises_regexp(ValidationError, "item #2: 'foo' value must be int"):
            spec([{'foo': 123}, {'foo': 456}, {'foo': 'bogus'}])
开发者ID:neithere,项目名称:monk,代码行数:28,代码来源:validation_tests.py


示例5: test_exists

def test_exists():
    must_exist = Exists()

    assert repr(must_exist) == 'must exist'

    with raises_regexp(ValidationError, 'must exist'):
        must_exist(MISSING)

    must_exist(None)
    must_exist(0)
    must_exist(False)
    must_exist('foo')
    must_exist([])

    # negated

    must_not_exist = ~Exists()

    assert repr(must_not_exist) == 'must not exist'

    must_not_exist(MISSING)

    with raises_regexp(ValidationError, 'must not exist'):
        must_not_exist(None)

    with raises_regexp(ValidationError, 'must not exist'):
        must_not_exist('foo')
开发者ID:neithere,项目名称:monk,代码行数:27,代码来源:validators_tests.py


示例6: test_list_of_any

def test_list_of_any():
    v = ListOfAny(IsA(str))

    assert repr(v) == 'ListOfAny(must be str)'

    with raises_regexp(ValidationError, '^must be list$'):
        v('foo')

    with raises_regexp(ValidationError, '^lacks item: must be str$'):
        v([])

    # positive

    v(['foo'])

    v(['foo', 123])

    with raises_regexp(ValidationError,
        '^item #0: must be str or item #1: must be str$'):
        v([123, 5.5])

    # negated

    v = ~v

    with raises_regexp(ValidationError, '^~ListOfAny\(must be str\)$'):
        v(['foo'])

    with raises_regexp(ValidationError, '^~ListOfAny\(must be str\)$'):
        v(['foo', 123])

    v([123, 5.5])
开发者ID:neithere,项目名称:monk,代码行数:32,代码来源:validators_tests.py


示例7: test_pytest_raises_regexp

def test_pytest_raises_regexp():
    def f():
        raise ValueError('f')

    pytest.raises_regexp(ValueError, 'f', f)
    with pytest.raises_regexp(ValueError, 'f'):
        f()
开发者ID:xinming90,项目名称:python-misc,代码行数:7,代码来源:test_pytest.py


示例8: test_functional_syntax

def test_functional_syntax():
    raises_regexp(
        ExpectedException,
        r"Args and kwargs raised: .*param1.*param4",
        function_to_test_with_args_and_kwargs,
        'param1', 'param2', kwarg1='param3', kwarg2='param4'
    )
开发者ID:FRidh,项目名称:pytest-raisesregexp,代码行数:7,代码来源:test_plugin.py


示例9: test_source_branch_does_not_exist_caught

 def test_source_branch_does_not_exist_caught(self, empty_dendrifier):
     repo = empty_dendrifier.repo
     # Doesn't really matter that these branches are unrelated:
     dendrify.create_base(repo, 'test-base')
     pytest.raises_regexp(ValueError, 'source branch "linear" does not exist',
                          empty_dendrifier.dendrify,
                          'dendrified', 'test-base', 'linear')
开发者ID:bennorth,项目名称:git-dendrify,代码行数:7,代码来源:test_dendrify.py


示例10: test_nonlinear_ancestry

 def test_nonlinear_ancestry(self, empty_dendrifier):
     repo = empty_dendrifier.repo
     populate_repo(repo, ['.develop', '.', '.', '[', '.', '.', ']'])
     empty_dendrifier.dendrify('dendrified', 'develop', 'linear')
     pytest.raises_regexp(ValueError, 'ancestry of "dendrified" is not linear',
                          empty_dendrifier.dendrify,
                          're-dendrified', 'develop', 'dendrified')
开发者ID:bennorth,项目名称:git-dendrify,代码行数:7,代码来源:test_dendrify.py


示例11: test_corrupt_index

 def test_corrupt_index(self, tmpfile):
     with io.open(tmpfile, 'wb') as f:
         f.write(FORMAT_STRING)
         write_i64(f, FORMAT_VERSION)
         f.write(b'foo')
     pytest.raises_regexp(IOError, 'unable to read index',
                          File, tmpfile)
开发者ID:aldanor,项目名称:blox,代码行数:7,代码来源:test_file.py


示例12: test_list_of_all

def test_list_of_all():
    v = ListOfAll(IsA(str))

    assert repr(v) == 'ListOfAll(must be str)'

    with raises_regexp(ValidationError, '^must be list$'):
        v('foo')

    with raises_regexp(ValidationError, '^lacks item: must be str$'):
        v([])

    # positive

    v(['foo'])

    v(['foo', 'bar'])

    with raises_regexp(ValidationError, '^item #2: must be str$'):
        v(['foo', 'bar', 123])

    # negated

    v = ~v

    with raises_regexp(ValidationError, '^~ListOfAll\(must be str\)$'):
        v(['foo'])

    with raises_regexp(ValidationError, '^~ListOfAll\(must be str\)$'):
        v(['foo', 'bar'])

    v(['foo', 'bar', 123])
开发者ID:neithere,项目名称:monk,代码行数:31,代码来源:validators_tests.py


示例13: test_fail_on_write

 def test_fail_on_write(self, tmpfile):
     with File(tmpfile, 'w') as f:
         f.write_json('a', 42)
         pytest.raises_regexp(ValueError, 'unable to serialize: invalid dtype',
                              f.write_array, 'b', {})
     with File(tmpfile) as f:
         assert list(f) == ['a']
         assert f.read('a') == 42
开发者ID:aldanor,项目名称:blox,代码行数:8,代码来源:test_file.py


示例14: test_linear_ancestry_reaches_root

 def test_linear_ancestry_reaches_root(self, empty_dendrifier):
     repo = empty_dendrifier.repo
     populate_repo(repo, ['.develop', '.', '.'])
     # Deliberately swap args to linear_ancestry() such that the
     # 'base' is not an ancestor of the branch:
     pytest.raises_regexp(ValueError, '"linear" is not an ancestor of "develop"',
                          empty_dendrifier.linear_ancestry,
                          'linear', 'develop')
开发者ID:bennorth,项目名称:git-dendrify,代码行数:8,代码来源:test_dendrify.py


示例15: test_dendrified_ancestry_reaches_root

 def test_dendrified_ancestry_reaches_root(self, empty_dendrifier):
     repo = empty_dendrifier.repo
     populate_repo(repo, ['.develop', '.', '.', '[', '.', '.', ']'])
     empty_dendrifier.dendrify('dendrified', 'develop', 'linear')
     # Deliberately swap args so that base is not ancestor of branch:
     pytest.raises_regexp(ValueError, '"dendrified" is not an ancestor of "develop"',
                          empty_dendrifier.linearize,
                          'linear-1', 'dendrified', 'develop')
开发者ID:bennorth,项目名称:git-dendrify,代码行数:8,代码来源:test_dendrify.py


示例16: test_destination_branch_exists_caught

 def test_destination_branch_exists_caught(self, empty_dendrifier):
     repo = empty_dendrifier.repo
     # Doesn't really matter that these branches are unrelated:
     dendrify.create_base(repo, 'test-base')
     dendrify.create_base(repo, 'dendrified')
     dendrify.create_base(repo, 'linear')
     pytest.raises_regexp(ValueError, 'destination branch "dendrified" exists',
                          empty_dendrifier.dendrify,
                          'dendrified', 'test-base', 'linear')
开发者ID:bennorth,项目名称:git-dendrify,代码行数:9,代码来源:test_dendrify.py


示例17: test_mode_writable

 def test_mode_writable(self, tmpfile):
     raises_regexp(ValueError, 'invalid mode', File, tmpfile, 'foo')
     f1 = File(tmpfile)
     assert f1.mode == 'r' and not f1.writable
     f2 = File(tmpfile, 'w')
     assert f2.mode == 'r+' and f2.writable
     f3 = File(tmpfile, 'r')
     assert f3.mode == 'r' and not f3.writable
     f4 = File(tmpfile, 'r+')
     assert f4.mode == 'r+' and f4.writable
开发者ID:aldanor,项目名称:blox,代码行数:10,代码来源:test_file.py


示例18: test_invert_requirement

def test_invert_requirement():
    says_hello = Equals('hello')
    says_hello('hello')
    with raises_regexp(ValidationError, "^must equal 'hello'$"):
        says_hello('bye')

    says_not_hello = ~says_hello
    with raises_regexp(ValidationError, "^not \(must equal 'hello'\)$"):
        says_not_hello('hello')
    says_not_hello('bye')
开发者ID:neithere,项目名称:monk,代码行数:10,代码来源:validators_tests.py


示例19: test_combinator_all

def test_combinator_all():
    v = All([ Length(min=2), Length(max=3) ])

    assert repr(v) == '(must have length of 2.. and must have length of ..3)'

    with raises_regexp(ValidationError, '^must have length of 2\.\.$'):
        v('f')
    v('fo')
    v('foo')
    with raises_regexp(ValidationError, '^must have length of \.\.3$'):
        v('fooo')
开发者ID:neithere,项目名称:monk,代码行数:11,代码来源:validators_tests.py


示例20: test_list_with_opt_elem

    def test_list_with_opt_elem(self):

        v = translate([optional(str)])

        with raises_regexp(ValidationError, 'must be list'):
            v(None)
        v([])
        with raises_regexp(ValidationError, 'must be str or must not exist'):
            v([None])
        v(['hi'])
        with raises_regexp(ValidationError, 'must be str'):
            v([1234])
开发者ID:neithere,项目名称:monk,代码行数:12,代码来源:validation_tests.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python pytest.skip函数代码示例发布时间:2022-05-27
下一篇:
Python pytest.raises函数代码示例发布时间: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