Skip to content

Commit 2f96373

Browse files
committed
Fix various linting and style checks
- Functions names must be lowercase. - Needless `else` after `return`. - Invalid module name for tests file.
1 parent e2e626b commit 2f96373

File tree

3 files changed

+228
-64
lines changed

3 files changed

+228
-64
lines changed

barcode/codex.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
:Provided barcodes: Code 39, Code 128, PZN
44
"""
5+
56
from __future__ import annotations
67

78
from typing import TYPE_CHECKING
@@ -176,14 +177,18 @@ def _new_charset(self, which: Literal["A", "B", "C"]) -> list[int]:
176177
return [code]
177178

178179
# to be redefined in subclass if required
179-
def _is_char_FNC1_CHAR(self, char):
180-
# FNC1 char is defined in GS1-128 specification and it is defined just the same for all encodings
181-
# therefore this sing should be treated in a special way.
180+
def _is_char_fnc1_char(self, char):
181+
"""Whether a character is the FNC1 character.
182+
183+
May be redefined by subclasses if required. FNC1 char is defined in GS1-128
184+
specification and it is defined just the same for all encodings therefore this
185+
sign should be treated in a special way.
186+
"""
182187
return False
183188

184189
def _maybe_switch_charset(self, pos: int) -> list[int]:
185190
char = self.code[pos]
186-
next_ = self.code[pos: pos + 10]
191+
next_ = self.code[pos : pos + 10]
187192

188193
def look_next() -> bool:
189194
digits = 0
@@ -196,16 +201,15 @@ def look_next() -> bool:
196201

197202
codes: list[int] = []
198203
if self._charset == "C" and not char.isdigit():
199-
if self._is_char_FNC1_CHAR(char) and not self._buffer:
204+
if self._is_char_fnc1_char(char) and not self._buffer:
200205
return codes
201-
else:
202-
if char in code128.B:
203-
codes = self._new_charset("B")
204-
elif char in code128.A:
205-
codes = self._new_charset("A")
206-
if len(self._buffer) == 1:
207-
codes.append(self._convert(self._buffer[0]))
208-
self._buffer = ""
206+
if char in code128.B:
207+
codes = self._new_charset("B")
208+
elif char in code128.A:
209+
codes = self._new_charset("A")
210+
if len(self._buffer) == 1:
211+
codes.append(self._convert(self._buffer[0]))
212+
self._buffer = ""
209213
elif self._charset == "B":
210214
if look_next():
211215
codes = self._new_charset("C")
@@ -297,7 +301,7 @@ def __init__(self, code, writer=None) -> None:
297301
def get_fullcode(self):
298302
return super().get_fullcode()[1:]
299303

300-
def _is_char_FNC1_CHAR(self, char):
304+
def _is_char_fnc1_char(self, char):
301305
return char == self.FNC1_CHAR
302306

303307

tests/test_Gs1_128.py

Lines changed: 0 additions & 50 deletions
This file was deleted.

tests/test_gs1_128.py

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
from __future__ import annotations
2+
3+
import pytest
4+
5+
from barcode.codex import Gs1_128
6+
7+
FNC1_CHAR = "\xf1"
8+
FNC1 = 102
9+
START_B = 104
10+
START_C = 105
11+
FROM_AC_TO_B = 100
12+
FROM_AB_TO_C = 99
13+
FROM_BC_TO_A = 101
14+
CODE_BUILD_TEST = (
15+
# '(01)01234567891011(11)200622(17)240622(21)88888888' # noqa: ERA001
16+
(
17+
"010123456789101111200622172406222188888888",
18+
[
19+
START_C,
20+
FNC1,
21+
1,
22+
1,
23+
23,
24+
45,
25+
67,
26+
89,
27+
10,
28+
11,
29+
11,
30+
20,
31+
6,
32+
22,
33+
17,
34+
24,
35+
6,
36+
22,
37+
21,
38+
88,
39+
88,
40+
88,
41+
88,
42+
],
43+
),
44+
# '(01)01234567891011(11)200622(17)240622(21)888888888' # noqa: ERA001
45+
(
46+
"0101234567891011112006221724062221888888888",
47+
[
48+
START_C,
49+
FNC1,
50+
1,
51+
1,
52+
23,
53+
45,
54+
67,
55+
89,
56+
10,
57+
11,
58+
11,
59+
20,
60+
6,
61+
22,
62+
17,
63+
24,
64+
6,
65+
22,
66+
21,
67+
88,
68+
88,
69+
88,
70+
88,
71+
100,
72+
24,
73+
],
74+
),
75+
# '(01)01234567891011(11)200622(10)12345(21)1234' # noqa: ERA001
76+
(
77+
"0101234567891011112006221012345" + FNC1_CHAR + "211234",
78+
[
79+
START_C,
80+
FNC1,
81+
1,
82+
1,
83+
23,
84+
45,
85+
67,
86+
89,
87+
10,
88+
11,
89+
11,
90+
20,
91+
6,
92+
22,
93+
10,
94+
12,
95+
34,
96+
FROM_AC_TO_B,
97+
21,
98+
FNC1,
99+
FROM_AB_TO_C,
100+
21,
101+
12,
102+
34,
103+
],
104+
),
105+
# '(01)01234567891011(11)200622(10)1234(21)1234' # noqa: ERA001
106+
(
107+
"010123456789101111200622101234" + FNC1_CHAR + "211234",
108+
[
109+
START_C,
110+
FNC1,
111+
1,
112+
1,
113+
23,
114+
45,
115+
67,
116+
89,
117+
10,
118+
11,
119+
11,
120+
20,
121+
6,
122+
22,
123+
10,
124+
12,
125+
34,
126+
FNC1,
127+
21,
128+
12,
129+
34,
130+
],
131+
),
132+
# '(01)01234567891011(11)200622(10)240622(21)888888888' # noqa: ERA001
133+
(
134+
"01012345678910111120062210240622" + FNC1_CHAR + "21888888888",
135+
[
136+
START_C,
137+
FNC1,
138+
1,
139+
1,
140+
23,
141+
45,
142+
67,
143+
89,
144+
10,
145+
11,
146+
11,
147+
20,
148+
6,
149+
22,
150+
10,
151+
24,
152+
6,
153+
22,
154+
FNC1,
155+
21,
156+
88,
157+
88,
158+
88,
159+
88,
160+
100,
161+
24,
162+
],
163+
),
164+
# '(01)08720299927469(11)240621(17)250621(10)20240621/0001(21)xyz' # noqa: ERA001
165+
(
166+
"010872029992746911240621172506211020240621/0001" + FNC1_CHAR + "21xyz",
167+
[
168+
105,
169+
102,
170+
1,
171+
8,
172+
72,
173+
2,
174+
99,
175+
92,
176+
74,
177+
69,
178+
11,
179+
24,
180+
6,
181+
21,
182+
17,
183+
25,
184+
6,
185+
21,
186+
10,
187+
20,
188+
24,
189+
6,
190+
21,
191+
100,
192+
15,
193+
99,
194+
0,
195+
1,
196+
102,
197+
21,
198+
100,
199+
88,
200+
89,
201+
90,
202+
],
203+
),
204+
)
205+
206+
207+
@pytest.mark.parametrize(("target", "answer"), CODE_BUILD_TEST)
208+
def test_code_build(target, answer):
209+
gs1_128 = Gs1_128(target)
210+
assert gs1_128._build() == answer

0 commit comments

Comments
 (0)