Skip to content

Commit

Permalink
Add test for file-level Boundary
Browse files Browse the repository at this point in the history
  • Loading branch information
emdoyle committed Feb 7, 2024
1 parent cb53970 commit 51692e9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
1 change: 0 additions & 1 deletion modguard/core/boundary.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class Boundary:

@dataclass
class BoundaryNode:
name: str = ""
public_members: dict[str, PublicMember] = field(default_factory=dict)
children: dict = field(default_factory=dict)
is_end_of_path: bool = False
Expand Down
4 changes: 4 additions & 0 deletions tests/example/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from modguard import Boundary

# intentional import violations
from .domain_one.interface import domain_one_interface
from .domain_three.api import public_for_domain_two
from .domain_four.subsystem import private_subsystem_call

# OK import
import example.domain_four

# modguard-ignore
Expand Down
3 changes: 0 additions & 3 deletions tests/example/domain_four/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
from modguard import Boundary

Boundary()
7 changes: 7 additions & 0 deletions tests/example/domain_four/subsystem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from modguard import Boundary

Boundary()


def private_subsystem_call():
...
13 changes: 7 additions & 6 deletions tests/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ def test_has_boundary():

def test_get_imports():
assert get_imports("example/domain_one/interface.py") == ["modguard.public"]
assert get_imports("example/domain_one/__init__.py") == [
assert set(get_imports("example/domain_one/__init__.py")) == {
"modguard.Boundary",
"example.domain_one.interface.domain_one_interface",
]
assert get_imports("example/__init__.py") == [
}
assert set(get_imports("example/__init__.py")) == {
"modguard.Boundary",
"example.domain_one.interface.domain_one_interface",
"example.domain_three.api.public_for_domain_two",
"example.domain_four",
]
"example.domain_four.subsystem.private_subsystem_call",
}


def test_check():
Expand All @@ -48,9 +49,9 @@ def test_check():
boundary_path="example.domain_one",
),
ErrorInfo(
import_mod_path="example.domain_four",
import_mod_path="example.domain_four.subsystem.private_subsystem_call",
location="example/__init__.py",
boundary_path="example.domain_four",
boundary_path="example.domain_four.subsystem",
),
]
check_results = check("example")
Expand Down

0 comments on commit 51692e9

Please sign in to comment.