| 1 | import py |
| 2 | |
| 3 | from rpython.config.config import * |
| 4 | from pypy.config.makerestdoc import make_cmdline_overview |
| 5 | from pypy.tool.rest.rest import process as restcheck |
| 6 | |
| 7 | tempdir = py.test.ensuretemp('config') |
| 8 | |
| 9 | try: |
| 10 | import docutils |
| 11 | except ImportError: |
| 12 | py.test.skip("don't have docutils") |
| 13 | |
| 14 | def checkrest(rest, filename): |
| 15 | tempfile = tempdir.join(filename) |
| 16 | tempfile.write(rest) |
| 17 | restcheck(tempfile) |
| 18 | return tempfile.new(ext='.html').read() |
| 19 | |
| 20 | def generate_html(descr): |
| 21 | config = Config(descr) |
| 22 | txt = descr.make_rest_doc().text() |
| 23 | |
| 24 | result = {"": txt} |
| 25 | for path in config.getpaths(include_groups=True): |
| 26 | subconf, step = config._cfgimpl_get_home_by_path(path) |
| 27 | fullpath = (descr._name + "." + path) |
| 28 | prefix = fullpath.rsplit(".", 1)[0] |
| 29 | txt = getattr(subconf._cfgimpl_descr, step).make_rest_doc( |
| 30 | prefix).text() |
| 31 | result[path] = txt |
| 32 | return result |
| 33 | |
| 34 | def test_simple(): |
| 35 | descr = OptionDescription("foo", "doc", [ |
| 36 | ChoiceOption("bar", "more doc", ["a", "b", "c"]), |
| 37 | OptionDescription("sub", "nope", [ |
| 38 | ChoiceOption("subbar", "", ["d", "f"]), |
| 39 | BoolOption("boolean", "this is a boolean", default=False, |
| 40 | cmdline="-b --with-b") |
| 41 | ]), |
| 42 | StrOption("str", "string option!", default="strange"), |
| 43 | IntOption("int", "integer option", default=42), |
| 44 | FloatOption("float", "float option", default=py.std.math.pi), |
| 45 | ArbitraryOption("surprise", "special", defaultfactory=int), |
| 46 | ]) |
| 47 | generate_html(descr) |
| 48 | |
| 49 | def test_choice_requires(): |
| 50 | descr = OptionDescription("s0", "doc", [ |
| 51 | BoolOption("b1", "", default=False), |
| 52 | BoolOption("b2", "", default=False), |
| 53 | BoolOption("b3", "", default=False), |
| 54 | ChoiceOption("bar", "more doc", ["a", "b", "c"], |
| 55 | default="a", |
| 56 | requires={"a": [("s0.b1", True), |
| 57 | ("s0.b2", False)], |
| 58 | "b": [("s0.b1", False)]}) |
| 59 | ]) |
| 60 | generate_html(descr) |
| 61 | |
| 62 | def test_bool_requires_suggests(): |
| 63 | descr = OptionDescription("a0", "doc", [ |
| 64 | BoolOption("B1", "", default=False), |
| 65 | BoolOption("B2", "", default=False, |
| 66 | suggests=[("a0.B1", True)]), |
| 67 | BoolOption("B3", "", default=False, |
| 68 | requires=[("a0.bar", "c"), ("a0.B2", True)]), |
| 69 | ChoiceOption("bar", "more doc", ["a", "b", "c"], |
| 70 | default="a")]) |
| 71 | result = generate_html(descr) |
| 72 | |
| 73 | def test_cmdline_overview(): |
| 74 | descr = OptionDescription("foo", "doc", [ |
| 75 | ChoiceOption("bar", "more doc", ["a", "b", "c"]), |
| 76 | OptionDescription("sub", "nope", [ |
| 77 | ChoiceOption("subbar", "", ["d", "f"]), |
| 78 | BoolOption("boolean", "this is a boolean", default=False, |
| 79 | cmdline="-b --with-b") |
| 80 | ]), |
| 81 | StrOption("str", "string option!", default="strange"), |
| 82 | IntOption("int", "integer option", default=42), |
| 83 | FloatOption("float", "float option", default=py.std.math.pi), |
| 84 | ArbitraryOption("surprise", "special", defaultfactory=int), |
| 85 | ]) |
| 86 | generate_html(descr) |
| 87 | c = make_cmdline_overview(descr) |
| 88 | checkrest(c.text(), "index.txt") |