Skip to content

Commit fef2d18

Browse files
Merge pull request #152 from SuffolkLITLab/mypy-fixes
Typing and unit test fixes
2 parents 44a1773 + e057983 commit fef2d18

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

formfyxer/pdf_wrangling.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class FieldType(Enum):
5353
CHOICE = "choice" # allows only one selection
5454
RADIO = "radio"
5555

56-
def __str__(self):
56+
def __str__(self) -> str:
5757
return self.value
5858

5959

@@ -131,7 +131,7 @@ def __init__(
131131
self.configs.update(configs)
132132

133133
@classmethod
134-
def make_textbox(cls, label: str, field_bbox: BoundingBox, font_size):
134+
def make_textbox(cls, label: str, field_bbox: BoundingBox, font_size: int) -> "FormField":
135135
return FormField(
136136
label,
137137
FieldType.TEXT,
@@ -142,7 +142,7 @@ def make_textbox(cls, label: str, field_bbox: BoundingBox, font_size):
142142
)
143143

144144
@classmethod
145-
def make_textarea(cls, label: str, field_bbox: BoundingBox, font_size):
145+
def make_textarea(cls, label: str, field_bbox: BoundingBox, font_size: int) -> "FormField":
146146
return FormField(
147147
label,
148148
FieldType.AREA,
@@ -153,7 +153,7 @@ def make_textarea(cls, label: str, field_bbox: BoundingBox, font_size):
153153
)
154154

155155
@classmethod
156-
def make_checkbox(cls, label: str, bbox: BoundingBox):
156+
def make_checkbox(cls, label: str, bbox: BoundingBox) -> "FormField":
157157
return FormField(
158158
label,
159159
FieldType.CHECK_BOX,
@@ -163,7 +163,7 @@ def make_checkbox(cls, label: str, bbox: BoundingBox):
163163
)
164164

165165
@classmethod
166-
def from_pikefield(cls, pike_field: PikeField):
166+
def from_pikefield(cls, pike_field: PikeField) -> "FormField":
167167
if pike_field["type"] == "/Tx":
168168
var_type = FieldType.TEXT
169169
elif pike_field["type"] == "/Btn":
@@ -174,10 +174,10 @@ def from_pikefield(cls, pike_field: PikeField):
174174
var_type = FieldType.TEXT
175175

176176
if hasattr(pike_field["all"], "Rect"):
177-
x = float(pike_field["all"].Rect[0]) # type: ignore
178-
y = float(pike_field["all"].Rect[1]) # type: ignore
179-
width = float(pike_field["all"].Rect[2]) - x # type: ignore
180-
height = float(pike_field["all"].Rect[3]) - y # type: ignore
177+
x = float(pike_field["all"].Rect[0])
178+
y = float(pike_field["all"].Rect[1])
179+
width = float(pike_field["all"].Rect[2]) - x
180+
height = float(pike_field["all"].Rect[3]) - y
181181
else:
182182
x = 0
183183
y = 0
@@ -1134,8 +1134,12 @@ def get_possible_radios(img: Union[str, BinaryIO, cv2.Mat]):
11341134
if isinstance(img, str):
11351135
# 0 is for the flags: means nothing special is being used
11361136
img_mat = cv2.imread(img, 0)
1137+
if img_mat is None:
1138+
return []
11371139
elif isinstance(img, BinaryIO):
11381140
img_mat = cv2.imdecode(np.frombuffer(img.read(), np.uint8), 0)
1141+
if img_mat is None:
1142+
return []
11391143
else:
11401144
img_mat = img
11411145

@@ -1184,8 +1188,12 @@ def get_possible_text_fields(
11841188
if isinstance(img, str):
11851189
# 0 is for the flags: means nothing special is being used
11861190
img_mat = cv2.imread(img, 0)
1191+
if img_mat is None:
1192+
return []
11871193
elif isinstance(img, BinaryIO):
11881194
img_mat = cv2.imdecode(np.frombuffer(img.read(), np.uint8), 0)
1195+
if img_mat is None:
1196+
return []
11891197
else:
11901198
img_mat = img
11911199

formfyxer/tests/test_lit_explorer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def setUp(self) -> None:
134134
def test_calls_spot(self, mock_post):
135135
text = "The quick brown fox jumps over the lazy dog."
136136
self.request_args["data"]["text"] = text
137-
spot(text)
137+
spot(text, token="your_SPOT_API_token goes here")
138138
mock_post.assert_called_with(
139139
self.request_args["url"],
140140
headers=self.request_args["headers"],
@@ -146,7 +146,7 @@ def test_calls_spot_with_reduced_character_count(self, mock_post):
146146
text = "a" * 5001
147147
reduced_text = "a" * 5000
148148
self.request_args["data"]["text"] = reduced_text
149-
spot(text)
149+
spot(text, token="your_SPOT_API_token goes here")
150150
mock_post.assert_called_with(
151151
self.request_args["url"],
152152
headers=self.request_args["headers"],

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ extend-exclude = '(__init__.py|setup.py)'
88
[tool.mypy]
99
exclude= '''(?x)(
1010
^setup.py$
11+
| ^test_.*\.py$
12+
| ^.*/tests/.*\.py$
1113
)'''
1214

1315
[[tool.mypy.overrides]]

0 commit comments

Comments
 (0)