eea542a5c4507c46f795152b3e6577b1408df4bd
Marco Ricci Change the author e-mail ad...

Marco Ricci authored 3 months ago

tests/test_derivepassphrase_vault.py   1) # SPDX-FileCopyrightText: 2024 Marco Ricci <software@the13thletter.info>
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py         2) #
tests/test_derivepassphrase.py         3) # SPDX-License-Identifier: MIT
tests/test_derivepassphrase.py         4) 
Marco Ricci Move `sequin` and `ssh_agen...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py         5) """Test passphrase generation via derivepassphrase.vault.Vault."""
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py         6) 
tests/test_derivepassphrase.py         7) from __future__ import annotations
tests/test_derivepassphrase.py         8) 
tests/test_derivepassphrase.py         9) import math
Marco Ricci Add support for Python 3.9

Marco Ricci authored 2 months ago

tests/test_derivepassphrase_vault.py  10) from typing import TYPE_CHECKING
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        11) 
Marco Ricci Add hypothesis-based tests...

Marco Ricci authored 2 months ago

tests/test_derivepassphrase_vault.py  12) import hypothesis
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        13) import pytest
Marco Ricci Add hypothesis-based tests...

Marco Ricci authored 2 months ago

tests/test_derivepassphrase_vault.py  14) from hypothesis import strategies
Marco Ricci Add support for Python 3.9

Marco Ricci authored 2 months ago

tests/test_derivepassphrase_vault.py  15) from typing_extensions import TypeAlias, TypeVar
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        16) 
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        17) import derivepassphrase
tests/test_derivepassphrase.py        18) 
Marco Ricci Add hypothesis-based tests...

Marco Ricci authored 2 months ago

tests/test_derivepassphrase_vault.py  19) if TYPE_CHECKING:
tests/test_derivepassphrase_vault.py  20)     from collections.abc import Iterator
tests/test_derivepassphrase_vault.py  21) 
tests/test_derivepassphrase_vault.py  22) Vault: TypeAlias = derivepassphrase.vault.Vault
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        23) 
tests/test_derivepassphrase.py        24) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        25) class TestVault:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        26)     phrase = b'She cells C shells bye the sea shoars'
tests/test_derivepassphrase.py        27)     google_phrase = rb': 4TVH#5:aZl8LueOT\{'
tests/test_derivepassphrase.py        28)     twitter_phrase = rb"[ (HN_N:lI&<ro=)3'g9"
tests/test_derivepassphrase.py        29) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        30)     @pytest.mark.parametrize(
tests/test_derivepassphrase.py        31)         ['service', 'expected'],
tests/test_derivepassphrase.py        32)         [
tests/test_derivepassphrase.py        33)             (b'google', google_phrase),
tests/test_derivepassphrase.py        34)             ('twitter', twitter_phrase),
tests/test_derivepassphrase.py        35)         ],
tests/test_derivepassphrase.py        36)     )
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        37)     def test_200_basic_configuration(
tests/test_derivepassphrase.py        38)         self, service: bytes | str, expected: bytes
tests/test_derivepassphrase.py        39)     ) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        40)         assert Vault(phrase=self.phrase).generate(service) == expected
tests/test_derivepassphrase.py        41) 
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        42)     def test_201_phrase_dependence(self) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        43)         assert (
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        44)             Vault(phrase=(self.phrase + b'X')).generate('google')
tests/test_derivepassphrase.py        45)             == b'n+oIz6sL>K*lTEWYRO%7'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        46)         )
tests/test_derivepassphrase.py        47) 
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        48)     def test_202_reproducibility_and_bytes_service_name(self) -> None:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        49)         assert Vault(phrase=self.phrase).generate(b'google') == Vault(
tests/test_derivepassphrase.py        50)             phrase=self.phrase
tests/test_derivepassphrase.py        51)         ).generate('google')
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        52) 
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        53)     def test_203_reproducibility_and_bytearray_service_name(self) -> None:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        54)         assert Vault(phrase=self.phrase).generate(b'google') == Vault(
tests/test_derivepassphrase.py        55)             phrase=self.phrase
tests/test_derivepassphrase.py        56)         ).generate(bytearray(b'google'))
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        57) 
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        58)     def test_210_nonstandard_length(self) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        59)         assert (
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        60)             Vault(phrase=self.phrase, length=4).generate('google') == b'xDFu'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        61)         )
tests/test_derivepassphrase.py        62) 
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        63)     def test_211_repetition_limit(self) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        64)         assert (
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        65)             Vault(
tests/test_derivepassphrase.py        66)                 phrase=b'', length=24, symbol=0, number=0, repeat=1
tests/test_derivepassphrase.py        67)             ).generate('asd')
tests/test_derivepassphrase.py        68)             == b'IVTDzACftqopUXqDHPkuCIhV'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        69)         )
tests/test_derivepassphrase.py        70) 
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        71)     def test_212_without_symbols(self) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        72)         assert (
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        73)             Vault(phrase=self.phrase, symbol=0).generate('google')
tests/test_derivepassphrase.py        74)             == b'XZ4wRe0bZCazbljCaMqR'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        75)         )
tests/test_derivepassphrase.py        76) 
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        77)     def test_213_no_numbers(self) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        78)         assert (
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        79)             Vault(phrase=self.phrase, number=0).generate('google')
tests/test_derivepassphrase.py        80)             == b'_*$TVH.%^aZl(LUeOT?>'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        81)         )
tests/test_derivepassphrase.py        82) 
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        83)     def test_214_no_lowercase_letters(self) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        84)         assert (
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        85)             Vault(phrase=self.phrase, lower=0).generate('google')
tests/test_derivepassphrase.py        86)             == b':{?)+7~@OA:L]!0E$)(+'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        87)         )
tests/test_derivepassphrase.py        88) 
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        89)     def test_215_at_least_5_digits(self) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        90)         assert (
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        91)             Vault(phrase=self.phrase, length=8, number=5).generate('songkick')
tests/test_derivepassphrase.py        92)             == b'i0908.7['
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        93)         )
tests/test_derivepassphrase.py        94) 
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        95)     def test_216_lots_of_spaces(self) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        96)         assert (
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        97)             Vault(phrase=self.phrase, space=12).generate('songkick')
tests/test_derivepassphrase.py        98)             == b' c   6 Bq  % 5fR    '
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py        99)         )
tests/test_derivepassphrase.py       100) 
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       101)     def test_217_all_character_classes(self) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       102)         assert (
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       103)             Vault(
tests/test_derivepassphrase.py       104)                 phrase=self.phrase,
tests/test_derivepassphrase.py       105)                 lower=2,
tests/test_derivepassphrase.py       106)                 upper=2,
tests/test_derivepassphrase.py       107)                 number=1,
tests/test_derivepassphrase.py       108)                 space=3,
tests/test_derivepassphrase.py       109)                 dash=2,
tests/test_derivepassphrase.py       110)                 symbol=1,
tests/test_derivepassphrase.py       111)             ).generate('google')
tests/test_derivepassphrase.py       112)             == b': : fv_wqt>a-4w1S  R'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       113)         )
tests/test_derivepassphrase.py       114) 
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       115)     def test_218_only_numbers_and_very_high_repetition_limit(self) -> None:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       116)         generated = Vault(
tests/test_derivepassphrase.py       117)             phrase=b'',
tests/test_derivepassphrase.py       118)             length=40,
tests/test_derivepassphrase.py       119)             lower=0,
tests/test_derivepassphrase.py       120)             upper=0,
tests/test_derivepassphrase.py       121)             space=0,
tests/test_derivepassphrase.py       122)             dash=0,
tests/test_derivepassphrase.py       123)             symbol=0,
tests/test_derivepassphrase.py       124)             repeat=4,
tests/test_derivepassphrase.py       125)         ).generate('abcdef')
tests/test_derivepassphrase.py       126)         forbidden_substrings = {
tests/test_derivepassphrase.py       127)             b'0000',
tests/test_derivepassphrase.py       128)             b'1111',
tests/test_derivepassphrase.py       129)             b'2222',
tests/test_derivepassphrase.py       130)             b'3333',
tests/test_derivepassphrase.py       131)             b'4444',
tests/test_derivepassphrase.py       132)             b'5555',
tests/test_derivepassphrase.py       133)             b'6666',
tests/test_derivepassphrase.py       134)             b'7777',
tests/test_derivepassphrase.py       135)             b'8888',
tests/test_derivepassphrase.py       136)             b'9999',
tests/test_derivepassphrase.py       137)         }
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       138)         for substring in forbidden_substrings:
tests/test_derivepassphrase.py       139)             assert substring not in generated
tests/test_derivepassphrase.py       140) 
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       141)     def test_219_very_limited_character_set(self) -> None:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       142)         generated = Vault(
tests/test_derivepassphrase.py       143)             phrase=b'', length=24, lower=0, upper=0, space=0, symbol=0
tests/test_derivepassphrase.py       144)         ).generate('testing')
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       145)         assert generated == b'763252593304946694588866'
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       146) 
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       147)     def test_220_character_set_subtraction(self) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       148)         assert Vault._subtract(b'be', b'abcdef') == bytearray(b'acdf')
tests/test_derivepassphrase.py       149) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       150)     @pytest.mark.parametrize(
tests/test_derivepassphrase.py       151)         ['length', 'settings', 'entropy'],
tests/test_derivepassphrase.py       152)         [
tests/test_derivepassphrase.py       153)             (20, {}, math.log2(math.factorial(20)) + 20 * math.log2(94)),
tests/test_derivepassphrase.py       154)             (
tests/test_derivepassphrase.py       155)                 20,
tests/test_derivepassphrase.py       156)                 {'upper': 0, 'number': 0, 'space': 0, 'symbol': 0},
tests/test_derivepassphrase.py       157)                 math.log2(math.factorial(20)) + 20 * math.log2(26),
tests/test_derivepassphrase.py       158)             ),
tests/test_derivepassphrase.py       159)             (0, {}, float('-inf')),
tests/test_derivepassphrase.py       160)             (
tests/test_derivepassphrase.py       161)                 0,
tests/test_derivepassphrase.py       162)                 {'lower': 0, 'number': 0, 'space': 0, 'symbol': 0},
tests/test_derivepassphrase.py       163)                 float('-inf'),
tests/test_derivepassphrase.py       164)             ),
tests/test_derivepassphrase.py       165)             (1, {}, math.log2(94)),
tests/test_derivepassphrase.py       166)             (1, {'upper': 0, 'lower': 0, 'number': 0, 'symbol': 0}, 0.0),
tests/test_derivepassphrase.py       167)         ],
tests/test_derivepassphrase.py       168)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       169)     def test_221_entropy(
tests/test_derivepassphrase.py       170)         self, length: int, settings: dict[str, int], entropy: int
tests/test_derivepassphrase.py       171)     ) -> None:
tests/test_derivepassphrase.py       172)         v = Vault(length=length, **settings)  # type: ignore[arg-type]
tests/test_derivepassphrase.py       173)         assert math.isclose(v._entropy(), entropy)
tests/test_derivepassphrase.py       174)         assert v._estimate_sufficient_hash_length() > 0
tests/test_derivepassphrase.py       175)         if math.isfinite(entropy) and entropy:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       176)             assert v._estimate_sufficient_hash_length(1.0) == math.ceil(
tests/test_derivepassphrase.py       177)                 entropy / 8
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       178)             )
tests/test_derivepassphrase.py       179)         assert v._estimate_sufficient_hash_length(8.0) >= entropy
tests/test_derivepassphrase.py       180) 
tests/test_derivepassphrase.py       181)     def test_222_hash_length_estimation(self) -> None:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       182)         v = Vault(
tests/test_derivepassphrase.py       183)             phrase=self.phrase,
tests/test_derivepassphrase.py       184)             lower=0,
tests/test_derivepassphrase.py       185)             upper=0,
tests/test_derivepassphrase.py       186)             number=0,
tests/test_derivepassphrase.py       187)             symbol=0,
tests/test_derivepassphrase.py       188)             space=1,
tests/test_derivepassphrase.py       189)             length=1,
tests/test_derivepassphrase.py       190)         )
Marco Ricci Fix style issues with ruff...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       191)         assert v._entropy() == 0.0
tests/test_derivepassphrase.py       192)         assert v._estimate_sufficient_hash_length() > 0
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       193) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       194)     @pytest.mark.parametrize(
tests/test_derivepassphrase.py       195)         ['service', 'expected'],
tests/test_derivepassphrase.py       196)         [
tests/test_derivepassphrase.py       197)             (b'google', google_phrase),
tests/test_derivepassphrase.py       198)             ('twitter', twitter_phrase),
tests/test_derivepassphrase.py       199)         ],
tests/test_derivepassphrase.py       200)     )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       201)     def test_223_hash_length_expansion(
Marco Ricci Clean up testing machinery...

Marco Ricci authored 3 months ago

tests/test_derivepassphrase_vault.py 202)         self,
tests/test_derivepassphrase_vault.py 203)         monkeypatch: pytest.MonkeyPatch,
tests/test_derivepassphrase_vault.py 204)         service: str | bytes,
tests/test_derivepassphrase_vault.py 205)         expected: bytes,
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       206)     ) -> None:
tests/test_derivepassphrase.py       207)         v = Vault(phrase=self.phrase)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       208)         monkeypatch.setattr(
tests/test_derivepassphrase.py       209)             v,
tests/test_derivepassphrase.py       210)             '_estimate_sufficient_hash_length',
tests/test_derivepassphrase.py       211)             lambda *args, **kwargs: 1,  # noqa: ARG005
tests/test_derivepassphrase.py       212)         )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       213)         assert v._estimate_sufficient_hash_length() < len(self.phrase)
tests/test_derivepassphrase.py       214)         assert v.generate(service) == expected
tests/test_derivepassphrase.py       215) 
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       216)     @pytest.mark.parametrize(
Marco Ricci Allow all textual strings,...

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py       217)         's',
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       218)         [
Marco Ricci Allow all textual strings,...

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py       219)             'ñ',
tests/test_derivepassphrase.py       220)             'Düsseldorf',
tests/test_derivepassphrase.py       221)             'liberté, egalité, fraternité',
tests/test_derivepassphrase.py       222)             'ASCII',
tests/test_derivepassphrase.py       223)             b'D\xc3\xbcsseldorf',
tests/test_derivepassphrase.py       224)             bytearray([2, 3, 5, 7, 11, 13]),
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       225)         ],
tests/test_derivepassphrase.py       226)     )
Marco Ricci Allow all textual strings,...

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py       227)     def test_224_binary_strings(self, s: str | bytes | bytearray) -> None:
Marco Ricci Move `sequin` and `ssh_agen...

Marco Ricci authored 4 months ago

tests/test_derivepassphrase.py       228)         binstr = Vault._get_binary_string
Marco Ricci Allow all textual strings,...

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py       229)         if isinstance(s, str):
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       230)             assert binstr(s) == s.encode('UTF-8')
tests/test_derivepassphrase.py       231)             assert binstr(binstr(s)) == s.encode('UTF-8')
tests/test_derivepassphrase.py       232)         else:
tests/test_derivepassphrase.py       233)             assert binstr(s) == bytes(s)
tests/test_derivepassphrase.py       234)             assert binstr(binstr(s)) == bytes(s)
tests/test_derivepassphrase.py       235) 
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       236)     def test_310_too_many_symbols(self) -> None:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       237)         with pytest.raises(
tests/test_derivepassphrase.py       238)             ValueError, match='requested passphrase length too short'
tests/test_derivepassphrase.py       239)         ):
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       240)             Vault(phrase=self.phrase, symbol=100)
tests/test_derivepassphrase.py       241) 
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       242)     def test_311_no_viable_characters(self) -> None:
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       243)         with pytest.raises(ValueError, match='no allowed characters left'):
tests/test_derivepassphrase.py       244)             Vault(
tests/test_derivepassphrase.py       245)                 phrase=self.phrase,
tests/test_derivepassphrase.py       246)                 lower=0,
tests/test_derivepassphrase.py       247)                 upper=0,
tests/test_derivepassphrase.py       248)                 number=0,
tests/test_derivepassphrase.py       249)                 space=0,
tests/test_derivepassphrase.py       250)                 dash=0,
tests/test_derivepassphrase.py       251)                 symbol=0,
tests/test_derivepassphrase.py       252)             )
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       253) 
Marco Ricci Fix typing issues in mypy s...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       254)     def test_320_character_set_subtraction_duplicate(self) -> None:
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       255)         with pytest.raises(ValueError, match='duplicate characters'):
tests/test_derivepassphrase.py       256)             Vault._subtract(b'abcdef', b'aabbccddeeff')
tests/test_derivepassphrase.py       257)         with pytest.raises(ValueError, match='duplicate characters'):
tests/test_derivepassphrase.py       258)             Vault._subtract(b'aabbccddeeff', b'abcdef')
tests/test_derivepassphrase.py       259) 
tests/test_derivepassphrase.py       260)     def test_322_hash_length_estimation(self) -> None:
tests/test_derivepassphrase.py       261)         v = Vault(phrase=self.phrase)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       262)         with pytest.raises(ValueError, match='invalid safety factor'):
Marco Ricci Rename and regroup all test...

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       263)             assert v._estimate_sufficient_hash_length(-1.0)
Marco Ricci Reformat everything with ruff

Marco Ricci authored 5 months ago

tests/test_derivepassphrase.py       264)         with pytest.raises(
tests/test_derivepassphrase.py       265)             TypeError, match='invalid safety factor: not a float'
tests/test_derivepassphrase.py       266)         ):
Marco Ricci Apply new ruff ruleset to c...

Marco Ricci authored 3 months ago

tests/test_derivepassphrase.py       267)             assert v._estimate_sufficient_hash_length(None)  # type: ignore[arg-type]
Marco Ricci Add hypothesis-based tests...

Marco Ricci authored 2 months ago

tests/test_derivepassphrase_vault.py 268) 
tests/test_derivepassphrase_vault.py 269) 
tests/test_derivepassphrase_vault.py 270) @strategies.composite
tests/test_derivepassphrase_vault.py 271) def vault_config(draw: strategies.DrawFn) -> dict[str, int]:
tests/test_derivepassphrase_vault.py 272)     lower = draw(strategies.integers(min_value=0, max_value=10))
tests/test_derivepassphrase_vault.py 273)     upper = draw(strategies.integers(min_value=0, max_value=10))
tests/test_derivepassphrase_vault.py 274)     number = draw(strategies.integers(min_value=0, max_value=10))
tests/test_derivepassphrase_vault.py 275)     space = draw(strategies.integers(min_value=0, max_value=10))
tests/test_derivepassphrase_vault.py 276)     dash = draw(strategies.integers(min_value=0, max_value=10))
tests/test_derivepassphrase_vault.py 277)     symbol = draw(strategies.integers(min_value=0, max_value=10))
tests/test_derivepassphrase_vault.py 278)     repeat = draw(strategies.integers(min_value=0, max_value=10))
tests/test_derivepassphrase_vault.py 279)     length = draw(
tests/test_derivepassphrase_vault.py 280)         strategies.integers(
tests/test_derivepassphrase_vault.py 281)             min_value=max(1, lower + upper + number + space + dash + symbol),
tests/test_derivepassphrase_vault.py 282)             max_value=70,
tests/test_derivepassphrase_vault.py 283)         )
tests/test_derivepassphrase_vault.py 284)     )
tests/test_derivepassphrase_vault.py 285)     hypothesis.assume(lower + upper + number + dash + symbol > 0)
tests/test_derivepassphrase_vault.py 286)     hypothesis.assume(lower + upper + number + space + symbol > 0)
tests/test_derivepassphrase_vault.py 287)     hypothesis.assume(repeat >= space)
tests/test_derivepassphrase_vault.py 288)     return {
tests/test_derivepassphrase_vault.py 289)         'lower': lower,
tests/test_derivepassphrase_vault.py 290)         'upper': upper,
tests/test_derivepassphrase_vault.py 291)         'number': number,
tests/test_derivepassphrase_vault.py 292)         'space': space,
tests/test_derivepassphrase_vault.py 293)         'dash': dash,
tests/test_derivepassphrase_vault.py 294)         'symbol': symbol,
tests/test_derivepassphrase_vault.py 295)         'repeat': repeat,
tests/test_derivepassphrase_vault.py 296)         'length': length,
tests/test_derivepassphrase_vault.py 297)     }
tests/test_derivepassphrase_vault.py 298) 
tests/test_derivepassphrase_vault.py 299) 
tests/test_derivepassphrase_vault.py 300) class TestHypotheses:
tests/test_derivepassphrase_vault.py 301)     @hypothesis.given(
tests/test_derivepassphrase_vault.py 302)         phrase=strategies.one_of(
tests/test_derivepassphrase_vault.py 303)             strategies.binary(min_size=1), strategies.text(min_size=1)
tests/test_derivepassphrase_vault.py 304)         ),
tests/test_derivepassphrase_vault.py 305)         config=vault_config(),
tests/test_derivepassphrase_vault.py 306)         service=strategies.text(min_size=1),
tests/test_derivepassphrase_vault.py 307)     )
tests/test_derivepassphrase_vault.py 308)     # regression test
tests/test_derivepassphrase_vault.py 309)     @hypothesis.example(
tests/test_derivepassphrase_vault.py 310)         phrase=b'\x00',
tests/test_derivepassphrase_vault.py 311)         config={
tests/test_derivepassphrase_vault.py 312)             'lower': 0,
tests/test_derivepassphrase_vault.py 313)             'upper': 0,
tests/test_derivepassphrase_vault.py 314)             'number': 0,
tests/test_derivepassphrase_vault.py 315)             'space': 2,
tests/test_derivepassphrase_vault.py 316)             'dash': 0,
tests/test_derivepassphrase_vault.py 317)             'symbol': 1,
tests/test_derivepassphrase_vault.py 318)             'repeat': 2,
tests/test_derivepassphrase_vault.py 319)             'length': 3,
tests/test_derivepassphrase_vault.py 320)         },
tests/test_derivepassphrase_vault.py 321)         service='0',
tests/test_derivepassphrase_vault.py 322)     )
tests/test_derivepassphrase_vault.py 323)     # regression test
tests/test_derivepassphrase_vault.py 324)     @hypothesis.example(
tests/test_derivepassphrase_vault.py 325)         phrase=b'\x00',
tests/test_derivepassphrase_vault.py 326)         config={
tests/test_derivepassphrase_vault.py 327)             'lower': 0,
tests/test_derivepassphrase_vault.py 328)             'upper': 0,
tests/test_derivepassphrase_vault.py 329)             'number': 0,
tests/test_derivepassphrase_vault.py 330)             'space': 1,
tests/test_derivepassphrase_vault.py 331)             'dash': 0,
tests/test_derivepassphrase_vault.py 332)             'symbol': 0,
tests/test_derivepassphrase_vault.py 333)             'repeat': 9,
tests/test_derivepassphrase_vault.py 334)             'length': 5,
tests/test_derivepassphrase_vault.py 335)         },
tests/test_derivepassphrase_vault.py 336)         service='0',
tests/test_derivepassphrase_vault.py 337)     )
Marco Ricci Add explicit example in hyp...

Marco Ricci authored 2 months ago

tests/test_derivepassphrase_vault.py 338)     # branch coverage: case `repeat = 0` in `if config[repeat]` below
tests/test_derivepassphrase_vault.py 339)     @hypothesis.example(
tests/test_derivepassphrase_vault.py 340)         phrase=b'\x00',
tests/test_derivepassphrase_vault.py 341)         config={
tests/test_derivepassphrase_vault.py 342)             'lower': 0,
tests/test_derivepassphrase_vault.py 343)             'upper': 0,
tests/test_derivepassphrase_vault.py 344)             'number': 0,
tests/test_derivepassphrase_vault.py 345)             'space': 1,
tests/test_derivepassphrase_vault.py 346)             'dash': 0,
tests/test_derivepassphrase_vault.py 347)             'symbol': 0,
tests/test_derivepassphrase_vault.py 348)             'repeat': 0,
tests/test_derivepassphrase_vault.py 349)             'length': 5,
tests/test_derivepassphrase_vault.py 350)         },
tests/test_derivepassphrase_vault.py 351)         service='0',
tests/test_derivepassphrase_vault.py 352)     )
Marco Ricci Add hypothesis-based tests...

Marco Ricci authored 2 months ago

tests/test_derivepassphrase_vault.py 353)     def test_100_all_length_character_and_occurrence_constraints_satisfied(
tests/test_derivepassphrase_vault.py 354)         self,
tests/test_derivepassphrase_vault.py 355)         phrase: str | bytes,
tests/test_derivepassphrase_vault.py 356)         config: dict[str, int],
tests/test_derivepassphrase_vault.py 357)         service: str,
tests/test_derivepassphrase_vault.py 358)     ) -> None:
tests/test_derivepassphrase_vault.py 359)         try:
tests/test_derivepassphrase_vault.py 360)             password = Vault(phrase=phrase, **config).generate(service)
tests/test_derivepassphrase_vault.py 361)         except ValueError as exc:
tests/test_derivepassphrase_vault.py 362)             if 'no allowed characters left' in exc.args:
tests/test_derivepassphrase_vault.py 363)                 return
tests/test_derivepassphrase_vault.py 364)             raise  # pragma: no cover
tests/test_derivepassphrase_vault.py 365)         n = len(password)
tests/test_derivepassphrase_vault.py 366)         assert n == config['length'], 'Password has wrong length.'
tests/test_derivepassphrase_vault.py 367)         for key in ('lower', 'upper', 'number', 'space', 'dash', 'symbol'):
tests/test_derivepassphrase_vault.py 368)             if config[key] > 0:
tests/test_derivepassphrase_vault.py 369)                 assert (
tests/test_derivepassphrase_vault.py 370)                     sum(c in Vault._CHARSETS[key] for c in password)
tests/test_derivepassphrase_vault.py 371)                     >= config[key]
tests/test_derivepassphrase_vault.py 372)                 ), (
tests/test_derivepassphrase_vault.py 373)                     'Password does not satisfy '
tests/test_derivepassphrase_vault.py 374)                     'character occurrence constraints.'
tests/test_derivepassphrase_vault.py 375)                 )
tests/test_derivepassphrase_vault.py 376)             elif key in {'dash', 'symbol'}:
tests/test_derivepassphrase_vault.py 377)                 # Character classes overlap, so "forbidden" characters may
tests/test_derivepassphrase_vault.py 378)                 # appear via the other character class.
tests/test_derivepassphrase_vault.py 379)                 assert True
tests/test_derivepassphrase_vault.py 380)             else:
tests/test_derivepassphrase_vault.py 381)                 assert (
tests/test_derivepassphrase_vault.py 382)                     sum(c in Vault._CHARSETS[key] for c in password) == 0
tests/test_derivepassphrase_vault.py 383)                 ), 'Password does not satisfy character ban constraints.'
tests/test_derivepassphrase_vault.py 384) 
tests/test_derivepassphrase_vault.py 385)         T = TypeVar('T', str, bytes)
tests/test_derivepassphrase_vault.py 386) 
tests/test_derivepassphrase_vault.py 387)         def length_r_substrings(string: T, *, r: int) -> Iterator[T]:
tests/test_derivepassphrase_vault.py 388)             for i in range(len(string) - (r - 1)):
tests/test_derivepassphrase_vault.py 389)                 yield string[i : i + r]
tests/test_derivepassphrase_vault.py 390) 
tests/test_derivepassphrase_vault.py 391)         repeat = config['repeat']
tests/test_derivepassphrase_vault.py 392)         if repeat:
tests/test_derivepassphrase_vault.py 393)             for snippet in length_r_substrings(password, r=(repeat + 1)):
tests/test_derivepassphrase_vault.py 394)                 assert (
tests/test_derivepassphrase_vault.py 395)                     len(set(snippet)) > 1
tests/test_derivepassphrase_vault.py 396)                 ), 'Password does not satisfy character repeat constraints.'
tests/test_derivepassphrase_vault.py 397) 
Marco Ricci Accomodate known slow tests...

Marco Ricci authored 2 months ago

tests/test_derivepassphrase_vault.py 398)     # This test tends to time out when using coverage without the
tests/test_derivepassphrase_vault.py 399)     # C tracer, which in my testing leads to a roughly 40-fold execution
tests/test_derivepassphrase_vault.py 400)     # time. So reset the deadline accordingly.
tests/test_derivepassphrase_vault.py 401)     @hypothesis.settings(
tests/test_derivepassphrase_vault.py 402)         deadline=(
tests/test_derivepassphrase_vault.py 403)             40 * deadline  # type: ignore[name-defined]
tests/test_derivepassphrase_vault.py 404)             if (deadline := hypothesis.settings().deadline) is not None
tests/test_derivepassphrase_vault.py 405)             else None
tests/test_derivepassphrase_vault.py 406)         )
tests/test_derivepassphrase_vault.py 407)     )