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

Python test.raises函数代码示例

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

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



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

示例1: test_combo

    def test_combo(self):
        x_obj = qterm.Variable('x', pq('obj'))
        x_var = qterm.Variable('x', pq('?a'))
        phi_var = qterm.Constant('phi', pq('?b->bool'))
        phi_obj = qterm.Constant('phi', pq('obj->bool'))
        combo_var = term_builder.build_combination(phi_var, x_var)
        combo_obj = term_builder.build_combination(phi_obj, x_obj)
        combo_var2 = term_builder.build_combination(phi_var, x_obj)

        x, combo = unify_types([x_obj, combo_var])
        assert x == x_obj
        assert combo == combo_obj

        phi_a, phi_b = unify_types([phi_var, phi_obj])
        assert phi_a == phi_var
        assert phi_b == phi_obj

        combo_a, combo_b = unify_types([combo_var, combo_obj])
        assert combo_a == combo_obj
        assert combo_b == combo_obj

        combo_a, combo_b = unify_types([combo_var2, combo_obj])
        assert combo_a == combo_obj
        assert combo_b == combo_obj

        f = qterm.Variable('f', pq('?x->?y'))
        raises(UnificationError, term_builder.build_combination, f, f)
        raises(UnificationError, term_builder.build_combination, x_var, x_var)
开发者ID:cap,项目名称:cheqed,代码行数:28,代码来源:test_term_type_unifier.py


示例2: test_help

 def test_help(self):
     """tests getting help (returning the help_string so further tests can be done)"""
     stdout = sys.stdout
     helpfile = self.open_testfile("help.txt", "w")
     sys.stdout = helpfile
     try:
         test.raises(SystemExit, self.run_command, help=True)
     finally:
         sys.stdout = stdout
     helpfile.close()
     help_string = self.read_testfile("help.txt")
     print help_string
     convertsummary = self.convertmodule.__doc__.split("\n")[0]
     # the convertsummary might be wrapped. this will probably unwrap it
     assert convertsummary in help_string.replace("\n", " ")
     usageline = help_string[:help_string.find("\n")]
     # Different versions of optparse might contain either upper or 
     # lowercase versions of 'Usage:' and 'Options:', so we need to take 
     # that into account
     assert (usageline.startswith("Usage: ") or usageline.startswith("usage: ")) \
         and "[--version] [-h|--help]" in usageline
     options = help_string[help_string.find("ptions:\n"):]
     options = options[options.find("\n")+1:]
     options = self.help_check(options, "--progress=PROGRESS")
     options = self.help_check(options, "--version")
     options = self.help_check(options, "-h, --help")
     options = self.help_check(options, "--manpage")
     options = self.help_check(options, "--errorlevel=ERRORLEVEL")
     if psyco:
         options = self.help_check(options, "--psyco=MODE")
     options = self.help_check(options, "-i INPUT, --input=INPUT")
     options = self.help_check(options, "-x EXCLUDE, --exclude=EXCLUDE")
     options = self.help_check(options, "-o OUTPUT, --output=OUTPUT")
     return options
开发者ID:AlexArgus,项目名称:affiliates-lib,代码行数:34,代码来源:test_convert.py


示例3: test_too_much_colons

    def test_too_much_colons(self, p):
        s = """
        name = s
        key_format =     32s
        type = HashIndex
        hash_lim = 1
        make_key_value:
        1<=2:1:1,None
        make_key:
        1"""
        with raises(IndexCreatorFunctionException):
            p.parse(s, 'TestIndex')
        s2 = """
        name = s
        key_format =     32s
        type = HashIndex
        hash_lim = 1
        make_key_value:
        1<=2:1,None
        make_key:
        a>1::"""
        with raises(IndexCreatorFunctionException):
            p.parse(s2, 'TestIndex')

        s3 = """
        name = s
        key_format =     : 32s
        type = HashIndex
        hash_lim = 1
        make_key_value:
        1<=2:1,None
        make_key:
        a>1:1"""
        with raises(IndexCreatorValueException):
            p.parse(s3, 'TestIndex')
开发者ID:andy0130tw,项目名称:CodernityDB3,代码行数:35,代码来源:test_indexcreator_exec.py


示例4: test_filter_values_req_opt_2

def test_filter_values_req_opt_2():
    r = [
        to_dict(
            Attribute(
                friendly_name="surName",
                name="urn:oid:2.5.4.4",
                name_format="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"),
            ONTS),
        to_dict(
            Attribute(
                friendly_name="givenName",
                name="urn:oid:2.5.4.42",
                name_format="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"),
            ONTS),
        to_dict(
            Attribute(
                friendly_name="mail",
                name="urn:oid:0.9.2342.19200300.100.1.3",
                name_format="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"),
            ONTS)]
    o = [
        to_dict(
            Attribute(
                friendly_name="title",
                name="urn:oid:2.5.4.12",
                name_format="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"),
            ONTS)]

    ava = {"surname": ["Hedberg"], "givenName": ["Roland"],
           "eduPersonAffiliation": ["staff"], "uid": ["rohe0002"]}

    raises(MissingValue, "filter_on_attributes(ava, r, o)")
开发者ID:jakew1ll,项目名称:pysaml2,代码行数:32,代码来源:test_20_assertion.py


示例5: test_finditer

    def test_finditer(self):
        import re

        it = re.finditer("b(.)", "brabbel")
        assert "br" == it.next().group(0)
        assert "bb" == it.next().group(0)
        raises(StopIteration, it.next)
开发者ID:cimarieta,项目名称:usp,代码行数:7,代码来源:test_app_sre.py


示例6: test

def test():
    for puzzle in puzzles.itervalues():
        puzzle = load(puzzle)
        puzzle.solve()
        assert puzzle.is_solved()
    for puzzle in bad_puzzles.itervalues():
        raises(InconsistentPuzzleError, load(puzzle).solve)
开发者ID:karldickman,项目名称:sudoku,代码行数:7,代码来源:sudoku.py


示例7: test_filesystem_loader

def test_filesystem_loader():
    env = Environment(loader=filesystem_loader)
    tmpl = env.get_template('test.html')
    assert tmpl.render().strip() == 'BAR'
    tmpl = env.get_template('foo/test.html')
    assert tmpl.render().strip() == 'FOO'
    raises(TemplateNotFound, env.get_template, 'missing.html')
开发者ID:492852238,项目名称:SourceLearning,代码行数:7,代码来源:test_loaders.py


示例8: test_choice_loader

def test_choice_loader():
    env = Environment(loader=choice_loader)
    tmpl = env.get_template('justdict.html')
    assert tmpl.render().strip() == 'FOO'
    tmpl = env.get_template('test.html')
    assert tmpl.render().strip() == 'BAR'
    raises(TemplateNotFound, env.get_template, 'missing.html')
开发者ID:492852238,项目名称:SourceLearning,代码行数:7,代码来源:test_loaders.py


示例9: test_coordinate_attribute_assignment_01

def test_coordinate_attribute_assignment_01( ):
    '''Coordinates are immutable.
    Attributes cannot be set (rebound).'''
    t = Coordinate(1, 2)
    assert raises(AttributeError, 't.xy = 2')
    assert raises(AttributeError, 't.foo = 3')
    assert raises(TypeError, 't[0] = 2')
开发者ID:drepetto,项目名称:chiplotle,代码行数:7,代码来源:test_coordinate_init.py


示例10: test_surface

def test_surface():
    # TypeError: The Surface type cannot be instantiated
    test.raises(TypeError, "s = cairo.Surface()")

    if cairo.HAS_IMAGE_SURFACE:
        f, w, h = cairo.FORMAT_ARGB32, 100, 100
        s = cairo.ImageSurface(f, w, h)
        assert s.get_format() == f
        assert s.get_width() == w
        assert s.get_height() == h

    if cairo.HAS_PDF_SURFACE:
        f, w, h = tfi.TemporaryFile(mode="w+b"), 100, 100
        s = cairo.PDFSurface(f, w, h)

    if cairo.HAS_PS_SURFACE:
        f, w, h = tfi.TemporaryFile(mode="w+b"), 100, 100
        s = cairo.PSSurface(f, w, h)

    if cairo.HAS_RECORDING_SURFACE:
        s = cairo.RecordingSurface(cairo.CONTENT_COLOR, None)
        s = cairo.RecordingSurface(cairo.CONTENT_COLOR, (1, 1, 10, 10))

    if cairo.HAS_SVG_SURFACE:
        f, w, h = tfi.TemporaryFile(mode="w+b"), 100, 100
        s = cairo.SVGSurface(f, w, h)
开发者ID:amremam2004,项目名称:py2cairo,代码行数:26,代码来源:api_test.py


示例11: test_ueimporterror

def test_ueimporterror():
    ue = uecommunication()
    raises(UeImportError, ue.valid_response, "<Response><Import>Import not ok</Import></Response>")
    assert (
        ue.valid_response("<Response><Import>Import ok</Import></Response>")
        == "<Response><Import>Import ok</Import></Response>"
    )
开发者ID:updatengine,项目名称:updatengine-client,代码行数:7,代码来源:test_updatengine_client.py


示例12: test_creation_fail2

def test_creation_fail2():
    """
    Try to create two Managers with the same position.
    This should fail without leaving any partial records in
    the database.

    """
    setupClass([DIManager, DIEmployee, DIPerson])

    kwargs = {'firstName': 'John', 'lastName': 'Doe',
              'position': 'Project Manager'}
    DIManager(**kwargs)
    persons = DIEmployee.select(DIPerson.q.firstName == 'John')
    assert persons.count() == 1

    kwargs = {'firstName': 'John', 'lastName': 'Doe II',
              'position': 'Project Manager'}
    raises(Exception, DIManager, **kwargs)
    persons = DIPerson.select(DIPerson.q.firstName == 'John')
    assert persons.count() == 1

    if not supports('transactions'):
        skip("Transactions aren't supported")
    transaction = DIPerson._connection.transaction()
    kwargs = {'firstName': 'John', 'lastName': 'Doe III',
              'position': 'Project Manager'}
    raises(Exception, DIManager, connection=transaction, **kwargs)
    transaction.rollback()
    transaction.begin()
    persons = DIPerson.select(DIPerson.q.firstName == 'John',
                              connection=transaction)
    assert persons.count() == 1
开发者ID:digideskio,项目名称:DyonisosV2,代码行数:32,代码来源:test_deep_inheritance.py


示例13: test_cjk

 def test_cjk(self):
     import sys
     import unicodedata
     cases = ((0x3400, 0x4DB5),
              (0x4E00, 0x9FA5))
     if unicodedata.unidata_version >= "4.1":
         cases = ((0x3400, 0x4DB5),
                  (0x4E00, 0x9FBB),
                  (0x20000, 0x2A6D6))
     for first, last in cases:
         # Test at and inside the boundary
         for i in (first, first + 1, last - 1, last):
             charname = 'CJK UNIFIED IDEOGRAPH-%X'%i
             char = ('\\U%08X' % i).decode('unicode-escape')
             assert unicodedata.name(char) == charname
             assert unicodedata.lookup(charname) == char
         # Test outside the boundary
         for i in first - 1, last + 1:
             charname = 'CJK UNIFIED IDEOGRAPH-%X'%i
             char = ('\\U%08X' % i).decode('unicode-escape')
             try:
                 unicodedata.name(char)
             except ValueError, e:
                 assert e.message == 'no such name'
             raises(KeyError, unicodedata.lookup, charname)
开发者ID:ParitoshThapliyal59,项目名称:pypy,代码行数:25,代码来源:test_unicodedata.py


示例14: test_copy

    def test_copy(self):
        import re

        # copy support is disabled by default in _sre.c
        m = re.match("bla", "bla")
        raises(TypeError, m.__copy__)
        raises(TypeError, m.__deepcopy__)
开发者ID:cimarieta,项目名称:usp,代码行数:7,代码来源:test_app_sre.py


示例15: test_prefix_loader

def test_prefix_loader():
    env = Environment(loader=prefix_loader)
    tmpl = env.get_template('a/test.html')
    assert tmpl.render().strip() == 'BAR'
    tmpl = env.get_template('b/justdict.html')
    assert tmpl.render().strip() == 'FOO'
    raises(TemplateNotFound, env.get_template, 'missing')
开发者ID:492852238,项目名称:SourceLearning,代码行数:7,代码来源:test_loaders.py


示例16: test_group

 def test_group(self):
     import re
     m = re.search("a((?P<first>\d)|(?P<second>\s))", "aa1b")
     assert "a1" == m.group()
     assert ("1", "1", None) == m.group(1, 2, 3)
     assert ("1", None) == m.group("first", "second")
     raises(IndexError, m.group, 1, 4)
开发者ID:charred,项目名称:pypy,代码行数:7,代码来源:test_app_sre.py


示例17: test_cjk

 def test_cjk(self):
     import sys
     if sys.maxunicode < 0x10ffff:
         skip("requires a 'wide' python build.")
     import unicodedata
     cases = ((0x3400, 0x4DB5),
              (0x4E00, 0x9FA5))
     if unicodedata.unidata_version >= "4.1":
         cases = ((0x3400, 0x4DB5),
                  (0x4E00, 0x9FBB),
                  (0x20000, 0x2A6D6))
     for first, last in cases:
         # Test at and inside the boundary
         for i in (first, first + 1, last - 1, last):
             charname = 'CJK UNIFIED IDEOGRAPH-%X'%i
             assert unicodedata.name(unichr(i)) == charname
             assert unicodedata.lookup(charname) == unichr(i)
         # Test outside the boundary
         for i in first - 1, last + 1:
             charname = 'CJK UNIFIED IDEOGRAPH-%X'%i
             try:
                 unicodedata.name(unichr(i))
             except ValueError:
                 pass
             raises(KeyError, unicodedata.lookup, charname)
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:25,代码来源:test_unicodedata.py


示例18: test_fill_in_start_end

    def test_fill_in_start_end(self):
        # case where neither start nor end is defined; they are returned
        # as is (as None values)
        s = e = None
        assert (None, None) == self.arl_indexer._fill_in_start_end(s, e)

        # case where end is defined but start isn't (invalid); exception raised
        e = datetime.datetime.utcnow()
        with raises(ValueError) as e_info:
            self.arl_indexer._fill_in_start_end(s, e)
        assert arlindexer.ArlIndexer.END_WITHOUT_START_ERR_MSG == e_info.value.args[0]

        # case where start is after end (invalid); exception raised
        s = e + datetime.timedelta(1)
        with raises(ValueError) as e_info:
            self.arl_indexer._fill_in_start_end(s, e)
        assert arlindexer.ArlIndexer.START_AFTER_END_ERR_MSG == e_info.value.args[0]

        # case where start is before end (valid); they are returned as is
        s = e - datetime.timedelta(1)
        assert s, e == self.arl_indexer._fill_in_start_end(s, e)

        # case where start is defined but not end; end gets set to now
        with timecop.freeze(time.mktime(e.timetuple())):
            assert s, e == self.arl_indexer._fill_in_start_end(s, None)
开发者ID:pnwairfire,项目名称:met,代码行数:25,代码来源:test_arlindexer.py


示例19: test_logout_2

    def test_logout_2(self):
        """ one IdP/AA with BINDING_SOAP, can't actually send something"""

        conf = config.SPConfig()
        conf.load_file("server2_conf")
        client = Saml2Client(conf)

        # information about the user from an IdP
        session_info = {
            "name_id": "123456",
            "issuer": "urn:mace:example.com:saml:roland:idp",
            "not_on_or_after": in_a_while(minutes=15),
            "ava": {
                "givenName": "Anders",
                "surName": "Andersson",
                "mail": "[email protected]"
            }
        }
        client.users.add_information_about_person(session_info)
        entity_ids = self.client.users.issuers_of_info("123456")
        assert entity_ids == ["urn:mace:example.com:saml:roland:idp"]
        destinations = client.config.single_logout_services(entity_ids[0],
                                                            BINDING_SOAP)
        print destinations
        assert destinations == ['http://localhost:8088/slo']

        # Will raise an error since there is noone at the other end.
        raises(LogoutError, 'client.global_logout("123456", "Tired", in_a_while(minutes=5))')
开发者ID:howow,项目名称:pysaml2,代码行数:28,代码来源:test_51_client.py


示例20: test_no_2nd_arg_and_1st_isnt_enough_for_mkv

    def test_no_2nd_arg_and_1st_isnt_enough_for_mkv(self, p):
        s = """
        name = s
        key_format =     16s
        type = HashIndex
        hash_lim = 1
        make_key_value:
        0
        """
        with raises(IndexCreatorValueException):
            p.parse(s, 'TestIndex')

        s2 = """
        name = s
        key_format =     16s
        type = HashIndex
        hash_lim = 1
        make_key_value:
        "aaa"
        """
        with raises(IndexCreatorValueException):
            p.parse(s2, 'TestIndex')

        s3 = """
        name = s
        key_format =     16s
        type = HashIndex
        hash_lim = 1
        make_key_value:
        md5(a)
        """
        with raises(IndexCreatorValueException):
            p.parse(s3, 'TestIndex')
开发者ID:andy0130tw,项目名称:CodernityDB3,代码行数:33,代码来源:test_indexcreator_exec.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python test.skip函数代码示例发布时间:2022-05-25
下一篇:
Python path.local函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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