def test_correctness(subtests, tests_path): for path in tests_path.glob('**/*.config'): with subtests.test(path=path): with open(path, 'r') as file: parents, scope = parse_string(file.read(), '.config') if not parents: Semantics(scope, set(vars(builtins))).check()
def standardize(source): parents, scope = parse_string(source, '.config') result = '\n'.join(f'from {"." * imp.dots}{".".join(imp.root)} import *' for imp in parents) + '\n' return result + '\n'.join( render_scope(scope, {v: i for i, v in enumerate(scope)})) + '\n'
def validate_config(source: str): parents, scope = parse_string(source, '.config') assert not parents Semantics(scope, set(vars(builtins))).check()
def test_unrecognized_token(): with pytest.raises(SyntaxError): parse_string('$', '.config')
def test_unexpected_eof(): with pytest.raises(SyntaxError): parse_string('a = [1, 2', '.config')