-
-
Notifications
You must be signed in to change notification settings - Fork 606
/
parser_test.py
34 lines (28 loc) · 1.27 KB
/
parser_test.py
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
# Copyright 2020 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).
import pytest
from pants.build_graph.build_file_aliases import BuildFileAliases
from pants.engine.internals.parser import BuildFilePreludeSymbols, ParseError, Parser
from pants.util.frozendict import FrozenDict
def test_imports_banned() -> None:
parser = Parser(target_type_aliases=[], object_aliases=BuildFileAliases())
with pytest.raises(ParseError) as exc:
parser.parse(
"dir/BUILD", "\nx = 'hello'\n\nimport os\n", BuildFilePreludeSymbols(FrozenDict())
)
assert "Import used in dir/BUILD at line 4" in str(exc.value)
def test_unrecognized_symbol() -> None:
parser = Parser(
target_type_aliases=["tgt"],
object_aliases=BuildFileAliases(
objects={"obj": 0},
context_aware_object_factories={"caof": lambda parse_context: lambda _: None},
),
)
prelude_symbols = BuildFilePreludeSymbols(FrozenDict({"prelude": 0}))
with pytest.raises(ParseError) as exc:
parser.parse("dir/BUILD", "fake", prelude_symbols)
assert (
str(exc.value)
== "Name 'fake' is not defined.\n\nAll registered symbols: ['caof', 'obj', 'prelude', 'tgt']"
)