From 4cd7dc93d6d93f255b12d8c1559861f5e0fe08ab Mon Sep 17 00:00:00 2001 From: Dhwani Patel Date: Tue, 8 Oct 2024 10:16:27 -0600 Subject: [PATCH] Add the suggestions --- .pre-commit-config.yaml | 2 +- pyproject.toml | 2 +- tests/test_fixity.py | 58 +++++++++++++++++++---------------------- 3 files changed, 29 insertions(+), 33 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 94e71a1..024d3ad 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -22,7 +22,7 @@ repos: (README)\.md ) - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.10.1 + rev: v1.11.2 hooks: - id: mypy additional_dependencies: diff --git a/pyproject.toml b/pyproject.toml index 7b95ae1..90c78f4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -143,4 +143,4 @@ module = [ "tests.test_fixity", ] ignore_errors = false -disallow_untyped_calls = false \ No newline at end of file + diff --git a/tests/test_fixity.py b/tests/test_fixity.py index 2e8b09b..cbba293 100644 --- a/tests/test_fixity.py +++ b/tests/test_fixity.py @@ -1,10 +1,10 @@ import io import json -import typing import uuid from datetime import datetime from datetime import timezone from typing import List +from typing import TextIO from unittest import mock import pytest @@ -56,20 +56,20 @@ def mock_check_fixity() -> List[mock.Mock]: ] -def _assert_stream_content_matches(stream: typing.TextIO, expected: List[str]) -> None: +def _assert_stream_content_matches(stream: TextIO, expected: List[str]) -> None: stream.seek(0) assert [line.strip() for line in stream.readlines()] == expected @mock.patch("requests.get") def test_scan( - _get: mock.Mock, environment: mock.Mock, mock_check_fixity: mock.Mock + _get: mock.Mock, environment: None, mock_check_fixity: List[mock.Mock] ) -> None: _get.side_effect = mock_check_fixity aip_id = uuid.uuid4() stream = io.StringIO() - response = fixity.main(["scan", str(aip_id)], stream=stream) + response = fixity.main(["scan", str(aip_id)], stream=stream) # type: ignore assert response == 0 @@ -92,8 +92,8 @@ def test_scan( def test_scan_if_timestamps_argument_is_passed( _get: mock.Mock, time: mock.Mock, - environment: pytest.MonkeyPatch, - mock_check_fixity: mock.Mock, + environment: None, + mock_check_fixity: List[mock.Mock], ) -> None: _get.side_effect = mock_check_fixity aip_id = uuid.uuid4() @@ -101,7 +101,7 @@ def test_scan_if_timestamps_argument_is_passed( time.return_value = timestamp stream = io.StringIO() - response = fixity.main(["scan", str(aip_id), "--timestamps"], stream=stream) + response = fixity.main(["scan", str(aip_id), "--timestamps"], stream=stream) # type: ignore assert response == 0 @@ -137,8 +137,8 @@ def test_scan_if_report_url_exists( _get: mock.Mock, utcnow: mock.Mock, uuid4: mock.Mock, - mock_check_fixity: mock.Mock, - environment: pytest.MonkeyPatch, + mock_check_fixity: List[mock.Mock], + environment: None, monkeypatch: pytest.MonkeyPatch, ) -> None: uuid4.return_value = expected_uuid = uuid.uuid4() @@ -149,7 +149,7 @@ def test_scan_if_report_url_exists( aip_id = uuid.uuid4() stream = io.StringIO() - response = fixity.main(["scan", str(aip_id)], stream=stream) + response = fixity.main(["scan", str(aip_id)], stream=stream) # type: ignore assert response == 0 @@ -212,16 +212,16 @@ def test_scan_if_report_url_exists( def test_scan_handles_exceptions_if_report_url_exists( _post: mock.Mock, _get: mock.Mock, - environment: pytest.MonkeyPatch, + environment: None, monkeypatch: pytest.MonkeyPatch, - mock_check_fixity: mock.Mock, + mock_check_fixity: List[mock.Mock], ) -> None: _get.side_effect = mock_check_fixity aip_id = uuid.uuid4() stream = io.StringIO() monkeypatch.setenv("REPORT_URL", REPORT_URL) - response = fixity.main(["scan", str(aip_id)], stream=stream) + response = fixity.main(["scan", str(aip_id)], stream=stream) # type: ignore assert response == 0 @@ -254,13 +254,11 @@ def test_scan_handles_exceptions_if_report_url_exists( ), ], ) -def test_scan_handles_exceptions( - _get: mock.Mock, environment: pytest.MonkeyPatch -) -> None: +def test_scan_handles_exceptions(_get: mock.Mock, environment: None) -> None: aip_id = uuid.uuid4() stream = io.StringIO() - response = fixity.main(["scan", str(aip_id)], stream=stream) + response = fixity.main(["scan", str(aip_id)], stream=stream) # type: ignore assert response is None @@ -292,11 +290,11 @@ def test_scan_handles_exceptions( ], ) def test_scan_handles_exceptions_if_no_scan_attempted( - _get: mock.Mock, environment: pytest.MonkeyPatch + _get: mock.Mock, environment: None ) -> None: aip_id = uuid.uuid4() - response = fixity.main(["scan", str(aip_id)]) + response = fixity.main(["scan", str(aip_id)]) # type: ignore assert response is None @@ -312,12 +310,12 @@ def test_scan_handles_exceptions_if_no_scan_attempted( ], ids=["Success", "Fail", "Did not run"], ) -def test_scan_message(status: mock.Mock, error_message: mock.Mock) -> None: +def test_scan_message(status: bool, error_message: str) -> None: aip_id = uuid.uuid4() response = fixity.scan_message( aip_uuid=aip_id, status=status, message=error_message - ) + ) # type: ignore assert ( response == f"Fixity scan {error_message} for AIP: {aip_id} ({error_message})" @@ -328,7 +326,7 @@ def test_scan_message(status: mock.Mock, error_message: mock.Mock) -> None: "requests.get", ) def test_scanall( - _get: mock.Mock, environment: pytest.MonkeyPatch, mock_check_fixity: mock.Mock + _get: mock.Mock, environment: None, mock_check_fixity: List[mock.Mock] ) -> None: aip1_uuid = str(uuid.uuid4()) aip2_uuid = str(uuid.uuid4()) @@ -359,7 +357,7 @@ def test_scanall( ] stream = io.StringIO() - response = fixity.main(["scanall"], stream=stream) + response = fixity.main(["scanall"], stream=stream) # type: ignore assert response == 0 @@ -374,9 +372,7 @@ def test_scanall( @mock.patch("requests.get") -def test_scanall_handles_exceptions( - _get: mock.Mock, environment: pytest.MonkeyPatch -) -> None: +def test_scanall_handles_exceptions(_get: mock.Mock, environment: None) -> None: aip_id1 = str(uuid.uuid4()) aip_id2 = str(uuid.uuid4()) _get.side_effect = [ @@ -422,7 +418,7 @@ def test_scanall_handles_exceptions( ] stream = io.StringIO() - response = fixity.main(["scanall"], stream=stream) + response = fixity.main(["scanall"], stream=stream) # type: ignore assert response == 1 @@ -438,7 +434,7 @@ def test_scanall_handles_exceptions( @mock.patch("requests.get") def test_main_handles_exceptions_if_scanall_fails( - _get: mock.Mock, environment: pytest.MonkeyPatch + _get: mock.Mock, environment: None ) -> None: aip_id1 = str(uuid.uuid4()) aip_id2 = str(uuid.uuid4()) @@ -485,7 +481,7 @@ def test_main_handles_exceptions_if_scanall_fails( ] stream = io.StringIO() - result = fixity.main(["scanall"], stream=stream) + result = fixity.main(["scanall"], stream=stream) # type: ignore assert result == 1 @@ -501,7 +497,7 @@ def test_main_handles_exceptions_if_scanall_fails( @mock.patch("requests.get") def test_scanall_if_sort_argument_is_passed( - _get: mock.Mock, environment: pytest.MonkeyPatch, mock_check_fixity: mock.Mock + _get: mock.Mock, environment: None, mock_check_fixity: List[mock.Mock] ) -> None: aip1_uuid = str(uuid.uuid4()) aip2_uuid = str(uuid.uuid4()) @@ -587,7 +583,7 @@ def test_scanall_if_sort_argument_is_passed( stream = io.StringIO() - response = fixity.main(["scanall", "--sort"], stream=stream) + response = fixity.main(["scanall", "--sort"], stream=stream) # type: ignore assert response == 1