예제 #1
0
    def test_find_actions_somedoc_noaction(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

        Test Steps
        ==========

        There are no rst directives in this section.
        ''')
        assert rstsource.find_actions(src) == []
예제 #2
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
예제 #3
0
    def test_find_actions_emptydoc(self):
        src = textwrap.dedent('''\
        Test Steps
        ==========

        There are no rst directives.
        ''')
        assert rstsource.find_actions(src) == []
예제 #4
0
    def test_find_actions_real_looking_test_steps_section(self):
        src = textwrap.dedent('''\
        Test Steps
        ==========

        .. test_step:: 1

            list files in the volume: ``ls -a /mnt/helloworld``

        .. test_result:: 1

            there are no files, output should be empty.

        .. test_step:: 2

            donec et mollis dolor::

                $ foo --extra sth
                $ bar -vvv

        .. test_result:: 2

            Maecenas congue ligula ac quam viverra nec
            consectetur ante hendrerit.

        .. test_step:: 3

            This one has no matching test result.

        .. test_result:: 4

            And this result has no test step.

            Donec et mollis dolor::

                $ foo --extra sth
                $ bar -vvv

        .. test_step:: 5

            List files in the volume: ``ls -a /mnt/helloworld``

            This is the last step.
        ''')
        exp_actions = [
            rstsource.RstTestAction(1, "test_step", 4, 6),
            rstsource.RstTestAction(1, "test_result", 8, 10),
            rstsource.RstTestAction(2, "test_step", 12, 17),
            rstsource.RstTestAction(2, "test_result", 19, 22),
            rstsource.RstTestAction(3, "test_step", 24, 26),
            rstsource.RstTestAction(4, "test_result", 28, 35),
            rstsource.RstTestAction(5, "test_step", 37, 41),
        ]
        assert rstsource.find_actions(src) == exp_actions
예제 #5
0
    def test_find_actions_minimal_single_action_highid(self):
        src = textwrap.dedent('''\
        .. test_step:: 3

            Maecenas congue ligula ac quam viverra nec
            consectetur ante hendrerit.

            This directive is the last node in this rst document.
        ''')
        exp_actions = [
            rstsource.RstTestAction(3, "test_step", 1, 6),
        ]
        assert rstsource.find_actions(src) == exp_actions
예제 #6
0
    def test_find_actions_simpledoc_endline_theend(self):
        src = textwrap.dedent('''\
        Test Steps
        ==========

        .. test_step:: 10

            Maecenas congue ligula ac quam viverra nec
            consectetur ante hendrerit.

            This directive is the last node in this rst document.
        ''')
        exp_actions = [
            rstsource.RstTestAction(10, "test_step", 4, 9),
        ]
        assert rstsource.find_actions(src) == exp_actions
예제 #7
0
    def test_find_actions_simpledoc_endline_paragraph(self):
        src = textwrap.dedent('''\
        Test Steps
        ==========

        .. test_step:: 5

            Maecenas congue ligula ac quam viverra nec
            consectetur ante hendrerit.

            And that's all!

        There is some other text after the directive.
        ''')
        exp_actions = [
            rstsource.RstTestAction(5, "test_step", 4, 9),
        ]
        assert rstsource.find_actions(src) == exp_actions
예제 #8
0
    def test_find_actions_simpledoc_endline_anotherdirective(self):
        src = textwrap.dedent('''\
        Test Steps
        ==========

        .. test_step:: 1

            Maecenas congue ligula ac quam viverra nec
            consectetur ante hendrerit.

            And that's all!

        .. test_step:: 2

            Maecenas congue ligula ac quam viverra nec
            consectetur ante hendrerit.
        ''')
        exp_actions = [
            rstsource.RstTestAction(1, "test_step", 4, 9),
            rstsource.RstTestAction(2, "test_step", 11, 14),
        ]
        assert rstsource.find_actions(src) == exp_actions
예제 #9
0
    def test_find_actions_somedoc_oneaction(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
        ```````

        .. test_step:: 1

            Maecenas congue ligula ac quam viverra nec
            consectetur ante hendrerit.

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

           def foo(bar):
               return False

        Test Steps
        ==========

        There are no rst directives in this section.
        ''')
        exp_actions = [
            rstsource.RstTestAction(1, "test_step", 18, 21),
        ]
        assert rstsource.find_actions(src) == exp_actions
예제 #10
0
    def test_find_actions_mixed(self):
        src = textwrap.dedent('''\
        This looks little fishy.

        .. test_step:: 1

            list files in the volume: ``ls -a /mnt/helloworld``

        This just some line. Ignore it.

        .. test_result:: 1

            there are no files, output should be empty.

        And another one! Let's ignore it as well.

        .. test_step:: 2

            donec et mollis dolor::

                $ foo --extra sth
                $ bar -vvv

        Test Steps
        ==========

        This doesn't make any sense.

        .. test_result:: 2

            Maecenas congue ligula ac quam viverra nec
            consectetur ante hendrerit.

        Test Steps Subsection
        `````````````````````

        Yay!

        .. test_step:: 3

            This one has no matching test result.

        .. test_result:: 4

            And this result has no test step.

            Donec et mollis dolor::

                $ foo --extra sth
                $ bar -vvv

        Foo Bar Baz Section
        ===================

        Really, this looks weird. But find_sections() should work anyway.

        .. test_step:: 5

            List files in the volume: ``ls -a /mnt/helloworld``

            This is the last step.
        ''')
        exp_actions = [
            rstsource.RstTestAction(1, "test_step", 3, 5),
            rstsource.RstTestAction(1, "test_result", 9, 11),
            rstsource.RstTestAction(2, "test_step", 15, 20),
            rstsource.RstTestAction(2, "test_result", 27, 30),
            rstsource.RstTestAction(3, "test_step", 37, 39),
            rstsource.RstTestAction(4, "test_result", 41, 48),
            rstsource.RstTestAction(5, "test_step", 55, 59),
        ]
        assert rstsource.find_actions(src) == exp_actions
예제 #11
0
 def test_find_actions_null(self):
     assert rstsource.find_actions("") == []
예제 #12
0
from pylatest.xdocutils.core import register_all

parser = argparse.ArgumentParser(
    description="Convert directives test_{step,result} into test_action.")
parser.add_argument("rstfile")
args = parser.parse_args()

register_all(use_plain=True)

actions = TestActions()

# extract test actions of all deprecated test_{step,result} directives,
# including line numbers
with open(args.rstfile) as rstfile:
    rstsource = rstfile.read()
    for action in find_actions(rstsource):
        actions.add(action.action_name, action, action.action_id)

# list with content of rstfile
rstcontent = rstsource.splitlines()

# number of next line in rstfile to go to output, zero indexed
next_line_number = 0

with open(args.rstfile, "w") as rstfile:
    for action_id, test_step, test_result in actions:
        # make the assumptions clear
        assert test_step is not None
        assert test_step.start_line > next_line_number
        if test_result is not None:
            assert test_step.end_line < test_result.start_line