Skip to content

Commit d803672

Browse files
committedFeb 22, 2025··
Replace loop with parametrization
1 parent adde718 commit d803672

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed
 

‎tests/test_password_hasher.py

+24-24
Original file line numberDiff line numberDiff line change
@@ -160,37 +160,37 @@ def test_type_is_configurable(self):
160160
assert ph.check_needs_rehash(default_hash)
161161

162162
@mock.patch("sys.platform", "emscripten")
163-
def test_params_on_wasm(self):
163+
@pytest.mark.parametrize("machine", ["wasm32", "wasm64"])
164+
def test_params_on_wasm(self, machine):
164165
"""
165166
Should fail if on wasm and parallelism > 1
166167
"""
167-
for machine in ["wasm32", "wasm64"]:
168-
with mock.patch("platform.machine", return_value=machine):
169-
with pytest.raises(
170-
UnsupportedParametersError,
171-
match="In WebAssembly environments `parallelism` must be 1.",
172-
):
173-
PasswordHasher(parallelism=2)
168+
with mock.patch("platform.machine", return_value=machine):
169+
with pytest.raises(
170+
UnsupportedParametersError,
171+
match="In WebAssembly environments `parallelism` must be 1.",
172+
):
173+
PasswordHasher(parallelism=2)
174174

175-
# last param is parallelism so it should fail
176-
params = Parameters(Type.I, 2, 8, 8, 3, 256, 8)
177-
with pytest.raises(
178-
UnsupportedParametersError,
179-
match="In WebAssembly environments `parallelism` must be 1.",
180-
):
181-
ph = PasswordHasher.from_parameters(params)
175+
# last param is parallelism so it should fail
176+
params = Parameters(Type.I, 2, 8, 8, 3, 256, 8)
177+
with pytest.raises(
178+
UnsupportedParametersError,
179+
match="In WebAssembly environments `parallelism` must be 1.",
180+
):
181+
ph = PasswordHasher.from_parameters(params)
182182

183-
# explicitly correct parameters
184-
ph = PasswordHasher(parallelism=1)
183+
# explicitly correct parameters
184+
ph = PasswordHasher(parallelism=1)
185185

186-
hash = ph.hash("hello")
186+
hash = ph.hash("hello")
187187

188-
assert ph.verify(hash, "hello") is True
188+
assert ph.verify(hash, "hello") is True
189189

190-
# explicit, but still default parameters
191-
default_params = profiles.get_default_parameters()
192-
ph = PasswordHasher.from_parameters(default_params)
190+
# explicit, but still default parameters
191+
default_params = profiles.get_default_parameters()
192+
ph = PasswordHasher.from_parameters(default_params)
193193

194-
hash = ph.hash("hello")
194+
hash = ph.hash("hello")
195195

196-
assert ph.verify(hash, "hello") is True
196+
assert ph.verify(hash, "hello") is True

0 commit comments

Comments
 (0)
Please sign in to comment.