Example #1
0
def test_parse_class_modulename(line, module):
    # check if the module name has been removed form the class def
    r = RSTReader()
    load_rst(r, CD_ACCEL)
    r.current_module = module
    # process
    r.parse()
    # check
    assert len(r.output) > 1
    assert line in [l.rstrip() for l in r.output]
Example #2
0
def test_parse_class_micro_modulename(line):
    # check if the module name has been removed form the class def
    r = RSTReader()
    load_rst(r, CD_HASHLIB)
    # r.current_module = module # 'uhashlib'
    # process
    r.parse()
    # check
    assert len(r.output) > 1
    # don't care about indentation,
    # but one of the lines must start with the class def
    assert any([l.strip().startswith(line) for l in r.output])
def test_parse_docstr_quoted():
    # quoted docstrings from module level constants
    r = RSTReader()
    load_rst(r, QUOTED_DOCSTR)
    r.parse()
    # check
    assert len(r.output) > 1
    assert len(r.output_dict["constants"]) > 2

    assert not any([l.startswith("# :") for l in r.output_dict["constants"]
                    ]), "Some lines were not unquoted"
    assert not any([l.startswith("# +") for l in r.output_dict["constants"]
                    ]), "Some lines were not unquoted"
def test_parse_docstr_module():
    # check if the module name has been removed form the class def
    r = RSTReader()
    load_rst(r, MODULE_DOCSTR)
    # r.current_module = module # 'uhashlib'
    # process
    r.parse()
    # check
    assert len(r.output) > 1
    assert len(r.output_dict["docstr"]) > 20

    # start & end with triple Quote
    assert r.output_dict["docstr"][0] == '"""'
    assert r.output_dict["docstr"][-1] == '"""'
def test_module_constants():
    # test is module level constants can be processed
    r = RSTReader()
    load_rst(r, MACHINE_RST)
    r.current_module = "machine"
    # process
    r.parse()
    # check
    assert len(r.output) > 1
    list = r.output_dict["constants"]
    doc_list = [c for c in list if c.startswith("#")]
    const_list = [c for c in list if not c.startswith("#")]
    # should have 11  constants
    assert len(const_list) == 11
    # and 11 single line comments for docstrings
    assert len(doc_list) == 11
def test_class_constants():
    # check if the module name has been removed form the class def
    r = RSTReader()
    load_rst(r, MACHINE_PIN_RST)
    # r.current_module = module # 'uhashlib'
    # process
    r.parse()
    # check
    assert len(r.output) > 1
    expected = [
        "class Pin():",
        "    #    Selects the pin mode.",
        "    IN : Any",
        "    OPEN_DRAIN : Any",
        "    #    Test wildcard handling.",
        "    # JOKER_* : Any",
        "    def __init__(self, id, mode=-1, pull=-1, *, value=None, drive=-1, alt=-1) -> None:",
    ]
    lines = [l.rstrip() for l in r.output]
    for l in expected:
        assert l in lines