Skip to content

Only allow asserts in tests #2466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion admin/create_secrets_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def main() -> None:
existing_secrets_file = Path(
os.environ["EXISTING_SECRETS_FILE"]
).expanduser()
assert existing_secrets_file.exists(), existing_secrets_file
if not existing_secrets_file.exists():
msg = f"Existing secrets file does not exist: {existing_secrets_file}"
raise FileNotFoundError(msg)
load_dotenv(dotenv_path=existing_secrets_file)
new_secrets_dir.mkdir(exist_ok=True)

Expand Down
6 changes: 5 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@
requires_python = project_metadata["Requires-Python"]
specifiers = SpecifierSet(specifiers=requires_python)
(specifier,) = specifiers
assert specifier.operator == ">="
if specifier.operator != ">=":
msg = (
f"We only support '>=' for Requires-Python, got {specifier.operator}."
)
raise ValueError(msg)
minimum_python_version = specifier.version

language = "en"
Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,17 @@ lint.ignore = [
# Also, allow 'assert' in other code as it is the standard for Python type hint
# narrowing - see
# https://mypy.readthedocs.io/en/stable/type_narrowing.html#type-narrowing-expressions.
# "S101",
]

lint.per-file-ignores."ci/test_custom_linters.py" = [
# Allow asserts in tests.
"S101",
]

lint.per-file-ignores."tests/**" = [
# Allow asserts in tests.
"S101",
# Allow possible hardcoded passwords in tests.
"S105",
"S106",
Expand Down
2 changes: 1 addition & 1 deletion src/mock_vws/_requests_mock_server/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def __exit__(self, *exc: object) -> Literal[False]:
"""
# __exit__ needs this to be passed in but vulture thinks that it is
# unused, so we "use" it here.
assert isinstance(exc, tuple)
del exc

self._mock.stop()
return False
3 changes: 1 addition & 2 deletions src/mock_vws/_requests_mock_server/mock_web_query_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,9 @@ def _body_bytes(request: PreparedRequest) -> bytes:
"""
Return the body of a request as bytes.
"""
if request.body is None:
if request.body is None or isinstance(request.body, str):
return b""

assert isinstance(request.body, bytes)
return request.body


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ def _body_bytes(request: PreparedRequest) -> bytes:
if isinstance(request.body, str):
return request.body.encode(encoding="utf-8")

assert isinstance(request.body, bytes)
return request.body


Expand Down
4 changes: 2 additions & 2 deletions src/mock_vws/target_raters.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
Args:
image_content: A target's image's content.
"""
assert image_content
del image_content

Check warning on line 76 in src/mock_vws/target_raters.py

View check run for this annotation

Codecov / codecov/patch

src/mock_vws/target_raters.py#L76

Added line #L76 was not covered by tests
return secrets.randbelow(exclusive_upper_bound=6)


Expand All @@ -96,7 +96,7 @@
Args:
image_content: A target's image's content.
"""
assert image_content
del image_content

Check warning on line 99 in src/mock_vws/target_raters.py

View check run for this annotation

Codecov / codecov/patch

src/mock_vws/target_raters.py#L99

Added line #L99 was not covered by tests
return self._rating


Expand Down
Loading