Skip to content

Commit f151eec

Browse files
committed
refactor some code
1 parent 22ff77f commit f151eec

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

hypothesis-python/src/hypothesis/core.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,16 +1010,18 @@ def run(data):
10101010

10111011
# self.test_runner can include the execute_example method, or setup/teardown
10121012
# _example, so it's important to get the PRNG and build context in place first.
1013-
with local_settings(self.settings):
1014-
with deterministic_PRNG():
1015-
with BuildContext(data, is_final=is_final) as context:
1016-
# providers may throw in per_case_context_fn, and we'd like
1017-
# `result` to still be set in these cases.
1018-
result = None
1019-
with data.provider.per_test_case_context_manager():
1020-
# Run the test function once, via the executor hook.
1021-
# In most cases this will delegate straight to `run(data)`.
1022-
result = self.test_runner(data, run)
1013+
with (
1014+
local_settings(self.settings),
1015+
deterministic_PRNG(),
1016+
BuildContext(data, is_final=is_final) as context,
1017+
):
1018+
# providers may throw in per_case_context_fn, and we'd like
1019+
# `result` to still be set in these cases.
1020+
result = None
1021+
with data.provider.per_test_case_context_manager():
1022+
# Run the test function once, via the executor hook.
1023+
# In most cases this will delegate straight to `run(data)`.
1024+
result = self.test_runner(data, run)
10231025

10241026
# If a failure was expected, it should have been raised already, so
10251027
# instead raise an appropriate diagnostic error.

hypothesis-python/src/hypothesis/internal/conjecture/choice.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -540,10 +540,11 @@ def choice_permitted(choice: ChoiceT, constraints: ChoiceConstraintsT) -> bool:
540540
constraints = cast(FloatConstraints, constraints)
541541
if math.isnan(choice):
542542
return constraints["allow_nan"]
543-
return (
544-
sign_aware_lte(constraints["min_value"], choice)
545-
and sign_aware_lte(choice, constraints["max_value"])
546-
) and not (0 < abs(choice) < constraints["smallest_nonzero_magnitude"])
543+
if 0 < abs(choice) < constraints["smallest_nonzero_magnitude"]:
544+
return False
545+
return sign_aware_lte(constraints["min_value"], choice) and sign_aware_lte(
546+
choice, constraints["max_value"]
547+
)
547548
elif isinstance(choice, str):
548549
constraints = cast(StringConstraints, constraints)
549550
if len(choice) < constraints["min_size"]:

0 commit comments

Comments
 (0)