Skip to content

Commit cc15a67

Browse files
committed
format tests with ruff
1 parent eba4c94 commit cc15a67

24 files changed

+1754
-1388
lines changed

pyformlang/cfg/tests/test_cfg.py

Lines changed: 375 additions & 274 deletions
Large diffs are not rendered by default.

pyformlang/cfg/tests/test_llone_parser.py

Lines changed: 266 additions & 150 deletions
Large diffs are not rendered by default.

pyformlang/cfg/tests/test_production.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
""" Tests the productions """
1+
"""Tests the productions."""
22

33
from pyformlang.cfg import Production, Variable, Terminal
44

55

66
class TestProduction:
7-
""" Tests the production """
7+
"""Tests the production."""
8+
89
# pylint: disable=missing-function-docstring
910

10-
def test_creation(self):
11+
def test_creation(self) -> None:
1112
prod0 = Production(Variable("S0"), [Terminal("S1"), Variable("a")])
1213
prod1 = Production(Variable("S0"), [Terminal("S1"), Variable("a")])
1314
prod2 = Production(Variable("S0'"), [Terminal("S1"), Variable("a")])

pyformlang/cfg/tests/test_recursive_decent_parser.py

Lines changed: 70 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
# pylint: disable=missing-class-docstring
33
# pylint: disable=missing-function-docstring
44
from pyformlang.cfg import CFG, Variable, Terminal
5-
from pyformlang.cfg.recursive_decent_parser import \
6-
RecursiveDecentParser, NotParsableError
5+
from pyformlang.cfg.recursive_decent_parser import (
6+
RecursiveDecentParser,
7+
NotParsableError,
8+
)
79
import pytest
810

911

@@ -19,43 +21,84 @@ def parser():
1921

2022

2123
class TestRecursiveDecentParser:
22-
23-
def test_creation(self, parser):
24+
def test_creation(self, parser) -> None:
2425
assert parser is not None
2526

26-
def test_get_parsing_tree(self, parser):
27+
def test_get_parsing_tree(self, parser) -> None:
2728
assert parser.is_parsable(
2829
["(", "int", "+", "(", "int", "*", "int", ")", ")"]
2930
)
3031
parse_tree = parser.get_parse_tree(
31-
["(", "int", "+", "(", "int", "*", "int", ")", ")"])
32+
["(", "int", "+", "(", "int", "*", "int", ")", ")"]
33+
)
3234
derivation = parse_tree.get_leftmost_derivation()
33-
assert derivation == \
34-
[[Variable("S")],
35-
[Terminal("("), Variable("E"), Terminal(")")],
36-
[Terminal("("), Variable("S"), Terminal("+"), Variable("S"),
37-
Terminal(")")],
38-
[Terminal("("), Terminal("int"), Terminal("+"), Variable("S"),
39-
Terminal(")")],
40-
[Terminal("("), Terminal("int"), Terminal("+"), Terminal("("),
41-
Variable("E"), Terminal(")"), Terminal(")")],
42-
[Terminal("("), Terminal("int"), Terminal("+"), Terminal("("),
43-
Variable("S"), Terminal("*"), Variable("S"), Terminal(")"),
44-
Terminal(")")],
45-
[Terminal("("), Terminal("int"), Terminal("+"), Terminal("("),
46-
Terminal("int"), Terminal("*"), Variable("S"), Terminal(")"),
47-
Terminal(")")],
48-
[Terminal("("), Terminal("int"), Terminal("+"), Terminal("("),
49-
Terminal("int"), Terminal("*"), Terminal("int"), Terminal(")"),
50-
Terminal(")")],
51-
]
35+
assert derivation == [
36+
[Variable("S")],
37+
[Terminal("("), Variable("E"), Terminal(")")],
38+
[
39+
Terminal("("),
40+
Variable("S"),
41+
Terminal("+"),
42+
Variable("S"),
43+
Terminal(")"),
44+
],
45+
[
46+
Terminal("("),
47+
Terminal("int"),
48+
Terminal("+"),
49+
Variable("S"),
50+
Terminal(")"),
51+
],
52+
[
53+
Terminal("("),
54+
Terminal("int"),
55+
Terminal("+"),
56+
Terminal("("),
57+
Variable("E"),
58+
Terminal(")"),
59+
Terminal(")"),
60+
],
61+
[
62+
Terminal("("),
63+
Terminal("int"),
64+
Terminal("+"),
65+
Terminal("("),
66+
Variable("S"),
67+
Terminal("*"),
68+
Variable("S"),
69+
Terminal(")"),
70+
Terminal(")"),
71+
],
72+
[
73+
Terminal("("),
74+
Terminal("int"),
75+
Terminal("+"),
76+
Terminal("("),
77+
Terminal("int"),
78+
Terminal("*"),
79+
Variable("S"),
80+
Terminal(")"),
81+
Terminal(")"),
82+
],
83+
[
84+
Terminal("("),
85+
Terminal("int"),
86+
Terminal("+"),
87+
Terminal("("),
88+
Terminal("int"),
89+
Terminal("*"),
90+
Terminal("int"),
91+
Terminal(")"),
92+
Terminal(")"),
93+
],
94+
]
5295

53-
def test_no_parse_tree(self, parser):
96+
def test_no_parse_tree(self, parser) -> None:
5497
with pytest.raises(NotParsableError):
5598
parser.get_parse_tree([")"])
5699
assert not (parser.is_parsable([")"]))
57100

58-
def test_infinite_recursion(self):
101+
def test_infinite_recursion(self) -> None:
59102
cfg = CFG.from_text("""
60103
S -> S E
61104
""")

pyformlang/cfg/tests/test_terminal.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
""" Tests the terminal """
1+
"""Tests the terminal."""
2+
23
from pyformlang.cfg import Variable, Terminal, Epsilon
34
from pyformlang.finite_automaton import State, Symbol, Epsilon as FAEpsilon
45

56

67
class TestTerminal:
7-
""" Tests the terminal """
8+
"""Tests the terminal."""
9+
810
# pylint: disable=missing-function-docstring
911

10-
def test_creation(self):
12+
def test_creation(self) -> None:
1113
terminal0 = Terminal(0)
1214
terminal1 = Terminal(1)
1315
terminal2 = Terminal(0)
@@ -27,7 +29,7 @@ def test_creation(self):
2729
assert str(terminal0) == "0"
2830
assert repr(terminal0) == "Terminal(0)"
2931

30-
def test_eq(self):
32+
def test_eq(self) -> None:
3133
assert "epsilon" == Epsilon()
3234
assert Epsilon() == "ɛ"
3335
assert Terminal("A") != Variable("A")

pyformlang/cfg/tests/test_variable.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
""" Tests the variable """
1+
"""Tests the variable."""
2+
23
from pyformlang.cfg import Variable
34

45

56
class TestVariable:
6-
""" Tests the variable """
7+
"""Tests the variable."""
8+
79
# pylint: disable=missing-function-docstring
810

9-
def test_creation(self):
11+
def test_creation(self) -> None:
1012
variable0 = Variable(0)
1113
variable1 = Variable(1)
1214
variable2 = Variable(0)

0 commit comments

Comments
 (0)