Skip to content

Commit aba1992

Browse files
Merge pull request #2466 from VWS-Python/no-asserts
Only allow asserts in tests
2 parents 575909b + 90a5743 commit aba1992

File tree

7 files changed

+19
-8
lines changed

7 files changed

+19
-8
lines changed

admin/create_secrets_files.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ def main() -> None:
3434
existing_secrets_file = Path(
3535
os.environ["EXISTING_SECRETS_FILE"]
3636
).expanduser()
37-
assert existing_secrets_file.exists(), existing_secrets_file
37+
if not existing_secrets_file.exists():
38+
msg = f"Existing secrets file does not exist: {existing_secrets_file}"
39+
raise FileNotFoundError(msg)
3840
load_dotenv(dotenv_path=existing_secrets_file)
3941
new_secrets_dir.mkdir(exist_ok=True)
4042

docs/source/conf.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@
5050
requires_python = project_metadata["Requires-Python"]
5151
specifiers = SpecifierSet(specifiers=requires_python)
5252
(specifier,) = specifiers
53-
assert specifier.operator == ">="
53+
if specifier.operator != ">=":
54+
msg = (
55+
f"We only support '>=' for Requires-Python, got {specifier.operator}."
56+
)
57+
raise ValueError(msg)
5458
minimum_python_version = specifier.version
5559

5660
language = "en"

pyproject.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,17 @@ lint.ignore = [
165165
# Also, allow 'assert' in other code as it is the standard for Python type hint
166166
# narrowing - see
167167
# https://mypy.readthedocs.io/en/stable/type_narrowing.html#type-narrowing-expressions.
168+
# "S101",
169+
]
170+
171+
lint.per-file-ignores."ci/test_custom_linters.py" = [
172+
# Allow asserts in tests.
168173
"S101",
169174
]
170175

171176
lint.per-file-ignores."tests/**" = [
177+
# Allow asserts in tests.
178+
"S101",
172179
# Allow possible hardcoded passwords in tests.
173180
"S105",
174181
"S106",

src/mock_vws/_requests_mock_server/decorators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def __exit__(self, *exc: object) -> Literal[False]:
192192
"""
193193
# __exit__ needs this to be passed in but vulture thinks that it is
194194
# unused, so we "use" it here.
195-
assert isinstance(exc, tuple)
195+
del exc
196196

197197
self._mock.stop()
198198
return False

src/mock_vws/_requests_mock_server/mock_web_query_api.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,9 @@ def _body_bytes(request: PreparedRequest) -> bytes:
6969
"""
7070
Return the body of a request as bytes.
7171
"""
72-
if request.body is None:
72+
if request.body is None or isinstance(request.body, str):
7373
return b""
7474

75-
assert isinstance(request.body, bytes)
7675
return request.body
7776

7877

src/mock_vws/_requests_mock_server/mock_web_services_api.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ def _body_bytes(request: PreparedRequest) -> bytes:
9090
if isinstance(request.body, str):
9191
return request.body.encode(encoding="utf-8")
9292

93-
assert isinstance(request.body, bytes)
9493
return request.body
9594

9695

src/mock_vws/target_raters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def __call__(self, image_content: bytes) -> int:
7373
Args:
7474
image_content: A target's image's content.
7575
"""
76-
assert image_content
76+
del image_content
7777
return secrets.randbelow(exclusive_upper_bound=6)
7878

7979

@@ -96,7 +96,7 @@ def __call__(self, image_content: bytes) -> int:
9696
Args:
9797
image_content: A target's image's content.
9898
"""
99-
assert image_content
99+
del image_content
100100
return self._rating
101101

102102

0 commit comments

Comments
 (0)