Пример #1
0
class TestDictDiff(CheckData):
    data_page_text_1 = trim("""
        .. dictdiff:: data*/file.pickle
        """)
    data_page_text_2 = trim("""
        .. dictdiff:: data*/file.pickle
           :link: %(path)s
        """)
    data_page_text_3 = trim("""
        .. dictdiff:: data*/file.pickle
           :link: %(non_magic_word)s
        """)
    data_file_tree = {
        'data_1/file.pickle': {
            'a': 1,
            'b': 0
        },
        'data_2/file.pickle': {
            'a': 2,
            'b': 0
        },
        'data_3/file.pickle': {
            'a': 3,
            'b': 0
        },
    }
    data_dictdiff = {
        'a': {
            'data_1/file.pickle': 1,
            'data_2/file.pickle': 2,
            'data_3/file.pickle': 3,
        },
    }
    data_links_2 = ['data_1', 'data_2', 'data_3']

    data = [
        (data_page_text_1, data_file_tree, data_dictdiff, []),
        (data_page_text_2, data_file_tree, data_dictdiff, data_links_2),
        (data_page_text_3, data_file_tree, data_dictdiff, None),
    ]

    def check(self, page_text, file_tree, dictdiff, links):
        page_path = 'it does not depend on the page_path'
        web = MockWeb()
        DictTable = MockDictTable.new_mock(file_tree)
        glob_list = Mock(return_value=sorted(file_tree))
        setup_wiki(web=web, DictTable=DictTable, glob_list=glob_list)
        page_html = gene_html(page_text, page_path)

        for key in dictdiff:
            assert key in page_html

        if links:
            for link in links:
                assert '%s</a>' % link in page_html
        elif links == []:
            assert 'link(s)' not in page_html
Пример #2
0
    def check_temp(self, base_path, page_text, num):
        assert num > 0
        temp_path = urljoin(base_path, *(['_temp_'] * num))
        temp_text = page_text + "\n" + trim("""
        path: {{ path }}
        relpath: {{ relpath }}
        """) + "\n" + "\n".join(
            "args[%(i)d]: {{ args[%(i)d] }}" % {'i': i}
            for i in range(num))

        self.check_save(temp_path, temp_text)

        args = ['arg%d' % i for i in range(num)]
        page_path = urljoin(base_path, *args)
        response = self.app.get(page_path + '/')
        for (i, a) in enumerate(args):
            assert "args[%d]: %s" % (i, a) in response.data
        assert "path: %s" % page_path in response.data
        assert "relpath: /%s" % '/'.join(args) in response.data

        # clean up is needed to avoid the template page to match
        # another page. this is required when NEORG_FASTTEST is
        # specified.
        if NEORG_FASTTEST:
            self.check_delete_yes(temp_path, '')
Пример #3
0
class TestGridImages(CheckData):

    data_file_tree_1 = dict(
        ('a_%d_b_%d_c_%d/file.pickle' % (a, b, c), dict(a=a, b=b, c=c))
        for (a, b, c) in product([0, 1, 2], [3, 4, 5], [6, 7, 8]))

    data_file_tree_2 = dict(
        (key, val) for (key, val) in data_file_tree_1.iteritems() if key not in
        ['a_%d_b_%d_c_%d/file.pickle' % abc for abc in [(0, 3, 6), (0, 3, 7)]])

    data_page_text_1 = trim("""
        .. grid-images:: */file.pickle
           :param: a b c
           :image: dummy-image.png
        """)

    data = [
        (
            data_page_text_1,
            data_file_tree_1,
            {
                '<td>': ((3**3) * 2  # number of images + c=%d besides it
                         + 3 * 3  # number of sub-tables (num_a x num_b)
                         + 3 * 2  # number of a=%d and b=%d
                         + 1  # top-left empty cell
                         ),
            },
        ),
        (
            data_page_text_1,
            data_file_tree_2,
            {
                '<td>': ((3**3) * 2  # number of images + c=%d besides it
                         + 3 * 3  # number of sub-tables (num_a x num_b)
                         + 3 * 2  # number of a=%d and b=%d
                         + 1  # top-left empty cell
                         ),
            },
        ),
        (
            data_page_text_1,
            {},  # no match
            {
                '<td>': 1
            },
        ),
    ]

    def check(self, page_text, file_tree, stats):
        page_path = 'it does not depend on the page_path'
        web = MockWeb()
        DictTable = MockDictTable.new_mock(file_tree)
        glob_list = Mock(return_value=sorted(file_tree))
        setup_wiki(web=web, DictTable=DictTable, glob_list=glob_list)
        page_html = gene_html(page_text, page_path)

        for (key, val) in stats.iteritems():
            eq_(page_html.count(key), val,
                "page_html must contains %d of '%s'" % (val, key))
Пример #4
0
    def test_search_deleted(self):
        query = 'some_long_string_to_test_search_deleted.'
        page_path = 'TestSearchDeleted'
        page_text = trim("""
        This page will be deleted
        -------------------------

        {0}.
        """.format(query))
        self.check_search_match(page_path, page_text, query)
        self.check_delete_yes(page_path, page_text)  # delete
        response = self.get_search_response(query)
        assert_raises(AssertionError, self.assert_page_path_in_search_result,
                      page_path, response)  # no match
Пример #5
0
    def test_search_deleted(self):
        query = 'some_long_string_to_test_search_deleted.'
        page_path = 'TestSearchDeleted'
        page_text = trim("""
        This page will be deleted
        -------------------------

        {0}.
        """.format(query))
        self.check_search_match(page_path, page_text, query)
        self.check_delete_yes(page_path, page_text)  # delete
        response = self.get_search_response(query)
        assert_raises(AssertionError,
                      self.assert_page_path_in_search_result,
                      page_path, response)  # no match
Пример #6
0
def test_gene_html_no_fail():
    exception_message = (
        '`gene_html` should not fail whatever happen during the '
        'html generation, provided DEBUG=False')
    page_text = trim("""
    .. dictdiff:: *

    dictdiff is for raising Exception via DictTable
    """)
    page_path = 'it does not depend on the page_path'
    web = MockWeb()
    DictTable = Mock()
    DictTable.from_path_list = Mock(
        side_effect=CheckException(exception_message))
    glob_list = Mock(return_value=[])
    setup_wiki(web=web, DictTable=DictTable, glob_list=glob_list)

    # error must be suppressed when _debug=False
    page_html = gene_html(page_text, page_path, _debug=False)
    assert exception_message in page_html  # TB will be returned

    # error must NOT be suppressed when _debug=True
    assert_raises(CheckException, gene_html, page_text, page_path, _debug=True)
Пример #7
0
    def check_temp(self, base_path, page_text, num):
        assert num > 0
        temp_path = urljoin(base_path, *(['_temp_'] * num))
        temp_text = page_text + "\n" + trim("""
        path: {{ path }}
        relpath: {{ relpath }}
        """) + "\n" + "\n".join("args[%(i)d]: {{ args[%(i)d] }}" % {'i': i}
                                for i in range(num))

        self.check_save(temp_path, temp_text)

        args = ['arg%d' % i for i in range(num)]
        page_path = urljoin(base_path, *args)
        response = self.app.get(page_path + '/')
        for (i, a) in enumerate(args):
            assert "args[%d]: %s" % (i, a) in response.data
        assert "path: %s" % page_path in response.data
        assert "relpath: /%s" % '/'.join(args) in response.data

        # clean up is needed to avoid the template page to match
        # another page. this is required when NEORG_FASTTEST is
        # specified.
        if NEORG_FASTTEST:
            self.check_delete_yes(temp_path, '')
Пример #8
0
def test_gene_html_no_fail():
    exception_message = (
        '`gene_html` should not fail whatever happen during the '
        'html generation, provided DEBUG=False')
    page_text = trim("""
    .. dictdiff:: *

    dictdiff is for raising Exception via DictTable
    """)
    page_path = 'it does not depend on the page_path'
    web = MockWeb()
    DictTable = Mock()
    DictTable.from_path_list = Mock(
        side_effect=CheckException(exception_message))
    glob_list = Mock(return_value=[])
    setup_wiki(web=web, DictTable=DictTable, glob_list=glob_list)

    # error must be suppressed when _debug=False
    page_html = gene_html(page_text, page_path, _debug=False)
    assert exception_message in page_html   # TB will be returned

    # error must NOT be suppressed when _debug=True
    assert_raises(CheckException, gene_html,
                  page_text, page_path, _debug=True)
Пример #9
0
class TestPagePathInlineMarkup(CheckData):
    data_symbols = ',!?;:(){}[]<>@#$%^&-+|\\~\'\"='

    data = [
        (
            trim("""
         This should become an /link/to/the/other/page/.
         But this should not: not/the/link/to/the/other/page/.
         """),
            ['/link/to/the/other/page/'],
            ['not/the/link/to/the/other/page/'],
        ),
        (
            trim("""
         /texts/in/the/literal/block/::

             /will/not/be/a/link/
         """),
            ['/texts/in/the/literal/block/'],
            ['/will/not/be/a/link/'],
        ),
        (
            trim("""
         */texts/in/the/inline/emphasis/literal/*
         **/texts/in/the/inline/strong/emphasis/literal/**
         """),
            [
                '/texts/in/the/inline/emphasis/literal/',
                '/texts/in/the/inline/strong/emphasis/literal/'
            ],
            [],
        ),
        (
            trim("""
         ``/texts/in/the/inline/literal/``
         """),
            [],
            ['/texts/in/the/inline/literal/'],
        ),
        (
            trim("""
         `/texts/in/the/hyper/link/ <link>`_`
         """),
            [],
            ['/texts/in/the/hyper/link/'],
        ),
        (
            trim("""
         /texsts_with_a_-hyphen-after-the-under_score/
         """),  # known issue
            [],
            ['/texsts_with_a_-hyphen-after-the-under_score/'],
        ),
        (
            trim("""
         /texsts_with_a\_-hyphen-after-the-under_score/
         """),  # this (^-- this slash!) is a workaround
            ['/texsts_with_a_-hyphen-after-the-under_score/'],
            [],
        ),
    ] + [('%s/starts/with/' % s, ['/starts/with/'], [])
         for s in '/' + data_symbols] + [('/ends/with/%s' % s, ['/ends/with/'
                                                                ], [])
                                         for s in '.' + data_symbols]

    def check(self, page_text, links, not_links):
        page_path = 'it does not depend on the page_path'
        web = object()  # web shuold not be used
        DictTable = object()  # DictTable should not be used
        setup_wiki(web=web, DictTable=DictTable)
        page_html = gene_html(
            page_text,
            page_path,
            settings_overrides={
                # ignore docutils system errors
                'report_level': 4,
            })

        def html_link(link):
            return 'href="%(link)s">%(link)s</a>' % {'link': link}

        for l in links:
            assert html_link(l) in page_html, \
                   "link '%s' should be in `page_html`" % l
        for l in not_links:
            assert html_link(l) not in page_html, \
                   "link '%s' should NOT be in `page_html`" % l