示例#1
0
def test_minimise_array_strategy():
    smallest = minimal(
        nps.arrays(
            nps.nested_dtypes(max_itemsize=200),
            nps.array_shapes(max_dims=3, max_side=3),
        ))
    assert smallest.dtype == np.dtype("bool") and not smallest.any()
示例#2
0
def test_minimise_array_strategy():
    smallest = minimal(
        nps.arrays(
            nps.nested_dtypes(max_itemsize=settings.default.buffer_size //
                              3**3),
            nps.array_shapes(max_dims=3, max_side=3),
        ))
    assert smallest.dtype == np.dtype(u"bool") and not smallest.any()
示例#3
0
    _global_type_lookup[datetime.tzinfo] = timezones()
except ImportError:  # pragma: no cover
    pass
try:  # pragma: no cover
    import numpy as np
    from hypothesis.extra.numpy import (
        arrays,
        array_shapes,
        scalar_dtypes,
        nested_dtypes,
    )

    _global_type_lookup.update(
        {
            np.dtype: nested_dtypes(),
            np.ndarray: arrays(scalar_dtypes(), array_shapes(max_dims=2)),
        }
    )
except ImportError:  # pragma: no cover
    pass

try:
    import typing
except ImportError:  # pragma: no cover
    pass
else:
    _global_type_lookup.update(
        {
            typing.ByteString: st.binary(),
            typing.io.BinaryIO: st.builds(io.BytesIO, st.binary()),
示例#4
0
def test_minimise_nested_types():
    assert minimal(nps.nested_dtypes()) == np.dtype("bool")
示例#5
0
    "kwargs", [{"min_side": 100}, {"min_dims": 15}, {"min_dims": 32}]
)
def test_interesting_array_shapes_argument(kwargs):
    nps.array_shapes(**kwargs).example()


@given(nps.scalar_dtypes())
def test_can_generate_scalar_dtypes(dtype):
    assert isinstance(dtype, np.dtype)


@settings(max_examples=100)
@given(
    nps.nested_dtypes(
        subtype_strategy=st.one_of(
            nps.scalar_dtypes(), nps.byte_string_dtypes(), nps.unicode_string_dtypes()
        )
    )
)
def test_can_generate_compound_dtypes(dtype):
    assert isinstance(dtype, np.dtype)


@settings(max_examples=100)
@given(
    nps.nested_dtypes(
        subtype_strategy=st.one_of(
            nps.scalar_dtypes(), nps.byte_string_dtypes(), nps.unicode_string_dtypes()
        )
    ).flatmap(lambda dt: nps.arrays(dtype=dt, shape=1))
)
示例#6
0
            u"float",
            u"float16",
            u"float32",
            u"float64",
            u"complex64",
            u"complex128",
            u"datetime64",
            u"timedelta64",
            bool,
            text_type,
            binary_type,
        ],
    ))


@given(nps.nested_dtypes())
def test_strategies_for_standard_dtypes_have_reusable_values(dtype):
    assert nps.from_dtype(dtype).has_reusable_values


@pytest.mark.parametrize(u"t", STANDARD_TYPES)
def test_produces_instances(t):
    @given(nps.from_dtype(t))
    def test_is_t(x):
        assert isinstance(x, t.type)
        assert x.dtype.kind == t.kind

    test_is_t()


@given(nps.arrays(float, ()))
示例#7
0
        "float",
        "float16",
        "float32",
        "float64",
        "complex64",
        "complex128",
        "datetime64",
        "timedelta64",
        bool,
        str,
        bytes,
    )
]


@given(nps.nested_dtypes())
def test_strategies_for_standard_dtypes_have_reusable_values(dtype):
    assert nps.from_dtype(dtype).has_reusable_values


@pytest.mark.parametrize("t", STANDARD_TYPES)
def test_produces_instances(t):
    @given(nps.from_dtype(t))
    def test_is_t(x):
        assert isinstance(x, t.type)
        assert x.dtype.kind == t.kind

    test_is_t()


@settings(max_examples=100)
示例#8
0
    _global_type_lookup[datetime.tzinfo] = timezones()
except ImportError:  # pragma: no cover
    pass
try:  # pragma: no cover
    import numpy as np
    from hypothesis.extra.numpy import (
        arrays,
        array_shapes,
        scalar_dtypes,
        nested_dtypes,
    )

    _global_type_lookup.update({
        np.dtype:
        nested_dtypes(),
        np.ndarray:
        arrays(scalar_dtypes(), array_shapes(max_dims=2)),
    })
except ImportError:  # pragma: no cover
    pass

try:
    import typing
except ImportError:  # pragma: no cover
    pass
else:
    _global_type_lookup.update({
        typing.ByteString:
        st.binary(),
        typing.io.BinaryIO:
示例#9
0
    _global_type_lookup.update({
        int: st.integers().filter(lambda x: isinstance(x, int)),
        long: st.integers().map(long)  # noqa
    })

try:
    from hypothesis.extra.pytz import timezones
    _global_type_lookup[datetime.tzinfo] = timezones()
except ImportError:  # pragma: no cover
    pass
try:  # pragma: no cover
    import numpy as np
    from hypothesis.extra.numpy import \
        arrays, array_shapes, scalar_dtypes, nested_dtypes
    _global_type_lookup.update({
        np.dtype: nested_dtypes(),
        np.ndarray: arrays(scalar_dtypes(), array_shapes(max_dims=2)),
    })
except ImportError:  # pragma: no cover
    pass

try:
    import typing
except ImportError:  # pragma: no cover
    pass
else:
    _global_type_lookup.update({
        typing.ByteString: st.binary(),
        typing.io.BinaryIO: st.builds(io.BytesIO, st.binary()),  # type: ignore
        typing.io.TextIO: st.builds(io.StringIO, st.text()),  # type: ignore
        typing.Reversible: st.lists(st.integers()),
def test_minimise_nested_types():
    assert minimal(nested_dtypes()) == np.dtype(u'bool')
示例#11
0
def test_minimise_array_strategy():
    smallest = minimal(nps.arrays(
        nps.nested_dtypes(max_itemsize=settings.default.buffer_size // 3**3),
        nps.array_shapes(max_dims=3, max_side=3)))
    assert smallest.dtype == np.dtype(u'bool') and not smallest.any()
示例#12
0
def test_minimise_nested_types():
    assert minimal(nps.nested_dtypes()) == np.dtype(u'bool')
示例#13
0
from tests.common.debug import minimal, find_any
from tests.common.utils import checks_deprecated_behaviour
from hypothesis.searchstrategy import SearchStrategy
from hypothesis.internal.compat import text_type, binary_type

STANDARD_TYPES = list(map(np.dtype, [
    u'int8', u'int16', u'int32', u'int64',
    u'uint8', u'uint16', u'uint32', u'uint64',
    u'float', u'float16', u'float32', u'float64',
    u'complex64', u'complex128',
    u'datetime64', u'timedelta64',
    bool, text_type, binary_type
]))


@given(nps.nested_dtypes())
def test_strategies_for_standard_dtypes_have_reusable_values(dtype):
    assert nps.from_dtype(dtype).has_reusable_values


@pytest.mark.parametrize(u't', STANDARD_TYPES)
def test_produces_instances(t):
    @given(nps.from_dtype(t))
    def test_is_t(x):
        assert isinstance(x, t.type)
        assert x.dtype.kind == t.kind
    test_is_t()


@given(nps.arrays(float, ()))
def test_empty_dimensions_are_scalars(x):