File: test_makerestdoc.py

package info (click to toggle)
pypy3 7.0.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 111,848 kB
  • sloc: python: 1,291,746; ansic: 74,281; asm: 5,187; cpp: 3,017; sh: 2,533; makefile: 544; xml: 243; lisp: 45; csh: 21; awk: 4
file content (88 lines) | stat: -rw-r--r-- 3,395 bytes parent folder | download | duplicates (10)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import py

from rpython.config.config import *
from pypy.config.makerestdoc import make_cmdline_overview
from pypy.tool.rest.rest import process as restcheck

tempdir = py.test.ensuretemp('config')

try:
    import docutils
except ImportError:
    py.test.skip("don't have docutils")

def checkrest(rest, filename):
    tempfile = tempdir.join(filename)
    tempfile.write(rest)
    restcheck(tempfile)
    return tempfile.new(ext='.html').read()

def generate_html(descr):
    config = Config(descr)
    txt = descr.make_rest_doc().text()

    result = {"": txt}
    for path in config.getpaths(include_groups=True):
        subconf, step = config._cfgimpl_get_home_by_path(path)
        fullpath = (descr._name + "." + path)
        prefix = fullpath.rsplit(".", 1)[0]
        txt = getattr(subconf._cfgimpl_descr, step).make_rest_doc(
                prefix).text()
        result[path] = txt
    return result

def test_simple():
    descr = OptionDescription("foo", "doc", [
            ChoiceOption("bar", "more doc", ["a", "b", "c"]),
            OptionDescription("sub", "nope", [
                ChoiceOption("subbar", "", ["d", "f"]),
                BoolOption("boolean", "this is a boolean", default=False,
                           cmdline="-b --with-b")
                ]),
            StrOption("str", "string option!", default="strange"),
            IntOption("int", "integer option", default=42),
            FloatOption("float", "float option", default=py.std.math.pi),
            ArbitraryOption("surprise", "special", defaultfactory=int),
            ])
    generate_html(descr)

def test_choice_requires():
    descr = OptionDescription("s0", "doc", [
            BoolOption("b1", "", default=False),
            BoolOption("b2", "", default=False),
            BoolOption("b3", "", default=False),
            ChoiceOption("bar", "more doc", ["a", "b", "c"],
                         default="a",
                         requires={"a": [("s0.b1", True),
                                         ("s0.b2", False)],
                                   "b": [("s0.b1", False)]})
            ])
    generate_html(descr)

def test_bool_requires_suggests():
    descr = OptionDescription("a0", "doc", [
            BoolOption("B1", "", default=False),
            BoolOption("B2", "", default=False,
                       suggests=[("a0.B1", True)]),
            BoolOption("B3", "", default=False,
                       requires=[("a0.bar", "c"), ("a0.B2", True)]),
            ChoiceOption("bar", "more doc", ["a", "b", "c"],
                         default="a")])
    result = generate_html(descr)

def test_cmdline_overview():
    descr = OptionDescription("foo", "doc", [
            ChoiceOption("bar", "more doc", ["a", "b", "c"]),
            OptionDescription("sub", "nope", [
                ChoiceOption("subbar", "", ["d", "f"]),
                BoolOption("boolean", "this is a boolean", default=False,
                           cmdline="-b --with-b")
                ]),
            StrOption("str", "string option!", default="strange"),
            IntOption("int", "integer option", default=42),
            FloatOption("float", "float option", default=py.std.math.pi),
            ArbitraryOption("surprise", "special", defaultfactory=int),
            ])
    generate_html(descr)
    c = make_cmdline_overview(descr)
    checkrest(c.text(), "index.txt")