예제 #1
0
 async def test_run_nodes(self):
     with contextlib.ExitStack() as stack:
         await run_nodes(
             CONSOLETEST_README_PATH.parent,
             CONSOLETEST_README_PATH.parent,
             stack,
             nodes_to_test(parse_nodes(
                 CONSOLETEST_README_PATH.read_text())),
         )
예제 #2
0
    def test_parse_nodes(self):
        self.maxDiff = None
        self.assertListEqual(
            list(
                filter(
                    lambda node: node.directive in
                    {"code-block", "literalinclude"},
                    parse_nodes(
                        inspect.cleandoc(r"""
                .. code-block:: console
                    :test:

                    $ echo -e 'Hello\n\n\nWorld'
                    Hello


                    World

                .. literalinclude:: some/file.py
                    :filepath: myfile.py
                    :test:

                .. note::

                    .. note::

                        .. code-block:: console
                            :test:
                            :daemon: 8080

                            $ echo -e 'Hello\n\n\n    World\n\n\nTest'
                            Hello


                                World


                            Test

                    .. code-block:: console

                        $ echo -e 'Hello\n\n\n    World\n\n\n\n'
                        Hello


                            World



                        $ echo 'feedface'
                        feedface

                    .. note::

                        .. code-block:: console
                            :test:

                            $ echo feedface
                            feedface

                .. code-block:: console
                    :test:

                    $ echo feedface
                    feedface
                """)),
                )),
            [
                Node(
                    directive="code-block",
                    content=[
                        r"$ echo -e 'Hello\n\n\nWorld'",
                        "Hello",
                        "",
                        "",
                        "World",
                    ],
                    options={"test": True},
                    node={},
                ),
                Node(
                    directive="literalinclude",
                    content="",
                    options={
                        "filepath": "myfile.py",
                        "test": True
                    },
                    node={"source": "some/file.py"},
                ),
                Node(
                    directive="code-block",
                    content=[
                        r"$ echo -e 'Hello\n\n\n    World\n\n\nTest'",
                        "Hello",
                        "",
                        "",
                        "    World",
                        "",
                        "",
                        "Test",
                    ],
                    options={
                        "test": True,
                        "daemon": "8080"
                    },
                    node={},
                ),
                Node(
                    directive="code-block",
                    content=[
                        r"$ echo -e 'Hello\n\n\n    World\n\n\n\n'",
                        "Hello",
                        "",
                        "",
                        "    World",
                        "",
                        "",
                        "",
                        "$ echo 'feedface'",
                        "feedface",
                    ],
                    options={},
                    node={},
                ),
                Node(
                    directive="code-block",
                    content=[
                        "$ echo feedface",
                        "feedface",
                    ],
                    options={"test": True},
                    node={},
                ),
                Node(
                    directive="code-block",
                    content=[
                        "$ echo feedface",
                        "feedface",
                    ],
                    options={"test": True},
                    node={},
                ),
            ],
        )
예제 #3
0
for name, (import_name, module, obj) in to_test.items():
    # Check that class or function has an example that could be doctested
    docstring = inspect.getdoc(obj)
    # Remove the package name from the Python style path to the object
    name = name[len(package_name) + 1:]
    # Create a dictionary to hold the test case functions of the AsyncTestCase
    # class we're going to create
    test_cases = {}
    # Add a doctest testcase if there are any lines to doctest
    if docstring is not None and ">>>" in docstring:
        test_cases["test_docstring"] = mktestcase(name, import_name, module,
                                                  obj)
    # Add a consoletest testcase if there are any testable rst nodes
    if docstring is not None and [
            node for node in parse_nodes(docstring) if "test" in node.options
    ]:
        test_cases["test_consoletest"] = mkconsoletest(name, import_name,
                                                       module, obj)
    # Only create the instance of AsyncTestCase if the object's docstring holds
    # anything that could have a testcase made out of it
    if not test_cases:
        continue
    # Create the test case class with the object as a property and test cases
    testcase = type(name.replace(".", "_"), (AsyncTestCase, ), {
        "obj": obj,
        **test_cases
    })
    # Create the name of the class using the path to it and the object name
    # Add the class to this file's globals
    setattr(sys.modules[__name__], testcase.__qualname__, testcase)