| 1 |
# This file is part of Hypothesis, which may be found at |
| 2 |
# https://github.com/HypothesisWorks/hypothesis/ |
| 3 |
# |
| 4 |
# Copyright the Hypothesis Authors. |
| 5 |
# Individual contributors are listed in AUTHORS.rst and the git log. |
| 6 |
# |
| 7 |
# This Source Code Form is subject to the terms of the Mozilla Public License, |
| 8 |
# v. 2.0. If a copy of the MPL was not distributed with this file, You can |
| 9 |
# obtain one at https://mozilla.org/MPL/2.0/. |
| 10 |
|
| 11 |
SHOULD_NOT_IMPORT_NUMPY = """ |
| 12 |
import sys |
| 13 |
from hypothesis import given, strategies as st |
| 14 |
|
| 15 |
@given(st.integers() | st.floats() | st.sampled_from(["a", "b"])) |
| 16 |
def test_no_numpy_import(x): |
| 17 |
assert "numpy" not in sys.modules |
| 18 |
""" |
| 19 |
|
| 20 |
|
| 21 |
def test_hypothesis_is_not_the_first_to_import_numpy(testdir): |
| 22 |
# We only import numpy if the user did so first. |
| 23 |
result = testdir.runpytest(testdir.makepyfile(SHOULD_NOT_IMPORT_NUMPY)) |
| 24 |
result.assert_outcomes(passed=1, failed=0) |
| 25 |
|
| 26 |
|
| 27 |
# We check the wildcard import works on the module level because that's the only |
| 28 |
# place Python actually allows us to use them. |
| 29 |
try: |
| 30 |
from hypothesis.extra.numpy import * # noqa: F403 |
| 31 |
|
| 32 |
star_import_works = True |
| 33 |
except AttributeError: |
| 34 |
star_import_works = False |
| 35 |
|
| 36 |
|
| 37 |
def test_wildcard_import(): |
| 38 |
assert star_import_works |