Skip to content

Commit 833e71d

Browse files
committed
ruff changes
1 parent 06690a7 commit 833e71d

3 files changed

Lines changed: 85 additions & 28 deletions

File tree

src/graphomotor/core/models.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,7 @@ def from_bbox(
247247
n_cells = n_rows * n_cols
248248
if labels is not None and len(labels) != n_cells:
249249
raise ValueError(
250-
f"labels length ({len(labels)}) must match "
251-
f"n_rows * n_cols ({n_cells})."
250+
f"labels length ({len(labels)}) must match n_rows * n_cols ({n_cells})."
252251
)
253252

254253
padded_x_min = x_min - padding

tests/unit/test_alphabet_utils.py

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,13 @@ def test_strokes_assigned_to_correct_cells(self) -> None:
3030
data = _make_drawing_data()
3131
grid = alphabet_utils.segment_strokes(
3232
data=data,
33-
x_min=0.0, x_max=100.0, y_min=0.0, y_max=100.0,
34-
n_rows=2, n_cols=2, labels=["TL", "TR", "BL", "BR"],
33+
x_min=0.0,
34+
x_max=100.0,
35+
y_min=0.0,
36+
y_max=100.0,
37+
n_rows=2,
38+
n_cols=2,
39+
labels=["TL", "TR", "BL", "BR"],
3540
)
3641

3742
assert len(grid.cells[0].strokes) == 1
@@ -47,8 +52,12 @@ def test_total_stroke_count_matches_line_numbers(self) -> None:
4752
data = _make_drawing_data()
4853
grid = alphabet_utils.segment_strokes(
4954
data=data,
50-
x_min=0.0, x_max=100.0, y_min=0.0, y_max=100.0,
51-
n_rows=2, n_cols=2,
55+
x_min=0.0,
56+
x_max=100.0,
57+
y_min=0.0,
58+
y_max=100.0,
59+
n_rows=2,
60+
n_cols=2,
5261
)
5362

5463
total_strokes = sum(len(c.strokes) for c in grid.cells)
@@ -59,8 +68,12 @@ def test_stroke_points_are_correct(self) -> None:
5968
data = _make_drawing_data()
6069
grid = alphabet_utils.segment_strokes(
6170
data=data,
62-
x_min=0.0, x_max=100.0, y_min=0.0, y_max=100.0,
63-
n_rows=2, n_cols=2,
71+
x_min=0.0,
72+
x_max=100.0,
73+
y_min=0.0,
74+
y_max=100.0,
75+
n_rows=2,
76+
n_cols=2,
6477
)
6578

6679
stroke_0 = grid.cells[0].strokes[0]
@@ -72,8 +85,12 @@ def test_empty_dataframe(self) -> None:
7285
data = pd.DataFrame(columns=["line_number", "x", "y", "seconds"])
7386
grid = alphabet_utils.segment_strokes(
7487
data=data,
75-
x_min=0.0, x_max=10.0, y_min=0.0, y_max=10.0,
76-
n_rows=1, n_cols=1,
88+
x_min=0.0,
89+
x_max=10.0,
90+
y_min=0.0,
91+
y_max=10.0,
92+
n_rows=1,
93+
n_cols=1,
7794
)
7895

7996
assert all(len(c.strokes) == 0 for c in grid.cells)
@@ -90,8 +107,12 @@ def test_stroke_outside_grid_is_not_assigned(self) -> None:
90107
)
91108
grid = alphabet_utils.segment_strokes(
92109
data=data,
93-
x_min=0.0, x_max=10.0, y_min=0.0, y_max=10.0,
94-
n_rows=1, n_cols=1,
110+
x_min=0.0,
111+
x_max=10.0,
112+
y_min=0.0,
113+
y_max=10.0,
114+
n_rows=1,
115+
n_cols=1,
95116
)
96117

97118
assert len(grid.cells[0].strokes) == 0
@@ -108,8 +129,12 @@ def test_multiple_strokes_in_same_cell(self) -> None:
108129
)
109130
grid = alphabet_utils.segment_strokes(
110131
data=data,
111-
x_min=0.0, x_max=10.0, y_min=0.0, y_max=10.0,
112-
n_rows=1, n_cols=1,
132+
x_min=0.0,
133+
x_max=10.0,
134+
y_min=0.0,
135+
y_max=10.0,
136+
n_rows=1,
137+
n_cols=1,
113138
)
114139

115140
assert len(grid.cells[0].strokes) == 3
@@ -120,8 +145,13 @@ def test_grid_structure_matches_parameters(self) -> None:
120145
labels = ["A", "B", "C", "D", "E", "F"]
121146
grid = alphabet_utils.segment_strokes(
122147
data=data,
123-
x_min=0.0, x_max=100.0, y_min=0.0, y_max=100.0,
124-
n_rows=2, n_cols=3, labels=labels,
148+
x_min=0.0,
149+
x_max=100.0,
150+
y_min=0.0,
151+
y_max=100.0,
152+
n_rows=2,
153+
n_cols=3,
154+
labels=labels,
125155
)
126156

127157
assert len(grid.cells) == 6
@@ -140,8 +170,12 @@ def test_stroke_index_is_reset(self) -> None:
140170
)
141171
grid = alphabet_utils.segment_strokes(
142172
data=data,
143-
x_min=0.0, x_max=10.0, y_min=0.0, y_max=10.0,
144-
n_rows=1, n_cols=1,
173+
x_min=0.0,
174+
x_max=10.0,
175+
y_min=0.0,
176+
y_max=10.0,
177+
n_rows=1,
178+
n_cols=1,
145179
)
146180

147181
stroke = grid.cells[0].strokes[0]

tests/unit/test_grid.py

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,13 @@ def test_labels_assigned(self) -> None:
4848
"""Labels should be assigned in row-major order when provided."""
4949
labels = ["A", "B", "C", "D"]
5050
grid = models.Grid.from_bbox(
51-
x_min=0.0, x_max=10.0, y_min=0.0, y_max=10.0,
52-
n_rows=2, n_cols=2, labels=labels,
51+
x_min=0.0,
52+
x_max=10.0,
53+
y_min=0.0,
54+
y_max=10.0,
55+
n_rows=2,
56+
n_cols=2,
57+
labels=labels,
5358
)
5459

5560
assert [c.label for c in grid.cells] == ["A", "B", "C", "D"]
@@ -66,8 +71,13 @@ def test_labels_length_mismatch_raises(self) -> None:
6671
"""Providing the wrong number of labels should raise ValueError."""
6772
with pytest.raises(ValueError, match="labels length"):
6873
models.Grid.from_bbox(
69-
x_min=0.0, x_max=10.0, y_min=0.0, y_max=10.0,
70-
n_rows=2, n_cols=2, labels=["A", "B"],
74+
x_min=0.0,
75+
x_max=10.0,
76+
y_min=0.0,
77+
y_max=10.0,
78+
n_rows=2,
79+
n_cols=2,
80+
labels=["A", "B"],
7181
)
7282

7383
@pytest.mark.parametrize(
@@ -79,15 +89,24 @@ def test_invalid_dimensions_raise(self, n_rows: int, n_cols: int) -> None:
7989
"""Non-positive row or column counts should raise ValueError."""
8090
with pytest.raises(ValueError, match="n_rows and n_cols must be at least 1"):
8191
models.Grid.from_bbox(
82-
x_min=0.0, x_max=10.0, y_min=0.0, y_max=10.0,
83-
n_rows=n_rows, n_cols=n_cols,
92+
x_min=0.0,
93+
x_max=10.0,
94+
y_min=0.0,
95+
y_max=10.0,
96+
n_rows=n_rows,
97+
n_cols=n_cols,
8498
)
8599

86100
def test_custom_padding(self) -> None:
87101
"""Custom padding should extend the outer boundaries accordingly."""
88102
grid = models.Grid.from_bbox(
89-
x_min=0.0, x_max=10.0, y_min=0.0, y_max=10.0,
90-
n_rows=1, n_cols=1, padding=1.0,
103+
x_min=0.0,
104+
x_max=10.0,
105+
y_min=0.0,
106+
y_max=10.0,
107+
n_rows=1,
108+
n_cols=1,
109+
padding=1.0,
91110
)
92111

93112
cell = grid.cells[0]
@@ -124,8 +143,13 @@ class TestGetCellForPoint:
124143
def grid_2x2(self) -> models.Grid:
125144
"""Create a 2x2 grid over the unit square with labels."""
126145
return models.Grid.from_bbox(
127-
x_min=0.0, x_max=10.0, y_min=0.0, y_max=10.0,
128-
n_rows=2, n_cols=2, labels=["TL", "TR", "BL", "BR"],
146+
x_min=0.0,
147+
x_max=10.0,
148+
y_min=0.0,
149+
y_max=10.0,
150+
n_rows=2,
151+
n_cols=2,
152+
labels=["TL", "TR", "BL", "BR"],
129153
)
130154

131155
def test_point_in_top_left(self, grid_2x2: models.Grid) -> None:

0 commit comments

Comments
 (0)