File: testproject.py

package info (click to toggle)
exhale 0.3.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,616 kB
  • sloc: python: 9,057; cpp: 1,260; javascript: 915; f90: 29; ansic: 18; makefile: 16
file content (51 lines) | stat: -rw-r--r-- 1,685 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import textwrap

from docutils import nodes
from docutils.parsers.rst import Directive
from sphinx.locale import _

import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent.absolute()))
from github_url import get_github_base_url


def visit_testproject_node(self, node):
    self.visit_admonition(node)


def depart_testproject_node(self, node):
    self.depart_admonition(node)


class testproject(nodes.Admonition, nodes.Element):
    pass


class TestProjectDirective(Directive):
    has_content = True

    def run(self):
        if len(self.content) != 1:
            raise ValueError(
                "`testproject` directive needs exactly one argument (the name of the test folder).  "
                "Example: .. testproject:: c_maths"
            )
        self.content[0] = textwrap.dedent('''\
            The ``{project}`` test project.

            - Additional documentation: :mod:`testing.projects.{project_fixed}`.
            - Source code for `{project} available here <{baseurl}/{project_dir}>`_.

            See also: :data:`ExhaleTestCase.test_project <testing.base.ExhaleTestCase.test_project>`.
        '''.format(
            project=self.content[0],
            project_dir=self.content[0].replace(" ", "\\ "),
            project_fixed=self.content[0].replace(" ", "_"),  # cpp with spaces project
            baseurl=f"{get_github_base_url()}/testing/projects"
        ))
        project_node = testproject("\n".join(self.content))
        project_node += nodes.title(_("Test Project Source"), _("Test Project Source"))
        self.state.nested_parse(self.content, self.content_offset, project_node)

        return [project_node]