Skip to content

Commit

Permalink
Add abstract method tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eliotwrobson committed Oct 21, 2023
1 parent 7f38399 commit 9d357e9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions automata/fa/fa.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ def iter_transitions(self) -> Generator[Tuple[FAStateT, FAStateT, str], None, No
of the form (from_state, to_state, symbol)
"""

raise NotImplementedError(
f"iter_transitions is not implemented for {self.__class__}"
)

def show_diagram(
self,
input_str: Optional[str] = None,
Expand Down
8 changes: 8 additions & 0 deletions tests/test_fa.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ class TestFAAbstract(unittest.TestCase):
def test_abstract_methods_not_implemented(self) -> None:
"""Should raise NotImplementedError when calling abstract methods."""

abstract_methods = {
"iter_transitions": (FA,),
"_get_input_path": (FA, ""),
}
for method_name, method_args in abstract_methods.items():
with self.assertRaises(NotImplementedError):
getattr(FA, method_name)(*method_args)

with self.assertRaises(NotImplementedError):
getattr(FA, "_get_input_path")(FA, "")

Expand Down
13 changes: 13 additions & 0 deletions tests/test_pda.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from automata.pda.dpda import DPDA
from automata.pda.npda import NPDA
from automata.pda.pda import PDA


class TestPDA(unittest.TestCase):
Expand Down Expand Up @@ -76,3 +77,15 @@ def setUp(self) -> None:
final_states={"q2"},
acceptance_mode="final_state",
)


class TestPDAAbstract(unittest.TestCase):
def test_abstract_methods_not_implemented(self) -> None:
"""Should raise NotImplementedError when calling abstract methods."""
abstract_methods = {
"iter_transitions": (PDA,),
"_get_input_path": (PDA, ""),
}
for method_name, method_args in abstract_methods.items():
with self.assertRaises(NotImplementedError):
getattr(PDA, method_name)(*method_args)

0 comments on commit 9d357e9

Please sign in to comment.