Esempio n. 1
0
    def test_find_sections_doc_without_title(self):
        src = textwrap.dedent('''\
        There is no title or any sections. Just a paragraph.

        Or two.
        ''')
        assert rstsource.find_sections(src) == []
Esempio n. 2
0
    def test_find_sections_multilevel_startswithline(self):
        src = textwrap.dedent('''\
        Having some text like this before any title will make this rst
        document to lack a title.

        ===============
         Status Report
        ===============

        Lieber ein Spatz in der Hand als eine Taube auf dem Dach.

        Header One
        ==========

        Here is some text.

        .. while this line tries to hide itself

        Achtung
        ```````

        In this piece of code, we can see a similar issue::

           def foo(bar):
               return False

        Header Two
        ==========

        And here we have some text again.
        ''')
        exp_sections = [
            rstsource.RstSection("Status Report", 5, 28),
        ]
        assert rstsource.find_sections(src) == exp_sections
Esempio n. 3
0
    def test_find_sections_metadata_simple_wrong(self):
        src = textwrap.dedent('''\
        Hello World Test Case
        *********************

        :author: [email protected]
        :date: 2015-11-06
        :comment: This is here just to test metadata processing.

        Section One
        ***********

        Foo.

        Section Two
        ***********

        Bar.
        ''')
        exp_sections = [
            rstsource.RstSection("Hello World Test Case", 1, 6),
            rstsource.RstSection('Section One', 8, 11),
            rstsource.RstSection('Section Two', 13, 16),
        ]
        assert rstsource.find_sections(src) == exp_sections
Esempio n. 4
0
 def build_doc(self):
     """
     Build RstTestCaseDoc object based on pylatest string literals (aka
     document fragments) stored in this object.
     """
     if self.default is None:
         doc = RstTestCaseDoc()
     else:
         # TODO: this builds the default doc every time, cache the build
         # (if nothing changed - for merging def doc.)
         doc = self.default.build_doc()
     # find pylatest document sections/directives in every fragment
     for lineno, doc_str in self.docstrings.items():
         doc_str_lines = doc_str.splitlines()
         for rst_act in find_actions(doc_str):
             content = extract_content(doc_str_lines, rst_act.start_line,
                                       rst_act.end_line)
             doc.add_test_action(rst_act.action_name, content,
                                 rst_act.action_id, lineno)
         for rst_sct in find_sections(doc_str):
             if rst_sct.title is None:
                 section = TestCaseDoc._HEAD
             else:
                 section = Section(rst_sct.title)
             content = extract_content(doc_str_lines, rst_sct.start_line,
                                       rst_sct.end_line)
             doc.add_section(section, content, lineno)
     return doc
Esempio n. 5
0
    def test_find_sections_metadata_doc_without_title(self):
        src = textwrap.dedent('''\
        There is no title or any sections. Just a paragraph and some metadata.

        :author: [email protected]
        :date: 2015-11-06
        :comment: This is here just to test metadata processing.
        ''')
        assert rstsource.find_sections(src) == []
Esempio n. 6
0
    def test_find_sections_docwithoutsections_two(self):
        src = textwrap.dedent('''\
        =============
         Hello World
        =============

        Again, there are no sections, just a document title.
        ''')
        assert rstsource.find_sections(src) == []
Esempio n. 7
0
    def test_find_sections_metadata_simple_two(self):
        src = textwrap.dedent('''\
        Just Another Test Case
        **********************

        :author: [email protected]
        ''')
        exp_sections = [
            rstsource.RstSection(None, 1, 4),
        ]
        assert rstsource.find_sections(src) == exp_sections
Esempio n. 8
0
    def test_find_sections_docwithoutsections_one(self):
        src = textwrap.dedent('''\
        Hello World
        ***********

        There are no sections, just a document title.
        But in this case, it's evaluated as a section, so that
        we are able to detect section fragments.
        ''')
        exp_sections = [
            rstsource.RstSection("Hello World", 1, 6),
        ]
        assert rstsource.find_sections(src) == exp_sections
Esempio n. 9
0
    def test_find_sections_metadata_simple_one(self):
        src = textwrap.dedent('''\
        Hello World Test Case
        *********************

        :author: [email protected]
        :date: 2015-11-06
        :comment: This is here just to test metadata processing.


        ''')
        exp_sections = [
            rstsource.RstSection(None, 1, 8),
        ]
        assert rstsource.find_sections(src) == exp_sections
Esempio n. 10
0
    def test_find_sections_simpledoc(self):
        src = textwrap.dedent('''\
        Section One
        ***********

        Foo.

        Section Two
        ***********

        Bar.
        ''')
        exp_sections = [
            rstsource.RstSection("Section One", 1, 4),
            rstsource.RstSection("Section Two", 6, 9),
        ]
        assert rstsource.find_sections(src) == exp_sections
Esempio n. 11
0
    def test_find_sections_metadata_with_other_sections_one(self):
        src = textwrap.dedent('''\
        Just Another Test Case
        **********************

        :author: [email protected]

        Description
        ===========

        Vivamus fermentum semper porta. Nunc diam velit, adipiscing ut tristique
        vitae, sagittis vel odio. Maecenas convallis ullamcorper ultricies.
        ''')
        exp_sections = [
            rstsource.RstSection('Description', 6, 10),
            rstsource.RstSection(None, 1, 4),
        ]
        assert rstsource.find_sections(src) == exp_sections
Esempio n. 12
0
    def test_find_sections_docwithoutsections_one_another(self):
        """
        The same case as test_find_sections_docwithoutsections_one.
        """
        src = textwrap.dedent('''\
        Description
        ===========

        This is just demonstration of usage of pylatest rst directives and
        expected structure of rst document.

        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam
        lectus.  Sed sit amet ipsum mauris. Maecenas congue ligula ac quam
        viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent
        et diam eget libero egestas mattis sit amet vitae augue.

        See :RHBZ:`439858` for more details.
        ''')
        exp_sections = [
            rstsource.RstSection(TestCaseDoc.DESCR.title, 1, 12),
        ]
        assert rstsource.find_sections(src) == exp_sections
Esempio n. 13
0
    def test_find_sections_multilevel_with_testmetadata(self):
        src = textwrap.dedent('''\
        =============
         Test FooBar
        =============

        :author: [email protected]
        :date: 2015-11-06

        Header One
        ==========

        Here is some text.

        .. while this line tries to hide itself

        Achtung
        ```````

        In this piece of code, we can see a similar issue::

           def foo(bar):
               return False

        Header Two
        ==========

        And here we have some text again.

        Header Three
        ============
        ''')
        exp_sections = [
            rstsource.RstSection("Header One", 8, 21),
            rstsource.RstSection("Header Two", 23, 26),
            rstsource.RstSection("Header Three", 28, 29),
            rstsource.RstSection(None, 1, 6),
        ]
        assert rstsource.find_sections(src) == exp_sections
Esempio n. 14
0
    def test_find_sections_multilevel(self):
        src = textwrap.dedent('''\
        ===============
         Status Report
        ===============

        Lieber ein Spatz in der Hand als eine Taube auf dem Dach.

        Header One
        ==========

        Here is some text.

        .. while this line tries to hide itself

        Achtung
        ```````

        In this piece of code, we can see a similar issue::

           def foo(bar):
               return False

        Header Two
        ==========

        And here we have some text again.

        Header Three
        ============
        ''')
        exp_sections = [
            rstsource.RstSection("Header One", 7, 20),
            rstsource.RstSection("Header Two", 22, 25),
            rstsource.RstSection("Header Three", 27, 28),
        ]
        assert rstsource.find_sections(src) == exp_sections
Esempio n. 15
0
 def test_find_sections_emptydoc(self):
     assert rstsource.find_sections("") == []