diff --git a/tests/encryption_algorithms/test_common.py b/tests/encryption_algorithms/test_common.py index 4912308..e6b5441 100644 --- a/tests/encryption_algorithms/test_common.py +++ b/tests/encryption_algorithms/test_common.py @@ -5,6 +5,6 @@ @pytest.mark.parametrize("in_signature_params", utils.SOME_SIGNATURE_PARAMS) -def test_digest_size(in_signature_params): +def test_digest_size(in_signature_params: dict[str, str]) -> None: some_hash = eac.sign_bytes(b"some_msg", b"some_key", in_signature_params) assert eac.digest_size(in_signature_params) == len(some_hash) diff --git a/tests/encryption_algorithms/test_encryption_algorithms.py b/tests/encryption_algorithms/test_encryption_algorithms.py index ce7fbfd..594c967 100644 --- a/tests/encryption_algorithms/test_encryption_algorithms.py +++ b/tests/encryption_algorithms/test_encryption_algorithms.py @@ -1,3 +1,4 @@ +import typing import pytest from .. import utils @@ -6,7 +7,12 @@ @pytest.mark.parametrize("in_bytes", utils.BYTES_LIST) @pytest.mark.parametrize("in_pass", utils.BYTES_LIST) @pytest.mark.parametrize(("encrypt", "decrypt"), utils.ENCRYPT_DECRYPT_PAIRS) -def test_encryption_decryption(in_bytes, in_pass, encrypt, decrypt): +def test_encryption_decryption( + in_bytes: bytes, + in_pass: bytes, + encrypt: typing.Callable[[bytes, bytes], bytes], + decrypt: typing.Callable[[bytes, bytes], bytes | None], +) -> None: encrypted = encrypt(in_bytes, in_pass) assert encrypted != in_bytes diff --git a/tests/test_bytes_utils.py b/tests/test_bytes_utils.py index 24aa0b0..03ea87d 100644 --- a/tests/test_bytes_utils.py +++ b/tests/test_bytes_utils.py @@ -20,11 +20,11 @@ (2 ** (8 * 255), 256), ], ) -def test_byte_length(in_value, expected): +def test_byte_length(in_value: int, expected: int) -> None: assert bu.byte_length(in_value) == expected -def test_byte_length_raises_for_negative_input(): +def test_byte_length_raises_for_negative_input() -> None: with pytest.raises(ValueError, match="in_value must be non-negative"): bu.byte_length(-1) @@ -32,11 +32,11 @@ def test_byte_length_raises_for_negative_input(): @pytest.mark.parametrize( "in_value", [0, 1, 2, 3, 255, 256, 257, 3239949409384, 10**570, 2 ** (8 * 255) - 1] ) -def test_int_to_bytes(in_value): +def test_int_to_bytes(in_value: int) -> None: assert bu.bytes_to_int(bu.int_to_bytes(in_value)) == in_value -def test_int_to_bytes_raises_when_input_is_too_big(): +def test_int_to_bytes_raises_when_input_is_too_big() -> None: with pytest.raises(ValueError, match="in_value must be 255 bytes or less"): bu.int_to_bytes(2 ** (8 * 255)) @@ -44,7 +44,7 @@ def test_int_to_bytes_raises_when_input_is_too_big(): @pytest.mark.parametrize( ("in_str", "in_bytes"), itertools.product(utils.STRS, utils.BYTES_LIST) ) -def test_split_and_join(in_str, in_bytes): +def test_split_and_join(in_str: str, in_bytes: bytes) -> None: res_str, res_bytes = bu.split(bu.join(in_str, in_bytes)) assert res_str == in_str assert res_bytes == in_bytes diff --git a/tests/test_bytestr.py b/tests/test_bytestr.py index ee38e63..2c27b48 100644 --- a/tests/test_bytestr.py +++ b/tests/test_bytestr.py @@ -8,7 +8,7 @@ "in_bytes", utils.BYTES_LIST, ) -def test_bytes_to_bytestr(in_bytes): +def test_bytes_to_bytestr(in_bytes: bytes) -> None: bytestr = bu.bytes_to_bytestr(in_bytes) assert isinstance(bytestr, str) assert bu.bytestr_to_bytes(bytestr) == in_bytes diff --git a/tests/test_configurators.py b/tests/test_configurators.py index 3697db0..6a24ace 100644 --- a/tests/test_configurators.py +++ b/tests/test_configurators.py @@ -5,6 +5,6 @@ @pytest.mark.parametrize("configurator", [simple.Simple, spiced.Spiced]) -def test_configurators_raise_when_invalid_args(configurator): +def test_configurators_raise_when_invalid_args(configurator) -> None: with pytest.raises(TypeError): configurator(wrong_param=10) diff --git a/tests/test_create_puzzle.py b/tests/test_create_puzzle.py index 3e92d10..dcde624 100644 --- a/tests/test_create_puzzle.py +++ b/tests/test_create_puzzle.py @@ -24,7 +24,7 @@ @pytest.fixture(name="puzzle_tc") -def fixture_puzzle_tc(): +def fixture_puzzle_tc() -> _PuzzleTestCase: qa_list = [ "Question 1?", "Answer 1", @@ -157,7 +157,12 @@ def _input_simulator() -> str: @pytest.mark.parametrize(("encrypt", "decrypt"), utils.ENCRYPT_DECRYPT_PAIRS) -def test_run_puzzle_all_good_answers(capsys, puzzle_tc, encrypt, decrypt) -> None: +def test_run_puzzle_all_good_answers( + capsys, + puzzle_tc, + encrypt: typing.Callable[[bytes, bytes], bytes], + decrypt: typing.Callable[[bytes, bytes], bytes | None], +) -> None: encrypted_puzzle = pde.encrypt_data( cp.question_answer_list_to_dict(puzzle_tc.qa_list), encrypt ) @@ -224,7 +229,7 @@ def test_run_puzzle_wrong_answers(capsys, puzzle_tc, encrypt, decrypt) -> None: ), ], ) -def test_question_answer_list_to_dict(qa_list, expected): +def test_question_answer_list_to_dict(qa_list: list[str], expected) -> None: assert cp.question_answer_list_to_dict(qa_list) == expected @@ -237,8 +242,8 @@ def test_question_answer_list_to_dict(qa_list, expected): ], ) def test_question_answer_list_to_dict_raises_when_input_list_has_even_length( - wrong_qa_list, -): + wrong_qa_list: list[str], +) -> None: with pytest.raises( ValueError, match="The question/answer list must have odd length." ): diff --git a/tests/test_puzzle_data_encryption.py b/tests/test_puzzle_data_encryption.py index 8a39593..6070e3e 100644 --- a/tests/test_puzzle_data_encryption.py +++ b/tests/test_puzzle_data_encryption.py @@ -1,9 +1,24 @@ +import typing import pytest import puzzle_generator.puzzle_data_encryption as pde from . import utils +def _decrypt_data( + puzzle_bytes: bytes, + cur_pass: str, + decrypt: typing.Callable[[bytes, bytes], bytes | None], +) -> tuple[str, bytes]: + res = pde.decrypt_data( + puzzle_bytes, + cur_pass, + decrypt, + ) + assert res is not None + return res + + @pytest.mark.parametrize( "in_puzzle", [ @@ -47,7 +62,11 @@ ], ) @pytest.mark.parametrize(("encrypt", "decrypt"), utils.ENCRYPT_DECRYPT_PAIRS) -def test_pde(in_puzzle, encrypt, decrypt): +def test_pde( + in_puzzle, + encrypt: typing.Callable[[bytes, bytes], bytes], + decrypt: typing.Callable[[bytes, bytes], bytes | None], +) -> None: encrypted_puzzle = pde.encrypt_data(in_puzzle, encrypt) tmp_puzzle_data = in_puzzle while len(encrypted_puzzle[1]) > 0: @@ -61,7 +80,7 @@ def test_pde(in_puzzle, encrypt, decrypt): ) is None ) - encrypted_puzzle = pde.decrypt_data( + encrypted_puzzle = _decrypt_data( encrypted_puzzle[1], cur_pass, decrypt, diff --git a/tests/utils.py b/tests/utils.py index ad3e76e..7ed3d5d 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -1,5 +1,6 @@ import string import itertools +import typing import puzzle_generator.encryption_algorithms.simple.simple as se import puzzle_generator.encryption_algorithms.simple.spiced as sse @@ -40,11 +41,21 @@ SOME_SIGNATURE_PARAMS = [{"digest": _} for _ in _SOME_HASHES] -def _get_simple_encrypt_decrypt_pair(*args): +def _get_simple_encrypt_decrypt_pair( + *args, +) -> typing.Tuple[ + typing.Callable[[bytes, bytes], bytes], + typing.Callable[[bytes, bytes], bytes | None], +]: return se.get_encrypt(*args), se.get_decrypt(*args) -def _get_spiced_simple_encrypt_decrypt_pair(*args): +def _get_spiced_simple_encrypt_decrypt_pair( + *args, +) -> typing.Tuple[ + typing.Callable[[bytes, bytes], bytes], + typing.Callable[[bytes, bytes], bytes | None], +]: return sse.get_encrypt(*args), sse.get_decrypt(*args)