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

Python util.raises函数代码示例

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

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



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

示例1: test_templates

def test_templates():
    check('class', "A<T>", None, "IE1AI1TE", output="template<> A<T>")
    # first just check which objects support templating
    check('class', "template<> A", None, "IE1A")
    check('function', "template<> void A()", None, "IE1Av")
    check('member', "template<> A a", None, "IE1a")
    check('type', "template<> a = A", None, "IE1a")
    raises(DefinitionError, parse, 'enum', "template<> A")
    raises(DefinitionError, parse, 'enumerator', "template<> A")
    # then all the real tests
    check('class', "template<typename T1, typename T2> A", None, "I00E1A")
    check('type', "template<> a", None, "IE1a")

    check('class', "template<typename T> A", None, "I0E1A")
    check('class', "template<class T> A", None, "I0E1A")
    check('class', "template<typename ...T> A", None, "IDpE1A")
    check('class', "template<typename...> A", None, "IDpE1A")
    check('class', "template<typename = Test> A", None, "I0E1A")
    check('class', "template<typename T = Test> A", None, "I0E1A")

    check('class', "template<template<typename> typename T> A",
          None, "II0E0E1A")
    check('class', "template<int> A", None, "I_iE1A")
    check('class', "template<int T> A", None, "I_iE1A")
    check('class', "template<int... T> A", None, "I_DpiE1A")
    check('class', "template<int T = 42> A", None, "I_iE1A")
    check('class', "template<int = 42> A", None, "I_iE1A")

    # from breathe#218
    check('function',
          "template<typename F> "
          "void allow(F *f, typename func<F, B, G!=1>::type tt)",
          None, "I0E5allowP1FN4funcI1F1BXG!=1EE4typeE")
开发者ID:synmnstr,项目名称:sphinx,代码行数:33,代码来源:test_domain_cpp.py


示例2: test_voting

def test_voting(support):
    session = Session()
    nodes = session.query(Node).all()
    node = nodes[0]

    comment = support.get_data(node.id)['comments'][0]

    def check_rating(val):
        data = support.get_data(node.id)
        comment = data['comments'][0]
        assert comment['rating'] == val, '%s != %s' % (comment['rating'], val)

    support.process_vote(comment['id'], 'user_one', '1')
    support.process_vote(comment['id'], 'user_two', '1')
    support.process_vote(comment['id'], 'user_three', '1')
    check_rating(3)
    support.process_vote(comment['id'], 'user_one', '-1')
    check_rating(1)
    support.process_vote(comment['id'], 'user_one', '0')
    check_rating(2)

    # Make sure a vote with value > 1 or < -1 can't be cast.
    raises(ValueError, support.process_vote, comment['id'], 'user_one', '2')
    raises(ValueError, support.process_vote, comment['id'], 'user_one', '-2')

    # Make sure past voting data is associated with comments when they are
    # fetched.
    data = support.get_data(str(node.id), username='user_two')
    comment = data['comments'][0]
    assert comment['vote'] == 1, '%s != 1' % comment['vote']
开发者ID:AlexEshoo,项目名称:sphinx,代码行数:30,代码来源:test_websupport.py


示例3: test_do_prompt

def test_do_prompt():
    d = {}
    answers = {
        'Q2': 'v2',
        'Q3': 'v3',
        'Q4': 'yes',
        'Q5': 'no',
        'Q6': 'foo',
    }
    qs.term_input = mock_input(answers)
    try:
        qs.do_prompt(d, 'k1', 'Q1')
    except AssertionError:
        assert 'k1' not in d
    else:
        assert False, 'AssertionError not raised'
    qs.do_prompt(d, 'k1', 'Q1', default='v1')
    assert d['k1'] == 'v1'
    qs.do_prompt(d, 'k3', 'Q3', default='v3_default')
    assert d['k3'] == 'v3'
    qs.do_prompt(d, 'k2', 'Q2')
    assert d['k2'] == 'v2'
    qs.do_prompt(d, 'k4', 'Q4', validator=qs.boolean)
    assert d['k4'] is True
    qs.do_prompt(d, 'k5', 'Q5', validator=qs.boolean)
    assert d['k5'] is False
    raises(AssertionError, qs.do_prompt, d, 'k6', 'Q6', validator=qs.boolean)
开发者ID:Felix-neko,项目名称:sphinx,代码行数:27,代码来源:test_quickstart.py


示例4: test_get_filename_for_language

def test_get_filename_for_language():
    app = TestApp()

    # language is None
    app.env.config.language = None
    assert app.env.config.language is None
    assert i18n.get_image_filename_for_language('foo.png', app.env) == 'foo.png'
    assert i18n.get_image_filename_for_language('foo.bar.png', app.env) == 'foo.bar.png'
    assert i18n.get_image_filename_for_language('subdir/foo.png', app.env) == 'subdir/foo.png'
    assert i18n.get_image_filename_for_language('../foo.png', app.env) == '../foo.png'
    assert i18n.get_image_filename_for_language('foo', app.env) == 'foo'

    # language is en
    app.env.config.language = 'en'
    assert i18n.get_image_filename_for_language('foo.png', app.env) == 'foo.en.png'
    assert i18n.get_image_filename_for_language('foo.bar.png', app.env) == 'foo.bar.en.png'
    assert i18n.get_image_filename_for_language('dir/foo.png', app.env) == 'dir/foo.en.png'
    assert i18n.get_image_filename_for_language('../foo.png', app.env) == '../foo.en.png'
    assert i18n.get_image_filename_for_language('foo', app.env) == 'foo.en'

    # modify figure_language_filename and language is None
    app.env.config.language = None
    app.env.config.figure_language_filename = 'images/{language}/{root}{ext}'
    assert i18n.get_image_filename_for_language('foo.png', app.env) == 'foo.png'
    assert i18n.get_image_filename_for_language('foo.bar.png', app.env) == 'foo.bar.png'
    assert i18n.get_image_filename_for_language('subdir/foo.png', app.env) == 'subdir/foo.png'
    assert i18n.get_image_filename_for_language('../foo.png', app.env) == '../foo.png'
    assert i18n.get_image_filename_for_language('foo', app.env) == 'foo'

    # modify figure_language_filename and language is 'en'
    app.env.config.language = 'en'
    app.env.config.figure_language_filename = 'images/{language}/{root}{ext}'
    assert i18n.get_image_filename_for_language('foo.png', app.env) == 'images/en/foo.png'
    assert i18n.get_image_filename_for_language(
        'foo.bar.png', app.env) == 'images/en/foo.bar.png'
    assert i18n.get_image_filename_for_language(
        'subdir/foo.png', app.env) == 'images/en/subdir/foo.png'
    assert i18n.get_image_filename_for_language(
        '../foo.png', app.env) == 'images/en/../foo.png'
    assert i18n.get_image_filename_for_language('foo', app.env) == 'images/en/foo'

    # new path and basename tokens
    app.env.config.language = 'en'
    app.env.config.figure_language_filename = '{path}{language}/{basename}{ext}'
    assert i18n.get_image_filename_for_language('foo.png', app.env) == 'en/foo.png'
    assert i18n.get_image_filename_for_language(
        'foo.bar.png', app.env) == 'en/foo.bar.png'
    assert i18n.get_image_filename_for_language(
        'subdir/foo.png', app.env) == 'subdir/en/foo.png'
    assert i18n.get_image_filename_for_language(
        '../foo.png', app.env) == '../en/foo.png'
    assert i18n.get_image_filename_for_language('foo', app.env) == 'en/foo'

    # invalid figure_language_filename
    app.env.config.figure_language_filename = '{root}.{invalid}{ext}'
    raises(SphinxError, i18n.get_image_filename_for_language, 'foo.png', app.env)
开发者ID:Felix-neko,项目名称:sphinx,代码行数:56,代码来源:test_util_i18n.py


示例5: test_moderator_delete_comments

def test_moderator_delete_comments(support):
    def get_comment():
        session = Session()
        node = session.query(Node).first()
        session.close()
        return support.get_data(node.id, moderator=True)['comments'][1]

    comment = get_comment()
    support.delete_comment(comment['id'], username='user_two',
                           moderator=True)
    raises(IndexError, get_comment)
开发者ID:AlexEshoo,项目名称:sphinx,代码行数:11,代码来源:test_websupport.py


示例6: test_concept_definitions

def test_concept_definitions():
    check('concept', 'template<typename Param> A::B::Concept',
          None, 'I0EN1A1B7ConceptE')
    check('concept', 'template<typename A, typename B, typename ...C> Foo',
          None, 'I00DpE3Foo')
    check('concept', 'template<typename Param> A::B::Concept()',
          None, 'I0EN1A1B7ConceptE')
    check('concept', 'template<typename A, typename B, typename ...C> Foo()',
          None, 'I00DpE3Foo')
    raises(DefinitionError, parse, 'concept', 'Foo')
    raises(DefinitionError, parse, 'concept',
           'template<typename T> template<typename U> Foo')
开发者ID:Felix-neko,项目名称:sphinx,代码行数:12,代码来源:test_domain_cpp.py


示例7: test_get_many

def test_get_many():
    # Dict with keys and values of 0, 1, 2, 3, 4
    params = dict((n,n) for n in range(5))

    eq_(get_many(params), [])
    eq_(get_many(params, required=[1, 2]), [1, 2])
    eq_(get_many(params, optional=[1, 2]), [1, 2])
    eq_(get_many(params, optional=[6, 7, 8]), [None, None, None])
    eq_(get_many(params, one_of=[1, 2]), [1])
    eq_(get_many(params, one_of=[6, 1]), [1])

    eq_(get_many(params, optional=[6, 1]), [None, 1])
    eq_(get_many(params, required=[1, 2], optional=[6, 1]), [1, 2, None, 1])
    eq_(get_many(params, required=[1, 2], optional=[6, 1], one_of=[7, 8, 3]), [1, 2, None, 1, 3])

    raises(KeyError, get_many, params, required=[1, 6])
    raises(KeyError, get_many, params, one_of=[7, 6])
开发者ID:aodag,项目名称:WebHelpers2,代码行数:17,代码来源:test_containers.py


示例8: test_user_delete_comments

def test_user_delete_comments(support):
    def get_comment():
        session = Session()
        node = session.query(Node).first()
        session.close()
        return support.get_data(node.id)['comments'][0]

    comment = get_comment()
    assert comment['username'] == 'user_one'
    # Make sure other normal users can't delete someone elses comments.
    raises(UserNotAuthorizedError, support.delete_comment,
           comment['id'], username='user_two')
    # Now delete the comment using the correct username.
    support.delete_comment(comment['id'], username='user_one')
    comment = get_comment()
    assert comment['username'] == '[deleted]'
    assert comment['text'] == '[deleted]'
开发者ID:AlexEshoo,项目名称:sphinx,代码行数:17,代码来源:test_websupport.py


示例9: test_comments

def test_comments(support):
    session = Session()
    nodes = session.query(Node).all()
    first_node = nodes[0]
    second_node = nodes[1]

    # Create a displayed comment and a non displayed comment.
    comment = support.add_comment('First test comment',
                                  node_id=first_node.id,
                                  username='user_one')
    hidden_comment = support.add_comment('Hidden comment',
                                         node_id=first_node.id,
                                         displayed=False)
    # Make sure that comments can't be added to a comment where
    # displayed == False, since it could break the algorithm that
    # converts a nodes comments to a tree.
    raises(CommentNotAllowedError, support.add_comment, 'Not allowed',
           parent_id=str(hidden_comment['id']))
    # Add a displayed and not displayed child to the displayed comment.
    support.add_comment('Child test comment', parent_id=str(comment['id']),
                        username='user_one')
    support.add_comment('Hidden child test comment',
                        parent_id=str(comment['id']), displayed=False)
    # Add a comment to another node to make sure it isn't returned later.
    support.add_comment('Second test comment',
                        node_id=second_node.id,
                        username='user_two')

    # Access the comments as a moderator.
    data = support.get_data(first_node.id, moderator=True)
    comments = data['comments']
    children = comments[0]['children']
    assert len(comments) == 2
    assert comments[1]['text'] == '<p>Hidden comment</p>\n'
    assert len(children) == 2
    assert children[1]['text'] == '<p>Hidden child test comment</p>\n'

    # Access the comments without being a moderator.
    data = support.get_data(first_node.id)
    comments = data['comments']
    children = comments[0]['children']
    assert len(comments) == 1
    assert comments[0]['text'] == '<p>First test comment</p>\n'
    assert len(children) == 1
    assert children[0]['text'] == '<p>Child test comment</p>\n'
开发者ID:AlexEshoo,项目名称:sphinx,代码行数:45,代码来源:test_websupport.py


示例10: test_templates

def test_templates():
    check("class", "A<T>", None, "IE1AI1TE", output="template<> A<T>")
    # first just check which objects support templating
    check("class", "template<> A", None, "IE1A")
    check("function", "template<> void A()", None, "IE1Av")
    check("member", "template<> A a", None, "IE1a")
    check("type", "template<> a = A", None, "IE1a")
    raises(DefinitionError, parse, "enum", "template<> A")
    raises(DefinitionError, parse, "enumerator", "template<> A")
    # then all the real tests
    check("class", "template<typename T1, typename T2> A", None, "I00E1A")
    check("type", "template<> a", None, "IE1a")

    check("class", "template<typename T> A", None, "I0E1A")
    check("class", "template<class T> A", None, "I0E1A")
    check("class", "template<typename ...T> A", None, "IDpE1A")
    check("class", "template<typename...> A", None, "IDpE1A")
    check("class", "template<typename = Test> A", None, "I0E1A")
    check("class", "template<typename T = Test> A", None, "I0E1A")

    check("class", "template<template<typename> typename T> A", None, "II0E0E1A")
    check("class", "template<int> A", None, "I_iE1A")
    check("class", "template<int T> A", None, "I_iE1A")
    check("class", "template<int... T> A", None, "I_DpiE1A")
    check("class", "template<int T = 42> A", None, "I_iE1A")
    check("class", "template<int = 42> A", None, "I_iE1A")

    # from breathe#218
    check(
        "function",
        "template<typename F> " "void allow(F *f, typename func<F, B, G!=1>::type tt)",
        None,
        "I0E5allowP1FN4funcI1F1BXG!=1EE4typeE",
    )

    # from #2058
    check(
        "function",
        "template<typename Char, typename Traits> "
        "inline std::basic_ostream<Char, Traits> &operator<<("
        "std::basic_ostream<Char, Traits> &os, "
        "const c_string_view_base<const Char, Traits> &str)",
        None,
        "I00ElsRNSt13basic_ostreamI4Char6TraitsEE" "RK18c_string_view_baseIK4Char6TraitsE",
    )
开发者ID:rmcgibbo,项目名称:sphinx,代码行数:45,代码来源:test_domain_cpp.py


示例11: test_rstdim_to_latexdim

def test_rstdim_to_latexdim():
    # Length units docutils supported
    # http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#length-units
    assert rstdim_to_latexdim('160em') == '160em'
    assert rstdim_to_latexdim('160px') == '160\\sphinxpxdimen'
    assert rstdim_to_latexdim('160in') == '160in'
    assert rstdim_to_latexdim('160cm') == '160cm'
    assert rstdim_to_latexdim('160mm') == '160mm'
    assert rstdim_to_latexdim('160pt') == '160bp'
    assert rstdim_to_latexdim('160pc') == '160pc'
    assert rstdim_to_latexdim('30%') == '0.300\\linewidth'
    assert rstdim_to_latexdim('160') == '160\\sphinxpxdimen'

    # flaot values
    assert rstdim_to_latexdim('160.0em') == '160.0em'
    assert rstdim_to_latexdim('.5em') == '.5em'

    # unknown values (it might be generated by 3rd party extension)
    raises(ValueError, rstdim_to_latexdim, 'unknown')
    assert rstdim_to_latexdim('160.0unknown') == '160.0unknown'
开发者ID:Felix-neko,项目名称:sphinx,代码行数:20,代码来源:test_writer_latex.py


示例12: test_moderation

def test_moderation(support):
    session = Session()
    nodes = session.query(Node).all()
    node = nodes[7]
    session.close()
    accepted = support.add_comment('Accepted Comment', node_id=node.id,
                                   displayed=False)
    deleted  = support.add_comment('Comment to delete', node_id=node.id,
                                   displayed=False)
    # Make sure the moderation_callback is called.
    assert called
    # Make sure the user must be a moderator.
    raises(UserNotAuthorizedError, support.accept_comment, accepted['id'])
    raises(UserNotAuthorizedError, support.delete_comment, deleted['id'])
    support.accept_comment(accepted['id'], moderator=True)
    support.delete_comment(deleted['id'], moderator=True)
    comments = support.get_data(node.id)['comments']
    assert len(comments) == 1
    comments = support.get_data(node.id, moderator=True)['comments']
    assert len(comments) == 1
开发者ID:AlexEshoo,项目名称:sphinx,代码行数:20,代码来源:test_websupport.py


示例13: test_theme_api

def test_theme_api(app, status, warning):
    cfg = app.config

    # test Theme class API
    assert set(Theme.themes.keys()) == \
        set(['basic', 'default', 'scrolls', 'agogo', 'sphinxdoc', 'haiku',
             'traditional', 'testtheme', 'ziptheme', 'epub', 'nature',
             'pyramid', 'bizstyle', 'classic', 'nonav'])
    assert Theme.themes['testtheme'][1] is None
    assert isinstance(Theme.themes['ziptheme'][1], zipfile.ZipFile)

    # test Theme instance API
    theme = app.builder.theme
    assert theme.name == 'ziptheme'
    assert theme.themedir_created
    themedir = theme.themedir
    assert theme.base.name == 'basic'
    assert len(theme.get_dirchain()) == 2

    # direct setting
    assert theme.get_confstr('theme', 'stylesheet') == 'custom.css'
    # inherited setting
    assert theme.get_confstr('options', 'nosidebar') == 'false'
    # nonexisting setting
    assert theme.get_confstr('theme', 'foobar', 'def') == 'def'
    raises(ThemeError, theme.get_confstr, 'theme', 'foobar')

    # options API
    raises(ThemeError, theme.get_options, {'nonexisting': 'foo'})
    options = theme.get_options(cfg.html_theme_options)
    assert options['testopt'] == 'foo'
    assert options['nosidebar'] == 'false'

    # cleanup temp directories
    theme.cleanup()
    assert not os.path.exists(themedir)
开发者ID:Felix-neko,项目名称:sphinx,代码行数:36,代码来源:test_theming.py


示例14: test_core_config

def test_core_config(app, status, warning):
    cfg = app.config

    # simple values
    assert 'project' in cfg.__dict__
    assert cfg.project == 'Sphinx <Tests>'
    assert cfg.templates_path == ['_templates']

    # overrides
    assert cfg.master_doc == 'master'
    assert cfg.latex_elements['docclass'] == 'scrartcl'
    assert cfg.modindex_common_prefix == ['path1', 'path2']

    # simple default values
    assert 'locale_dirs' not in cfg.__dict__
    assert cfg.locale_dirs == []
    assert cfg.trim_footnote_reference_space is False

    # complex default values
    assert 'html_title' not in cfg.__dict__
    assert cfg.html_title == 'Sphinx <Tests> 0.6alpha1 documentation'

    # complex default values mustn't raise
    for valuename in cfg.config_values:
        getattr(cfg, valuename)

    # "contains" gives True both for set and unset values
    assert 'project' in cfg
    assert 'html_title' in cfg
    assert 'nonexisting_value' not in cfg

    # invalid values
    raises(AttributeError, getattr, cfg, '_value')
    raises(AttributeError, getattr, cfg, 'nonexisting_value')

    # non-value attributes are deleted from the namespace
    raises(AttributeError, getattr, cfg, 'sys')

    # setting attributes
    cfg.project = 'Foo'
    assert cfg.project == 'Foo'

    # alternative access via item interface
    cfg['project'] = 'Sphinx Tests'
    assert cfg['project'] == cfg.project == 'Sphinx Tests'
开发者ID:Basis,项目名称:sphinx,代码行数:45,代码来源:test_config.py


示例15: test_core_config

def test_core_config(app):
    cfg = app.config

    # simple values
    assert "project" in cfg.__dict__
    assert cfg.project == "Sphinx <Tests>"
    assert cfg.templates_path == ["_templates"]

    # overrides
    assert cfg.master_doc == "master"
    assert cfg.latex_elements["docclass"] == "scrartcl"

    # simple default values
    assert "locale_dirs" not in cfg.__dict__
    assert cfg.locale_dirs == []
    assert cfg.trim_footnote_reference_space == False

    # complex default values
    assert "html_title" not in cfg.__dict__
    assert cfg.html_title == "Sphinx <Tests> 0.6alpha1 documentation"

    # complex default values mustn't raise
    for valuename in cfg.config_values:
        getattr(cfg, valuename)

    # "contains" gives True both for set and unset values
    assert "project" in cfg
    assert "html_title" in cfg
    assert "nonexisting_value" not in cfg

    # invalid values
    raises(AttributeError, getattr, cfg, "_value")
    raises(AttributeError, getattr, cfg, "nonexisting_value")

    # non-value attributes are deleted from the namespace
    raises(AttributeError, getattr, cfg, "sys")

    # setting attributes
    cfg.project = "Foo"
    assert cfg.project == "Foo"

    # alternative access via item interface
    cfg["project"] = "Sphinx Tests"
    assert cfg["project"] == cfg.project == "Sphinx Tests"
开发者ID:ethanfine,项目名称:oh-mainline,代码行数:44,代码来源:test_config.py


示例16: test_import_classes

def test_import_classes():
    from sphinx.application import Sphinx, TemplateBridge
    from sphinx.util.i18n import CatalogInfo

    try:
        sys.path.append(rootdir / 'roots/test-ext-inheritance_diagram')
        from example.sphinx import DummyClass

        # got exception for unknown class or module
        raises(InheritanceException, import_classes, 'unknown', None)
        raises(InheritanceException, import_classes, 'unknown.Unknown', None)

        # a module having no classes
        classes = import_classes('sphinx', None)
        assert classes == []

        classes = import_classes('sphinx', 'foo')
        assert classes == []

        # all of classes in the module
        classes = import_classes('sphinx.application', None)
        assert set(classes) == set([Sphinx, TemplateBridge])

        # specified class in the module
        classes = import_classes('sphinx.application.Sphinx', None)
        assert classes == [Sphinx]

        # specified class in current module
        classes = import_classes('Sphinx', 'sphinx.application')
        assert classes == [Sphinx]

        # relative module name to current module
        classes = import_classes('i18n.CatalogInfo', 'sphinx.util')
        assert classes == [CatalogInfo]

        # got exception for functions
        raises(InheritanceException, import_classes, 'encode_uri', 'sphinx.util')

        # import submodule on current module (refs: #3164)
        classes = import_classes('sphinx', 'example')
        assert classes == [DummyClass]
    finally:
        sys.path.pop()
开发者ID:Felix-neko,项目名称:sphinx,代码行数:43,代码来源:test_ext_inheritance_diagram.py


示例17: test_needs_sphinx

def test_needs_sphinx():
    # micro version
    app = TestApp(confoverrides={'needs_sphinx': '1.3.3'})  # OK: less
    app.cleanup()
    app = TestApp(confoverrides={'needs_sphinx': '1.3.4'})  # OK: equals
    app.cleanup()
    raises(VersionRequirementError, TestApp,
           confoverrides={'needs_sphinx': '1.3.5'})  # NG: greater

    # minor version
    app = TestApp(confoverrides={'needs_sphinx': '1.2'})  # OK: less
    app.cleanup()
    app = TestApp(confoverrides={'needs_sphinx': '1.3'})  # OK: equals
    app.cleanup()
    raises(VersionRequirementError, TestApp,
           confoverrides={'needs_sphinx': '1.4'})  # NG: greater

    # major version
    app = TestApp(confoverrides={'needs_sphinx': '0'})  # OK: less
    app.cleanup()
    app = TestApp(confoverrides={'needs_sphinx': '1'})  # OK: equals
    app.cleanup()
    raises(VersionRequirementError, TestApp,
           confoverrides={'needs_sphinx': '2'})  # NG: greater
开发者ID:Basis,项目名称:sphinx,代码行数:24,代码来源:test_config.py


示例18: test_templates

def test_templates():
    check('class', "A<T>", None, "IE1AI1TE", output="template<> A<T>")
    # first just check which objects support templating
    check('class', "template<> A", None, "IE1A")
    check('function', "template<> void A()", None, "IE1Av")
    check('member', "template<> A a", None, "IE1a")
    check('type', "template<> a = A", None, "IE1a")
    raises(DefinitionError, parse, 'enum', "template<> A")
    raises(DefinitionError, parse, 'enumerator', "template<> A")
    # then all the real tests
    check('class', "template<typename T1, typename T2> A", None, "I00E1A")
    check('type', "template<> a", None, "IE1a")

    check('class', "template<typename T> A", None, "I0E1A")
    check('class', "template<class T> A", None, "I0E1A")
    check('class', "template<typename ...T> A", None, "IDpE1A")
    check('class', "template<typename...> A", None, "IDpE1A")
    check('class', "template<typename = Test> A", None, "I0E1A")
    check('class', "template<typename T = Test> A", None, "I0E1A")

    check('class', "template<template<typename> typename T> A",
          None, "II0E0E1A")
    check('class', "template<int> A", None, "I_iE1A")
    check('class', "template<int T> A", None, "I_iE1A")
    check('class', "template<int... T> A", None, "I_DpiE1A")
    check('class', "template<int T = 42> A", None, "I_iE1A")
    check('class', "template<int = 42> A", None, "I_iE1A")

    # from breathe#218
    check('function',
          "template<typename F> "
          "void allow(F *f, typename func<F, B, G!=1>::type tt)",
          None, "I0E5allowP1FN4funcI1F1BXG!=1EE4typeE")

    # from #2058
    check('function',
          "template<typename Char, typename Traits> "
          "inline std::basic_ostream<Char, Traits> &operator<<("
          "std::basic_ostream<Char, Traits> &os, "
          "const c_string_view_base<const Char, Traits> &str)",
          None, "I00ElsRNSt13basic_ostreamI4Char6TraitsEE"
          "RK18c_string_view_baseIK4Char6TraitsE")

    # template introductions
    raises(DefinitionError, parse, 'enum', 'abc::ns::foo{id_0, id_1, id_2} A')
    raises(DefinitionError, parse, 'enumerator', 'abc::ns::foo{id_0, id_1, id_2} A')
    check('class', 'abc::ns::foo{id_0, id_1, id_2} xyz::bar',
          None, 'I000EXN3abc2ns3fooEI4id_04id_14id_2EEN3xyz3barE')
    check('class', 'abc::ns::foo{id_0, id_1, ...id_2} xyz::bar',
          None, 'I00DpEXN3abc2ns3fooEI4id_04id_1sp4id_2EEN3xyz3barE')
    check('class', 'abc::ns::foo{id_0, id_1, id_2} xyz::bar<id_0, id_1, id_2>',
          None, 'I000EXN3abc2ns3fooEI4id_04id_14id_2EEN3xyz3barI4id_04id_14id_2EE')
    check('class', 'abc::ns::foo{id_0, id_1, ...id_2} xyz::bar<id_0, id_1, id_2...>',
          None, 'I00DpEXN3abc2ns3fooEI4id_04id_1sp4id_2EEN3xyz3barI4id_04id_1Dp4id_2EE')

    check('class', 'template<> Concept{U} A<int>::B',
          None, 'IEI0EX7ConceptI1UEEN1AIiE1BE')

    check('type', 'abc::ns::foo{id_0, id_1, id_2} xyz::bar = ghi::qux',
          None, 'I000EXN3abc2ns3fooEI4id_04id_14id_2EEN3xyz3barE')
    check('type', 'abc::ns::foo{id_0, id_1, ...id_2} xyz::bar = ghi::qux',
          None, 'I00DpEXN3abc2ns3fooEI4id_04id_1sp4id_2EEN3xyz3barE')
    check('function', 'abc::ns::foo{id_0, id_1, id_2} void xyz::bar()',
          None, 'I000EXN3abc2ns3fooEI4id_04id_14id_2EEN3xyz3barEv')
    check('function', 'abc::ns::foo{id_0, id_1, ...id_2} void xyz::bar()',
          None, 'I00DpEXN3abc2ns3fooEI4id_04id_1sp4id_2EEN3xyz3barEv')
    check('member', 'abc::ns::foo{id_0, id_1, id_2} ghi::qux xyz::bar',
          None, 'I000EXN3abc2ns3fooEI4id_04id_14id_2EEN3xyz3barE')
    check('member', 'abc::ns::foo{id_0, id_1, ...id_2} ghi::qux xyz::bar',
          None, 'I00DpEXN3abc2ns3fooEI4id_04id_1sp4id_2EEN3xyz3barE')
    check('concept', 'Iterator{T, U} Another',
          None, 'I00EX8IteratorI1T1UEE7Another')
    check('concept', 'template<typename ...Pack> Numerics = (... && Numeric<Pack>)',
          None, 'IDpE8Numerics')
开发者ID:Felix-neko,项目名称:sphinx,代码行数:74,代码来源:test_domain_cpp.py


示例19: test_type_definitions


#.........这里部分代码省略.........
    check('function',
          'void operator()(const boost::array<VertexID, 2, "foo,  bar"> &v) const',
          'call-operator__boost::array:VertexID.2."foo,--bar":CRC',
          'NKclERKN5boost5arrayI8VertexIDX2EX"foo,  bar"EEE')
    check('function', 'MyClass::MyClass(MyClass::MyClass&&)',
          "MyClass::MyClass__MyClass::MyClassRR",
          "N7MyClass7MyClassERRN7MyClass7MyClassE")
    check('function', 'constexpr int get_value()', "get_valueCE", "9get_valuev")
    check('function', 'static constexpr int get_value()',
          "get_valueCE", "9get_valuev")
    check('function', 'int get_value() const noexcept',
          "get_valueC", "NK9get_valueEv")
    check('function', 'int get_value() const noexcept = delete',
          "get_valueC", "NK9get_valueEv")
    check('function', 'int get_value() volatile const',
          "get_valueVC", "NVK9get_valueEv")
    check('function', 'MyClass::MyClass(MyClass::MyClass&&) = default',
          "MyClass::MyClass__MyClass::MyClassRR",
          "N7MyClass7MyClassERRN7MyClass7MyClassE")
    check('function', 'virtual MyClass::a_virtual_function() const override',
          "MyClass::a_virtual_functionC", "NK7MyClass18a_virtual_functionEv")
    check('function', 'A B() override', "B", "1Bv")
    check('function', 'A B() final', "B", "1Bv")
    check('function', 'A B() final override', "B", "1Bv")
    check('function', 'A B() override final', "B", "1Bv",
          output='A B() final override')
    check('function', 'MyClass::a_member_function() volatile',
          "MyClass::a_member_functionV", "NV7MyClass17a_member_functionEv")
    check('function', 'MyClass::a_member_function() volatile const',
          "MyClass::a_member_functionVC", "NVK7MyClass17a_member_functionEv")
    check('function', 'MyClass::a_member_function() &&',
          "MyClass::a_member_functionO", "NO7MyClass17a_member_functionEv")
    check('function', 'MyClass::a_member_function() &',
          "MyClass::a_member_functionR", "NR7MyClass17a_member_functionEv")
    check('function', 'MyClass::a_member_function() const &',
          "MyClass::a_member_functionCR", "NKR7MyClass17a_member_functionEv")
    check('function', 'int main(int argc, char *argv[])',
          "main__i.cPA", "4mainiA_Pc")
    check('function', 'MyClass &MyClass::operator++()',
          "MyClass::inc-operator", "N7MyClassppEv")
    check('function', 'MyClass::pointer MyClass::operator->()',
          "MyClass::pointer-operator", "N7MyClassptEv")

    x = 'std::vector<std::pair<std::string, int>> &module::test(register int ' \
        'foo, bar[n], std::string baz = "foobar, blah, bleh") const = 0'
    check('function', x, "module::test__i.barA.ssC",
          "NK6module4testEiAn_3barNSt6stringE")
    check('function',
          'int foo(Foo f = Foo(double(), std::make_pair(int(2), double(3.4))))',
          "foo__Foo", "3foo3Foo")
    check('function', 'int foo(A a = x(a))', "foo__A", "3foo1A")
    raises(DefinitionError, parse, 'function', 'int foo(B b=x(a)')
    raises(DefinitionError, parse, 'function', 'int foo)C c=x(a))')
    raises(DefinitionError, parse, 'function', 'int foo(D d=x(a')
    check('function', 'int foo(const A&... a)', "foo__ACRDp", "3fooDpRK1A")
    check('function', 'virtual void f()', "f", "1fv")
    # test for ::nestedName, from issue 1738
    check("function", "result(int val, ::std::error_category const &cat)",
          "result__i.std::error_categoryCR", "6resultiRNSt14error_categoryE")
    check("function", "int *f()", "f", "1fv")
    # tests derived from issue #1753 (skip to keep sanity)
    check("function", "f(int (&array)[10])", None, "1fRA10_i")
    check("function", "void f(int (&array)[10])", None, "1fRA10_i")
    check("function", "void f(float *q(double))", None, "1fFPfdE")
    check("function", "void f(float *(*q)(double))", None, "1fPFPfdE")
    check("function", "void f(float (*q)(double))", None, "1fPFfdE")
    check("function", "int (*f(double d))(float)", "f__double", "1fd")
    check("function", "int (*f(bool b))[5]", "f__b", "1fb")
    check("function", "int (*A::f(double d) const)(float)",
          "A::f__doubleC", "NK1A1fEd")
    check("function", "void f(std::shared_ptr<int(double)> ptr)",
          None, "1fNSt10shared_ptrIFidEEE")

    # TODO: make tests for functions in a template, e.g., Test<int&&()>
    # such that the id generation for function type types is correct.

    check('function', 'friend std::ostream &f(std::ostream&, int)',
          'f__osR.i', '1fRNSt7ostreamEi')

    # from breathe#223
    check('function', 'void f(struct E e)', 'f__E', '1f1E')
    check('function', 'void f(class E e)', 'f__E', '1f1E')
    check('function', 'void f(typename E e)', 'f__E', '1f1E')
    check('function', 'void f(enum E e)', 'f__E', '1f1E')
    check('function', 'void f(union E e)', 'f__E', '1f1E')

    check('class', 'public A', "A", "1A", output='A')
    check('class', 'private A', "A", "1A")

    check('enum', 'A', None, "1A")
    check('enum', 'A : std::underlying_type<B>::type', None, "1A")
    check('enum', 'A : unsigned int', None, "1A")
    check('enum', 'public A', None, "1A", output='A')
    check('enum', 'private A', None, "1A")

    check('enumerator', 'A', None, "1A")
    check('enumerator', 'A = std::numeric_limits<unsigned long>::max()',
          None, "1A")

    check('type', 'A = B', None, '1A')
开发者ID:Nikokrock,项目名称:sphinx,代码行数:101,代码来源:test_domain_cpp.py


示例20: test_assert_deepequal

def test_assert_deepequal():
    f = util.assert_deepequal

    # Test with good scalar values:
    f(u'hello', u'hello')
    f(util.Fuzzy(), u'hello')
    f(util.Fuzzy(type=unicode), u'hello')
    f(util.Fuzzy('ell'), u'hello')
    f(util.Fuzzy(test=lambda other: other.endswith('llo')), u'hello')
    f(18, 18)
    f(util.Fuzzy(), 18)
    f(util.Fuzzy(type=int), 18)
    f(util.Fuzzy(type=(int, float), test=lambda other: other > 17.9), 18)

    # Test with bad scalar values:
    e = raises(AssertionError, f, u'hello', u'world', 'foo')
    assert str(e) == VALUE % (
        'foo', u'hello', u'world', tuple()
    )

    e = raises(AssertionError, f, 'hello', u'hello', 'foo')
    assert str(e) == TYPE % (
        'foo', str, unicode, 'hello', u'hello', tuple()
    )

    e = raises(AssertionError, f, 18, 18.0, 'foo')
    assert str(e) == TYPE % (
        'foo', int, float, 18, 18.0, tuple()
    )

    # Test with good compound values:
    a = [
        u'hello',
        dict(naughty=u'nurse'),
        18,
    ]
    b = [
        u'hello',
        dict(naughty=u'nurse'),
        18,
    ]
    f(a, b)

    # Test with bad compound values:
    b = [
        'hello',
        dict(naughty=u'nurse'),
        18,
    ]
    e = raises(AssertionError, f, a, b, 'foo')
    assert str(e) == TYPE % (
        'foo', unicode, str, u'hello', 'hello', (2,)
    )

    b = [
        u'hello',
        dict(naughty='nurse'),
        18,
    ]
    e = raises(AssertionError, f, a, b, 'foo')
    assert str(e) == TYPE % (
        'foo', unicode, str, u'nurse', 'nurse', (1, 'naughty')
    )

    b = [
        u'hello',
        dict(naughty=u'nurse'),
        18.0,
    ]
    e = raises(AssertionError, f, a, b, 'foo')
    assert str(e) == TYPE % (
        'foo' 

鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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