-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from datacamp/fix/get_cls
[LE-1175] Fix get_cls in BaseNodeRegistry
- Loading branch information
Showing
4 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
__version__ = "0.8.0" | ||
__version__ = "0.8.1" | ||
|
||
from . import ast |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import pytest | ||
|
||
from antlr_ast.ast import BaseNodeRegistry | ||
|
||
|
||
def test_base_node_registry_get_cls(): | ||
# Given | ||
base_node_registry = BaseNodeRegistry() | ||
|
||
# When | ||
cls1 = base_node_registry.get_cls("cls1", ("field1",)) | ||
cls1_2 = base_node_registry.get_cls("cls1", ("field1", "field2")) | ||
|
||
# Then | ||
assert set(cls1._fields) == {"field1", "field2"} | ||
assert set(cls1_2._fields) == {"field1", "field2"} | ||
|
||
|
||
def test_base_node_registry_isinstance(): | ||
# Given | ||
base_node_registry = BaseNodeRegistry() | ||
|
||
# When | ||
Cls1 = base_node_registry.get_cls("cls1", ("field1",)) | ||
Cls1_2 = base_node_registry.get_cls("cls1", ("field1", "field2")) | ||
Cls2 = base_node_registry.get_cls("cls2", ("field_a", "field_b")) | ||
|
||
cls1_obj = Cls1([], [], []) | ||
cls1_2_obj = Cls1_2([], [], []) | ||
cls2_obj = Cls2([], [], []) | ||
|
||
# Then | ||
assert isinstance(cls1_obj, type(cls1_2_obj)) | ||
assert base_node_registry.isinstance(cls1_obj, "cls1") | ||
assert base_node_registry.isinstance(cls1_2_obj, "cls1") | ||
assert base_node_registry.isinstance(cls2_obj, "cls2") | ||
assert not base_node_registry.isinstance(cls1_obj, "cls2") | ||
assert not base_node_registry.isinstance(cls1_2_obj, "cls2") | ||
assert not base_node_registry.isinstance(cls2_obj, "cls1") | ||
|
||
assert not base_node_registry.isinstance(cls2_obj, "cls3") | ||
|
||
with pytest.raises( | ||
TypeError, match="This function can only be used for BaseNode objects" | ||
): | ||
base_node_registry.isinstance([], "cls1") |