Exemplo n.º 1
0
        .+?\#{5}\s+Example # ensure the next code is in the Example section
        .+?```python\n+(.+?)\n``` # capture the source
        .+?\#{5}\s+Matches.+?^\|:--\|:--\| # ensure the table is in the Matches section
        (\n\|\s`(?P<LABELS>[^\|]+)`\s\|\s(?P<LINES>[^\|]+)\s\|)+ # capture the expected results
    """
    return regex.finditer(rex, text)


parse = ProgramParser()
reformat_spec(parse.spec_path)
examples = []
for match in extract_examples(parse.spec_path):
    label_name = match.group(1)
    source = match.group(2)
    source = regex.sub(r"(?m)^.{1,4}", "", source)
    source = centrifugate_hints(source)
    (addition, deletion) = collect_hints(source)
    source = remove_hints(source)
    program = Program(source=source,
                      labels=[],
                      taxons=[],
                      addition=addition,
                      deletion=deletion)
    actual_results = dict(parse(program))
    expected_results = list(
        zip(match.captures("LABELS"), match.captures("LINES")))
    examples.append((label_name, actual_results, expected_results))


@pytest.mark.parametrize("label_name, actual_results, expected_results",
                         examples)
def test_centrifugate_hints(title, original, expected):
    print(title)
    result = centrifugate_hints(original)
    print(result)
    assert result == expected