Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hermansje committed Mar 5, 2019
1 parent 165acbc commit f576e39
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
18 changes: 12 additions & 6 deletions tests/test_ast_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ class Test(AliasNode):
assert Test._fields == ("x",)


def test_spec_parse():
field_spec_str = "x=a.b"
field_spec = parse_field_spec(field_spec_str)
@pytest.mark.parametrize("field_spec_str, field_spec", [
("x", ("x", ["x"])),
("x=a", ("x", ["a"])),
("x=a.b", ("x", ["a", "b"])),
("x = a", ("x", ["a"])),
("x= a ", ("x", ["a"])),
])
def test_spec_parse(field_spec_str, field_spec):
spec = parse_field_spec(field_spec_str)

assert field_spec.name == "x"
assert field_spec.origin == ["a", "b"]
assert field_spec == ("x", ["a", "b"])
assert spec.name == field_spec[0]
assert spec.origin == field_spec[1]
assert spec == field_spec
6 changes: 3 additions & 3 deletions tests/test_expr_ast.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from antlr_ast.ast import AliasNode, parse as parse_ast, process_tree
from antlr_ast.ast import AliasNode, parse as parse_ast, process_tree, BaseNodeTransformer

from . import grammar

Expand All @@ -15,7 +15,7 @@ class NotExpr(AliasNode):
_fields_spec = ["op=NOT", "expr"]


class Transformer:
class Transformer(BaseNodeTransformer):
def visit_BinaryExpr(self, node):
return BinaryExpr.from_spec(node)

Expand All @@ -31,7 +31,7 @@ def visit_Terminal(self, node):

def parse(text, start="expr", **kwargs):
antlr_tree = parse_ast(grammar, text, start, upper=False, **kwargs)
simple_tree = process_tree(antlr_tree, Transformer)
simple_tree = process_tree(antlr_tree, transformer_cls=Transformer)

return simple_tree

Expand Down
4 changes: 2 additions & 2 deletions tests/test_visitor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from antlr_ast.ast import rule_to_visitor_name
from antlr_ast.ast import get_transformer_method_name


@pytest.mark.parametrize(
Expand All @@ -14,4 +14,4 @@
],
)
def test_upper_first(text, result):
assert rule_to_visitor_name(text) == result
assert get_transformer_method_name(text) == result

0 comments on commit f576e39

Please sign in to comment.