Пример #1
0
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)
Пример #2
0
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)
Пример #3
0
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")
Пример #4
0
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='******')
    comment = data['comments'][0]
    assert comment['vote'] == 1, '%s != 1' % comment['vote']
Пример #5
0
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='******')
    comment = data['comments'][0]
    assert comment['vote'] == 1, '%s != 1' % comment['vote']
Пример #6
0
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'

    # 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)
Пример #7
0
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)
Пример #8
0
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='******', moderator=True)
    raises(IndexError, get_comment)
Пример #9
0
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='******',
                           moderator=True)
    raises(IndexError, get_comment)
Пример #10
0
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')
Пример #11
0
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')
Пример #12
0
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='******')
    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='******')
    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='******')

    # 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'
Пример #13
0
def test_Registry():
    """
    Test the `ipahealthcheck.core.Registry` class
    """
    class plugin1(Plugin):
        pass

    class plugin2(Plugin):
        pass

    # Create a registry
    r = Registry()

    # Check that TypeError is raised trying to register something that isn't
    # a class:
    p = plugin1(r)
    e = raises(TypeError, r, p)
    assert str(e) == 'plugin must be callable; got %r' % p

    # Register the plugins
    r(plugin1)
    r(plugin2)

    # TODO: enforce plugin uniqueness

    # Test registration
    names = [plugin.__class__.__name__ for plugin in r.get_plugins()]
    assert (names == ['plugin1', 'plugin2'])
Пример #14
0
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='******')
    # Now delete the comment using the correct username.
    support.delete_comment(comment['id'], username='******')
    comment = get_comment()
    assert comment['username'] == '[deleted]'
    assert comment['text'] == '[deleted]'
Пример #15
0
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])
Пример #16
0
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='******')
    # Now delete the comment using the correct username.
    support.delete_comment(comment['id'], username='******')
    comment = get_comment()
    assert comment['username'] == '[deleted]'
    assert comment['text'] == '[deleted]'
Пример #17
0
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='******')
    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='******')
    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='******')

    # 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'
Пример #18
0
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",
    )
Пример #19
0
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])
Пример #20
0
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")
Пример #21
0
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
Пример #22
0
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
Пример #23
0
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'
Пример #24
0
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
Пример #25
0
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)
Пример #26
0
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)
Пример #27
0
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'
Пример #28
0
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'
Пример #29
0
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"
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()
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()
Пример #32
0
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
Пример #33
0
def test_type_definitions():
    check("type", "public bool b", "b", "1b", "bool b")
    check("type", "bool A::b", "A::b", "N1A1bE")
    check("type", "bool *b", "b", "1b")
    check("type", "bool *const b", "b", "1b")
    check("type", "bool *volatile const b", "b", "1b")
    check("type", "bool *volatile const b", "b", "1b")
    check("type", "bool *volatile const *b", "b", "1b")
    check("type", "bool &b", "b", "1b")
    check("type", "bool b[]", "b", "1b")
    check("type", "std::pair<int, int> coord", "coord", "5coord")
    check("type", "long long int foo", "foo", "3foo")
    check("type",
          'std::vector<std::pair<std::string, long long>> module::blah',
          "module::blah", "N6module4blahE")
    check("type", "std::function<void()> F", "F", "1F")
    check("type", "std::function<R(A1, A2)> F", "F", "1F")
    check("type", "std::function<R(A1, A2, A3)> F", "F", "1F")
    check("type", "std::function<R(A1, A2, A3, As...)> F", "F", "1F")
    check("type", "MyContainer::const_iterator", "MyContainer::const_iterator",
          "N11MyContainer14const_iteratorE")
    check("type",
          "public MyContainer::const_iterator",
          "MyContainer::const_iterator",
          "N11MyContainer14const_iteratorE",
          output="MyContainer::const_iterator")
    # test decl specs on right
    check("type", "bool const b", "b", "1b")

    check('member',
          '  const  std::string  &  name = 42',
          "name__ssCR",
          "4name",
          output='const std::string &name = 42')
    check('member',
          '  const  std::string  &  name',
          "name__ssCR",
          "4name",
          output='const std::string &name')
    check('member',
          '  const  std::string  &  name [ n ]',
          "name__ssCRA",
          "4name",
          output='const std::string &name[n]')
    check('member',
          'const std::vector< unsigned int, long> &name',
          "name__std::vector:unsigned-i.l:CR",
          "4name",
          output='const std::vector<unsigned int, long> &name')
    check('member', 'module::myclass foo[n]', "foo__module::myclassA", "3foo")

    check('function', 'operator bool() const', "castto-b-operatorC", "NKcvbEv")
    check('function', 'A::operator bool() const', "A::castto-b-operatorC",
          "NK1AcvbEv")
    check('function', 'A::operator bool() volatile const &',
          "A::castto-b-operatorVCR", "NVKR1AcvbEv")
    check('function', 'A::operator bool() volatile const &&',
          "A::castto-b-operatorVCO", "NVKO1AcvbEv")
    check('function', 'bool namespaced::theclass::method(arg1, arg2)',
          "namespaced::theclass::method__arg1.arg2",
          "N10namespaced8theclass6methodE4arg14arg2")
    x = 'std::vector<std::pair<std::string, int>> &module::test(register int ' \
        'foo, bar, std::string baz = "foobar, blah, bleh") const = 0'
    check('function', x, "module::test__i.bar.ssC",
          "NK6module4testEi3barNSt6stringE")
    check('function', 'void f(std::pair<A, B>)', "f__std::pair:A.B:",
          "1fNSt4pairI1A1BEE")
    check('function', 'explicit module::myclass::foo::foo()',
          "module::myclass::foo::foo", "N6module7myclass3foo3fooEv")
    check('function', 'module::myclass::foo::~foo()',
          "module::myclass::foo::~foo", "N6module7myclass3fooD0Ev")
    check('function', 'int printf(const char *fmt, ...)', "printf__cCP.z",
          "6printfPKcz")
    check('function', 'int foo(const unsigned int j)', "foo__unsigned-iC",
          "3fooKj")
    check('function', 'int foo(const int *const ptr)', "foo__iCPC", "3fooPCKi")
    check('function', 'module::myclass::operator std::vector<std::string>()',
          "module::myclass::castto-std::vector:ss:-operator",
          "N6module7myclasscvNSt6vectorINSt6stringEEEEv")
    check('function',
          'void operator()(const boost::array<VertexID, 2> &v) const',
          "call-operator__boost::array:VertexID.2:CRC",
          "NKclERKN5boost5arrayI8VertexIDX2EEE")
    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('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")
Пример #34
0
def test_needs_sphinx():
    raises(VersionRequirementError, TestApp, confoverrides={"needs_sphinx": "9.9"})
Пример #35
0
def test_type_definitions():
    check("type", "public bool b", "bool b")
    check("type", "bool A::b")
    check("type", "bool *b")
    check("type", "bool *const b")
    check("type", "bool *volatile const b")
    check("type", "bool *volatile const b")
    check("type", "bool *volatile const *b")
    check("type", "bool &b")
    check("type", "bool b[]")
    check("type", "std::pair<int, int> coord")
    check("type", "long long int foo")
    check("type",
          'std::vector<std::pair<std::string, long long>> module::blah')
    check("type", "std::function<void()> F")
    check("type", "std::function<R(A1, A2, A3)> F")
    check("type", "std::function<R(A1, A2, A3, As...)> F")
    check("type", "MyContainer::const_iterator")
    check("type", "public MyContainer::const_iterator",
          "MyContainer::const_iterator")

    check('member', '  const  std::string  &  name = 42',
          'const std::string &name = 42')
    check('member', '  const  std::string  &  name', 'const std::string &name')
    check('member', '  const  std::string  &  name [ n ]',
          'const std::string &name[n]')
    check('member', 'const std::vector< unsigned int, long> &name',
          'const std::vector<unsigned int, long> &name')
    check('member', 'module::myclass foo[n]')

    check('function', 'operator bool() const')
    check('function', 'bool namespaced::theclass::method(arg1, arg2)')
    x = 'std::vector<std::pair<std::string, int>> &module::test(register ' \
        'foo, bar, std::string baz = "foobar, blah, bleh") const = 0'
    check('function', x)
    check('function', 'explicit module::myclass::foo::foo()')
    check('function', 'module::myclass::foo::~foo()')
    check('function', 'int printf(const char *fmt, ...)')
    check('function', 'int foo(const unsigned int j)')
    check('function', 'int foo(const int *const ptr)')
    check('function', 'module::myclass::operator std::vector<std::string>()')
    check('function',
          'void operator()(const boost::array<VertexID, 2> &v) const')
    check(
        'function',
        'void operator()(const boost::array<VertexID, 2, "foo,  bar"> &v) const'
    )
    check('function', 'MyClass::MyClass(MyClass::MyClass&&)')
    check('function', 'constexpr int get_value()')
    check('function', 'static constexpr int get_value()')
    check('function', 'int get_value() const noexcept')
    check('function', 'int get_value() const noexcept = delete')
    check('function', 'MyClass::MyClass(MyClass::MyClass&&) = default')
    check('function', 'virtual MyClass::a_virtual_function() const override')
    check('function', 'A B() override')
    check('function', 'A B() final')
    check('function', 'A B() final override')
    check('function', 'A B() override final', 'A B() final override')
    check('function', 'MyClass::a_member_function() volatile')
    check('function', 'MyClass::a_member_function() volatile const')
    check('function', 'MyClass::a_member_function() &&')
    check('function', 'MyClass::a_member_function() &')
    check('function', 'MyClass::a_member_function() const &')
    check('function', 'int main(int argc, char *argv[])')
    check('function', 'MyClass &MyClass::operator++()')
    check('function', 'MyClass::pointer MyClass::operator->()')

    x = 'std::vector<std::pair<std::string, int>> &module::test(register ' \
        'foo, bar[n], std::string baz = "foobar, blah, bleh") const = 0'
    check('function', x)
    check(
        'function',
        'int foo(Foo f = Foo(double(), std::make_pair(int(2), double(3.4))))')
    check('function', 'int foo(A a = x(a))')
    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)')
    check('function', 'virtual void f()')
Пример #36
0
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', int, float, 18, 18.0, (0,)
    )

    # List length mismatch
    b = [
        u'hello',
        dict(naughty=u'nurse'),
        18,
        19
    ]
    e = raises(AssertionError, f, a, b, 'foo')
    assert str(e) == LEN % (
        'foo', 3, 4, a, b, tuple()
    )

    b = [
        dict(naughty=u'nurse'),
        18,
    ]
    e = raises(AssertionError, f, a, b, 'foo')
    assert str(e) == LEN % (
        'foo', 3, 2, a, b, tuple()
    )

    # Dict keys mismatch:

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

    # Extra
    b = [
        u'hello',
        dict(naughty=u'nurse', barely=u'legal'),
        18,
    ]
    e = raises(AssertionError, f, a, b, 'foo')
    assert str(e) == KEYS % ('foo',
        [], ['barely'],
        dict(naughty=u'nurse'), dict(naughty=u'nurse', barely=u'legal'),
        (1,)
    )

    # Missing + Extra
    b = [
        u'hello',
        dict(barely=u'legal'),
        18,
    ]
    e = raises(AssertionError, f, a, b, 'foo')
    assert str(e) == KEYS % ('foo',
        ['naughty'], ['barely'],
        dict(naughty=u'nurse'), dict(barely=u'legal'),
        (1,)
    )
Пример #37
0
def test_needs_sphinx():
    raises(VersionRequirementError,
           TestApp,
           confoverrides={'needs_sphinx': '9.9'})
Пример #38
0
 def test_id_and_id_(self):
     raises(TypeError, text, "spam", "pizza", id="fubar", id_="eggs")
Пример #39
0
def test_attributes():
    # style: C++
    check('member', '[[]] int f', 'f__i', '1f')
    check(
        'member',
        '[ [ ] ] int f',
        'f__i',
        '1f',
        # this will fail when the proper grammar is implemented
        output='[[ ]] int f')
    check('member', '[[a]] int f', 'f__i', '1f')
    # style: GNU
    check('member', '__attribute__(()) int f', 'f__i', '1f')
    check('member', '__attribute__((a)) int f', 'f__i', '1f')
    check('member', '__attribute__((a, b)) int f', 'f__i', '1f')
    # style: user-defined id
    check('member', 'id_attr int f', 'f__i', '1f')
    # style: user-defined paren
    check('member', 'paren_attr() int f', 'f__i', '1f')
    check('member', 'paren_attr(a) int f', 'f__i', '1f')
    check('member', 'paren_attr("") int f', 'f__i', '1f')
    check('member', 'paren_attr(()[{}][]{}) int f', 'f__i', '1f')
    raises(DefinitionError, parse, 'member', 'paren_attr(() int f')
    raises(DefinitionError, parse, 'member', 'paren_attr([) int f')
    raises(DefinitionError, parse, 'member', 'paren_attr({) int f')
    raises(DefinitionError, parse, 'member', 'paren_attr([)]) int f')
    raises(DefinitionError, parse, 'member', 'paren_attr((])) int f')
    raises(DefinitionError, parse, 'member', 'paren_attr({]}) int f')

    # position: decl specs
    check('function',
          'static inline __attribute__(()) void f()',
          'f',
          '1fv',
          output='__attribute__(()) static inline void f()')
Пример #40
0
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')
Пример #41
0
def test_get_document(support):
    raises(DocumentNotFoundError, support.get_document, 'nonexisting')

    contents = support.get_document('contents')
    assert contents['title'] and contents['body'] \
        and contents['sidebar'] and contents['relbar']
Пример #42
0
def test_no_srcdir(support):
    """Make sure the correct exception is raised if srcdir is not given."""
    raises(RuntimeError, support.build)
Пример #43
0
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', int, float, 18, 18.0, (0, ))

    # List length mismatch
    b = [u'hello', dict(naughty=u'nurse'), 18, 19]
    e = raises(AssertionError, f, a, b, 'foo')
    assert str(e) == LEN % ('foo', 3, 4, a, b, tuple())

    b = [
        dict(naughty=u'nurse'),
        18,
    ]
    e = raises(AssertionError, f, a, b, 'foo')
    assert str(e) == LEN % ('foo', 3, 2, a, b, tuple())

    # Dict keys mismatch:

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

    # Extra
    b = [
        u'hello',
        dict(naughty=u'nurse', barely=u'legal'),
        18,
    ]
    e = raises(AssertionError, f, a, b, 'foo')
    assert str(e) == KEYS % ('foo', [], ['barely'], dict(naughty=u'nurse'),
                             dict(naughty=u'nurse', barely=u'legal'), (1, ))

    # Missing + Extra
    b = [
        u'hello',
        dict(barely=u'legal'),
        18,
    ]
    e = raises(AssertionError, f, a, b, 'foo')
    assert str(e) == KEYS % ('foo', ['naughty'], ['barely'],
                             dict(naughty=u'nurse'), dict(barely=u'legal'),
                             (1, ))
Пример #44
0
 def test_id_and_id_(self):
     raises(TypeError, text, "spam", "pizza", id="fubar", id_="eggs")
Пример #45
0
def test_type_definitions():
    rv = parse('member_object', '  const  std::string  &  name = 42')
    assert unicode(rv) == 'const std::string& name = 42'

    rv = parse('member_object', '  const  std::string  &  name leftover')
    assert unicode(rv) == 'const std::string& name'

    rv = parse('member_object', '  const  std::string  &  name [n] leftover')
    assert unicode(rv) == 'const std::string& name[n]'

    rv = parse('member_object', 'const std::vector< unsigned int, long> &name')
    assert unicode(rv) == 'const std::vector<unsigned int, long>& name'

    x = 'std::vector<std::pair<std::string, int>>& module::test(register ' \
        'foo, bar, std::string baz="foobar, blah, bleh") const = 0'
    assert unicode(parse('function', x)) == x

    x = 'module::myclass::operator std::vector<std::string>()'
    assert unicode(parse('function', x)) == x
    x = 'explicit module::myclass::foo::foo()'
    assert unicode(parse('function', x)) == x

    x = 'int printf(const char* fmt, ...)'
    assert unicode(parse('function', x)) == x

    x = 'int foo(const unsigned int j)'
    assert unicode(parse('function', x)) == x

    x = 'int foo(const unsigned int const j)'
    assert unicode(parse('function', x)) == x

    x = 'int foo(const int* const ptr)'
    assert unicode(parse('function', x)) == x

    x = 'std::vector<std::pair<std::string, long long>> module::blah'
    assert unicode(parse('type_object', x)) == x

    assert unicode(parse('type_object', 'long long int foo')) == 'long long foo'

    x = 'void operator()(const boost::array<VertexID, 2>& v) const'
    assert unicode(parse('function', x)) == x

    x = 'void operator()(const boost::array<VertexID, 2, "foo,  bar">& v) const'
    assert unicode(parse('function', x)) == x

    x = 'MyClass::MyClass(MyClass::MyClass&&)'
    assert unicode(parse('function', x)) == x

    x = 'constexpr int get_value()'
    assert unicode(parse('function', x)) == x

    x = 'static constexpr int get_value()'
    assert unicode(parse('function', x)) == x

    x = 'int get_value() const noexcept'
    assert unicode(parse('function', x)) == x

    x = 'int get_value() const noexcept = delete'
    assert unicode(parse('function', x)) == x

    x = 'MyClass::MyClass(MyClass::MyClass&&) = default'
    assert unicode(parse('function', x)) == x

    x = 'MyClass::a_virtual_function() const override'
    assert unicode(parse('function', x)) == x

    x = 'MyClass::a_member_function() volatile'
    assert unicode(parse('function', x)) == x

    x = 'MyClass::a_member_function() const volatile'
    assert unicode(parse('function', x)) == x

    x = 'MyClass::a_member_function() &&'
    assert unicode(parse('function', x)) == x

    x = 'MyClass::a_member_function() &'
    assert unicode(parse('function', x)) == x

    x = 'MyClass::a_member_function() const &'
    assert unicode(parse('function', x)) == x

    x = 'int main(int argc, char* argv[][])'
    assert unicode(parse('function', x)) == x

    x = 'std::vector<std::pair<std::string, int>>& module::test(register ' \
        'foo, bar[n], std::string baz="foobar, blah, bleh") const = 0'
    assert unicode(parse('function', x)) == x

    x = 'module::myclass foo[n]'
    assert unicode(parse('member_object', x)) == x

    x = 'int foo(Foo f=Foo(double(), std::make_pair(int(2), double(3.4))))'
    assert unicode(parse('function', x)) == x

    x = 'int foo(A a=x(a))'
    assert unicode(parse('function', x)) == x

    x = 'int foo(B b=x(a)'
    raises(DefinitionError, parse, 'function', x)

    x = 'int foo)C c=x(a))'
    raises(DefinitionError, parse, 'function', x)

    x = 'int foo(D d=x(a'
    raises(DefinitionError, parse, 'function', x)
Пример #46
0
def test_no_srcdir(support):
    # make sure the correct exception is raised if srcdir is not given.
    raises(RuntimeError, support.build)
Пример #47
0
def test_get_document(support):
    raises(DocumentNotFoundError, support.get_document, 'nonexisting')

    contents = support.get_document('contents')
    assert contents['title'] and contents['body'] \
        and contents['sidebar'] and contents['relbar']
Пример #48
0
def test_attributes():
    # style: C++
    check('member', '[[]] int f', 'f__i', '1f')
    check('member', '[ [ ] ] int f', 'f__i', '1f',
          # this will fail when the proper grammar is implemented
          output='[[ ]] int f')
    check('member', '[[a]] int f', 'f__i', '1f')
    # style: GNU
    check('member', '__attribute__(()) int f', 'f__i', '1f')
    check('member', '__attribute__((a)) int f', 'f__i', '1f')
    check('member', '__attribute__((a, b)) int f', 'f__i', '1f')
    # style: user-defined id
    check('member', 'id_attr int f', 'f__i', '1f')
    # style: user-defined paren
    check('member', 'paren_attr() int f', 'f__i', '1f')
    check('member', 'paren_attr(a) int f', 'f__i', '1f')
    check('member', 'paren_attr("") int f', 'f__i', '1f')
    check('member', 'paren_attr(()[{}][]{}) int f', 'f__i', '1f')
    raises(DefinitionError, parse, 'member', 'paren_attr(() int f')
    raises(DefinitionError, parse, 'member', 'paren_attr([) int f')
    raises(DefinitionError, parse, 'member', 'paren_attr({) int f')
    raises(DefinitionError, parse, 'member', 'paren_attr([)]) int f')
    raises(DefinitionError, parse, 'member', 'paren_attr((])) int f')
    raises(DefinitionError, parse, 'member', 'paren_attr({]}) int f')

    # position: decl specs
    check('function', 'static inline __attribute__(()) void f()',
          'f', '1fv',
          output='__attribute__(()) static inline void f()')
Пример #49
0
def test_type_definitions():
    rv = parse('member_object', '  const  std::string  &  name = 42')
    assert unicode(rv) == 'const std::string& name = 42'

    rv = parse('member_object', '  const  std::string  &  name leftover')
    assert unicode(rv) == 'const std::string& name'

    rv = parse('member_object', '  const  std::string  &  name [n] leftover')
    assert unicode(rv) == 'const std::string& name[n]'

    rv = parse('member_object', 'const std::vector< unsigned int, long> &name')
    assert unicode(rv) == 'const std::vector<unsigned int, long>& name'

    x = 'std::vector<std::pair<std::string, int>>& module::test(register ' \
        'foo, bar, std::string baz="foobar, blah, bleh") const = 0'
    assert unicode(parse('function', x)) == x

    x = 'module::myclass::operator std::vector<std::string>()'
    assert unicode(parse('function', x)) == x
    x = 'explicit module::myclass::foo::foo()'
    assert unicode(parse('function', x)) == x

    x = 'int printf(const char* fmt, ...)'
    assert unicode(parse('function', x)) == x

    x = 'int foo(const unsigned int j)'
    assert unicode(parse('function', x)) == x

    x = 'int foo(const unsigned int const j)'
    assert unicode(parse('function', x)) == x

    x = 'int foo(const int* const ptr)'
    assert unicode(parse('function', x)) == x

    x = 'std::vector<std::pair<std::string, long long>> module::blah'
    assert unicode(parse('type_object', x)) == x

    assert unicode(parse('type_object',
                         'long long int foo')) == 'long long foo'

    x = 'void operator()(const boost::array<VertexID, 2>& v) const'
    assert unicode(parse('function', x)) == x

    x = 'void operator()(const boost::array<VertexID, 2, "foo,  bar">& v) const'
    assert unicode(parse('function', x)) == x

    x = 'MyClass::MyClass(MyClass::MyClass&&)'
    assert unicode(parse('function', x)) == x

    x = 'constexpr int get_value()'
    assert unicode(parse('function', x)) == x

    x = 'static constexpr int get_value()'
    assert unicode(parse('function', x)) == x

    x = 'int get_value() const noexcept'
    assert unicode(parse('function', x)) == x

    x = 'int get_value() const noexcept = delete'
    assert unicode(parse('function', x)) == x

    x = 'MyClass::MyClass(MyClass::MyClass&&) = default'
    assert unicode(parse('function', x)) == x

    x = 'MyClass::a_virtual_function() const override'
    assert unicode(parse('function', x)) == x

    x = 'MyClass::a_member_function() volatile'
    assert unicode(parse('function', x)) == x

    x = 'MyClass::a_member_function() const volatile'
    assert unicode(parse('function', x)) == x

    x = 'MyClass::a_member_function() &&'
    assert unicode(parse('function', x)) == x

    x = 'MyClass::a_member_function() &'
    assert unicode(parse('function', x)) == x

    x = 'MyClass::a_member_function() const &'
    assert unicode(parse('function', x)) == x

    x = 'int main(int argc, char* argv[][])'
    assert unicode(parse('function', x)) == x

    x = 'std::vector<std::pair<std::string, int>>& module::test(register ' \
        'foo, bar[n], std::string baz="foobar, blah, bleh") const = 0'
    assert unicode(parse('function', x)) == x

    x = 'module::myclass foo[n]'
    assert unicode(parse('member_object', x)) == x

    x = 'int foo(Foo f=Foo(double(), std::make_pair(int(2), double(3.4))))'
    assert unicode(parse('function', x)) == x

    x = 'int foo(A a=x(a))'
    assert unicode(parse('function', x)) == x

    x = 'int foo(B b=x(a)'
    raises(DefinitionError, parse, 'function', x)

    x = 'int foo)C c=x(a))'
    raises(DefinitionError, parse, 'function', x)

    x = 'int foo(D d=x(a'
    raises(DefinitionError, parse, 'function', x)
Пример #50
0
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')
Пример #51
0
def test_function_definitions():
    check('function', 'operator bool() const', "castto-b-operatorC", "NKcvbEv")
    check('function', 'A::operator bool() const', "A::castto-b-operatorC",
          "NK1AcvbEv")
    check('function', 'A::operator bool() volatile const &',
          "A::castto-b-operatorVCR", "NVKR1AcvbEv")
    check('function', 'A::operator bool() volatile const &&',
          "A::castto-b-operatorVCO", "NVKO1AcvbEv")
    check('function', 'bool namespaced::theclass::method(arg1, arg2)',
          "namespaced::theclass::method__arg1.arg2",
          "N10namespaced8theclass6methodE4arg14arg2")
    x = 'std::vector<std::pair<std::string, int>> &module::test(register int ' \
        'foo, bar, std::string baz = "foobar, blah, bleh") const = 0'
    check('function', x, "module::test__i.bar.ssC",
          "NK6module4testEi3barNSt6stringE")
    check('function', 'void f(std::pair<A, B>)', "f__std::pair:A.B:",
          "1fNSt4pairI1A1BEE")
    check('function', 'explicit module::myclass::foo::foo()',
          "module::myclass::foo::foo", "N6module7myclass3foo3fooEv")
    check('function', 'module::myclass::foo::~foo()',
          "module::myclass::foo::~foo", "N6module7myclass3fooD0Ev")
    check('function', 'int printf(const char *fmt, ...)', "printf__cCP.z",
          "6printfPKcz")
    check('function', 'int foo(const unsigned int j)', "foo__unsigned-iC",
          "3fooKj")
    check('function', 'int foo(const int *const ptr)', "foo__iCPC", "3fooPCKi")
    check('function', 'module::myclass::operator std::vector<std::string>()',
          "module::myclass::castto-std::vector:ss:-operator",
          "N6module7myclasscvNSt6vectorINSt6stringEEEEv")
    check('function',
          'void operator()(const boost::array<VertexID, 2> &v) const',
          "call-operator__boost::array:VertexID.2:CRC",
          "NKclERKN5boost5arrayI8VertexIDX2EEE")
    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")
    check("function", "void f(int *const p)", "f__iPC", "1fPCi")
    check("function", "void f(int *volatile const p)", "f__iPVC", "1fPVCi")

    check('function', 'extern int f()', 'f', '1fv')

    # 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')

    # pointer to member (function)
    check('function', 'void f(int C::*)', None, '1fM1Ci')
    check('function', 'void f(int C::* p)', None, '1fM1Ci')
    check('function', 'void f(int ::C::* p)', None, '1fM1Ci')
    check('function', 'void f(int C::* const)', None, '1fKM1Ci')
    check('function', 'void f(int C::* const&)', None, '1fRKM1Ci')
    check('function', 'void f(int C::* volatile)', None, '1fVM1Ci')
    check('function',
          'void f(int C::* const volatile)',
          None,
          '1fVKM1Ci',
          output='void f(int C::* volatile const)')
    check('function', 'void f(int C::* volatile const)', None, '1fVKM1Ci')
    check('function', 'void f(int (C::*)(float, double))', None, '1fM1CFifdE')
    check('function', 'void f(int (C::* p)(float, double))', None,
          '1fM1CFifdE')
    check('function', 'void f(int (::C::* p)(float, double))', None,
          '1fM1CFifdE')
    check('function', 'void f(void (C::*)() const &)', None, '1fM1CKRFvvE')
    check('function', 'int C::* f(int, double)', None, '1fid')
    check('function', 'void f(int C::* *)', None, '1fPM1Ci')
Пример #52
0
def test_function_definitions():
    check('function', 'operator bool() const', "castto-b-operatorC", "NKcvbEv")
    check('function', 'A::operator bool() const',
          "A::castto-b-operatorC", "NK1AcvbEv")
    check('function', 'A::operator bool() volatile const &',
          "A::castto-b-operatorVCR", "NVKR1AcvbEv")
    check('function', 'A::operator bool() volatile const &&',
          "A::castto-b-operatorVCO", "NVKO1AcvbEv")
    check('function', 'bool namespaced::theclass::method(arg1, arg2)',
          "namespaced::theclass::method__arg1.arg2",
          "N10namespaced8theclass6methodE4arg14arg2")
    x = 'std::vector<std::pair<std::string, int>> &module::test(register int ' \
        'foo, bar, std::string baz = "foobar, blah, bleh") const = 0'
    check('function', x, "module::test__i.bar.ssC",
          "NK6module4testEi3barNSt6stringE")
    check('function', 'void f(std::pair<A, B>)',
          "f__std::pair:A.B:", "1fNSt4pairI1A1BEE")
    check('function', 'explicit module::myclass::foo::foo()',
          "module::myclass::foo::foo", "N6module7myclass3foo3fooEv")
    check('function', 'module::myclass::foo::~foo()',
          "module::myclass::foo::~foo", "N6module7myclass3fooD0Ev")
    check('function', 'int printf(const char *fmt, ...)',
          "printf__cCP.z", "6printfPKcz")
    check('function', 'int foo(const unsigned int j)',
          "foo__unsigned-iC", "3fooKj")
    check('function', 'int foo(const int *const ptr)',
          "foo__iCPC", "3fooPCKi")
    check('function', 'module::myclass::operator std::vector<std::string>()',
          "module::myclass::castto-std::vector:ss:-operator",
          "N6module7myclasscvNSt6vectorINSt6stringEEEEv")
    check('function',
          'void operator()(const boost::array<VertexID, 2> &v) const',
          "call-operator__boost::array:VertexID.2:CRC",
          "NKclERKN5boost5arrayI8VertexIDX2EEE")
    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")
    check("function", "void f(int *const p)", "f__iPC", "1fPCi")
    check("function", "void f(int *volatile const p)", "f__iPVC", "1fPVCi")

    # 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')

    # pointer to member (function)
    check('function', 'void f(int C::*)', None, '1fM1Ci')
    check('function', 'void f(int C::* p)', None, '1fM1Ci')
    check('function', 'void f(int ::C::* p)', None, '1fM1Ci')
    check('function', 'void f(int C::* const)', None, '1fKM1Ci')
    check('function', 'void f(int C::* const&)', None, '1fRKM1Ci')
    check('function', 'void f(int C::* volatile)', None, '1fVM1Ci')
    check('function', 'void f(int C::* const volatile)', None, '1fVKM1Ci',
          output='void f(int C::* volatile const)')
    check('function', 'void f(int C::* volatile const)', None, '1fVKM1Ci')
    check('function', 'void f(int (C::*)(float, double))', None, '1fM1CFifdE')
    check('function', 'void f(int (C::* p)(float, double))', None, '1fM1CFifdE')
    check('function', 'void f(int (::C::* p)(float, double))', None, '1fM1CFifdE')
    check('function', 'void f(void (C::*)() const &)', None, '1fM1CKRFvvE')
    check('function', 'int C::* f(int, double)', None, '1fid')
    check('function', 'void f(int C::* *)', None, '1fPM1Ci')
Пример #53
0
def test_Result():
    """
    Test the `ipahealthcheck.plugin.Result` class
    """

    registry = Registry()
    p = Plugin(registry)

    # Standard case of passing plugin to Result
    r = Result(p, constants.SUCCESS)

    kw = dict(key='value')
    r = Result(p, constants.SUCCESS, **kw)

    e = raises(TypeError, Result)
    assert str(e) == "__init__() missing 2 required positional arguments: " \
                     "'plugin' and 'result'"

    # Test passing source and check to Result. This is used for loading
    # a previous output.
    try:
        r = Result(None, constants.SUCCESS)
    except TypeError as e:
        assert str(e) == "source and check or plugin must be provided"

    try:
        r = Result(None, constants.SUCCESS, source='test')
    except TypeError as e:
        assert str(e) == "source and check or plugin must be provided"

    try:
        r = Result(None, constants.SUCCESS, check='test')
    except TypeError as e:
        assert str(e) == "source and check or plugin must be provided"

    r = Result(None, constants.SUCCESS, source='test', check='test')

    # Test results
    r = Result(p, constants.SUCCESS)
    results = Results()
    results.add(r)

    assert len(results) == 1

    r = Result(p, constants.CRITICAL)
    results2 = Results()
    results2.add(r)

    assert len(results2) == 1

    results.extend(results2)

    assert len(results) == 2

    output = [x for x in results.output()]
    assert len(output) == 2
    for x in output:
        assert x['source'] == 'ipahealthcheck.core.plugin'
        assert x['check'] == 'Plugin'
        assert x['result'] in (constants.getLevelName(constants.SUCCESS),
                               constants.getLevelName(constants.CRITICAL))
        assert len(x['kw']) == 0
Пример #54
0
def test_type_definitions():
    check("type", "public bool b", "bool b")
    check("type", "bool A::b")
    check("type", "bool *b")
    check("type", "bool *const b")
    check("type", "bool *volatile const b")
    check("type", "bool *volatile const b")
    check("type", "bool *volatile const *b")
    check("type", "bool &b")
    check("type", "bool b[]")
    check("type", "std::pair<int, int> coord")
    check("type", "long long int foo")
    check("type", 'std::vector<std::pair<std::string, long long>> module::blah')
    check("type", "std::function<void()> F")
    check("type", "std::function<R(A1, A2, A3)> F")
    check("type", "std::function<R(A1, A2, A3, As...)> F")
    check("type", "MyContainer::const_iterator")
    check("type",
          "public MyContainer::const_iterator",
          "MyContainer::const_iterator")

    check('member',
          '  const  std::string  &  name = 42',
          'const std::string &name = 42')
    check('member', '  const  std::string  &  name', 'const std::string &name')
    check('member',
          '  const  std::string  &  name [ n ]',
          'const std::string &name[n]')
    check('member',
          'const std::vector< unsigned int, long> &name',
          'const std::vector<unsigned int, long> &name')
    check('member', 'module::myclass foo[n]')

    check('function', 'operator bool() const')
    check('function', 'bool namespaced::theclass::method(arg1, arg2)')
    x = 'std::vector<std::pair<std::string, int>> &module::test(register ' \
        'foo, bar, std::string baz = "foobar, blah, bleh") const = 0'
    check('function', x)
    check('function', 'explicit module::myclass::foo::foo()')
    check('function', 'module::myclass::foo::~foo()')
    check('function', 'int printf(const char *fmt, ...)')
    check('function', 'int foo(const unsigned int j)')
    check('function', 'int foo(const int *const ptr)')
    check('function', 'module::myclass::operator std::vector<std::string>()')
    check('function',
          'void operator()(const boost::array<VertexID, 2> &v) const')
    check('function',
          'void operator()(const boost::array<VertexID, 2, "foo,  bar"> &v) const')
    check('function', 'MyClass::MyClass(MyClass::MyClass&&)')
    check('function', 'constexpr int get_value()')
    check('function', 'static constexpr int get_value()')
    check('function', 'int get_value() const noexcept')
    check('function', 'int get_value() const noexcept = delete')
    check('function', 'MyClass::MyClass(MyClass::MyClass&&) = default')
    check('function', 'virtual MyClass::a_virtual_function() const override')
    check('function', 'A B() override')
    check('function', 'A B() final')
    check('function', 'A B() final override')
    check('function', 'A B() override final', 'A B() final override')
    check('function', 'MyClass::a_member_function() volatile')
    check('function', 'MyClass::a_member_function() volatile const')
    check('function', 'MyClass::a_member_function() &&')
    check('function', 'MyClass::a_member_function() &')
    check('function', 'MyClass::a_member_function() const &')
    check('function', 'int main(int argc, char *argv[])')
    check('function', 'MyClass &MyClass::operator++()')
    check('function', 'MyClass::pointer MyClass::operator->()')

    x = 'std::vector<std::pair<std::string, int>> &module::test(register ' \
        'foo, bar[n], std::string baz = "foobar, blah, bleh") const = 0'
    check('function', x)
    check('function',
          'int foo(Foo f = Foo(double(), std::make_pair(int(2), double(3.4))))')
    check('function', 'int foo(A a = x(a))')
    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)')
    check('function', 'virtual void f()')
Пример #55
0
def test_needs_sphinx():
    raises(VersionRequirementError, TestApp,
           confoverrides={'needs_sphinx': '9.9'})
Пример #56
0
def test_type_definitions():
    check("type", "public bool b", "b", "1b", "bool b")
    check("type", "bool A::b", "A::b", "N1A1bE")
    check("type", "bool *b", "b", "1b")
    check("type", "bool *const b", "b", "1b")
    check("type", "bool *volatile const b", "b", "1b")
    check("type", "bool *volatile const b", "b", "1b")
    check("type", "bool *volatile const *b", "b", "1b")
    check("type", "bool &b", "b", "1b")
    check("type", "bool b[]", "b", "1b")
    check("type", "std::pair<int, int> coord", "coord", "5coord")
    check("type", "long long int foo", "foo", "3foo")
    check("type", 'std::vector<std::pair<std::string, long long>> module::blah',
          "module::blah", "N6module4blahE")
    check("type", "std::function<void()> F", "F", "1F")
    check("type", "std::function<R(A1, A2)> F", "F", "1F")
    check("type", "std::function<R(A1, A2, A3)> F", "F", "1F")
    check("type", "std::function<R(A1, A2, A3, As...)> F", "F", "1F")
    check("type", "MyContainer::const_iterator",
          "MyContainer::const_iterator", "N11MyContainer14const_iteratorE")
    check("type",
          "public MyContainer::const_iterator",
          "MyContainer::const_iterator", "N11MyContainer14const_iteratorE",
          output="MyContainer::const_iterator")
    # test decl specs on right
    check("type", "bool const b", "b", "1b")
    # test name in global scope
    check("type", "bool ::B::b", "B::b", "N1B1bE")

    check('member', '  const  std::string  &  name = 42',
          "name__ssCR", "4name", output='const std::string &name = 42')
    check('member', '  const  std::string  &  name', "name__ssCR", "4name",
          output='const std::string &name')
    check('member', '  const  std::string  &  name [ n ]',
          "name__ssCRA", "4name", output='const std::string &name[n]')
    check('member', 'const std::vector< unsigned int, long> &name',
          "name__std::vector:unsigned-i.l:CR",
          "4name", output='const std::vector<unsigned int, long> &name')
    check('member', 'module::myclass foo[n]', "foo__module::myclassA", "3foo")

    check('function', 'operator bool() const', "castto-b-operatorC", "NKcvbEv")
    check('function', 'A::operator bool() const',
          "A::castto-b-operatorC", "NK1AcvbEv")
    check('function', 'A::operator bool() volatile const &',
          "A::castto-b-operatorVCR", "NVKR1AcvbEv")
    check('function', 'A::operator bool() volatile const &&',
          "A::castto-b-operatorVCO", "NVKO1AcvbEv")
    check('function', 'bool namespaced::theclass::method(arg1, arg2)',
          "namespaced::theclass::method__arg1.arg2",
          "N10namespaced8theclass6methodE4arg14arg2")
    x = 'std::vector<std::pair<std::string, int>> &module::test(register int ' \
        'foo, bar, std::string baz = "foobar, blah, bleh") const = 0'
    check('function', x, "module::test__i.bar.ssC",
          "NK6module4testEi3barNSt6stringE")
    check('function', 'void f(std::pair<A, B>)',
          "f__std::pair:A.B:", "1fNSt4pairI1A1BEE")
    check('function', 'explicit module::myclass::foo::foo()',
          "module::myclass::foo::foo", "N6module7myclass3foo3fooEv")
    check('function', 'module::myclass::foo::~foo()',
          "module::myclass::foo::~foo", "N6module7myclass3fooD0Ev")
    check('function', 'int printf(const char *fmt, ...)',
          "printf__cCP.z", "6printfPKcz")
    check('function', 'int foo(const unsigned int j)',
          "foo__unsigned-iC", "3fooKj")
    check('function', 'int foo(const int *const ptr)',
          "foo__iCPC", "3fooPCKi")
    check('function', 'module::myclass::operator std::vector<std::string>()',
          "module::myclass::castto-std::vector:ss:-operator",
          "N6module7myclasscvNSt6vectorINSt6stringEEEEv")
    check('function',
          'void operator()(const boost::array<VertexID, 2> &v) const',
          "call-operator__boost::array:VertexID.2:CRC",
          "NKclERKN5boost5arrayI8VertexIDX2EEE")
    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')