Hypothesis: from_type(xrange) is broken

Created on 8 May 2019  路  4Comments  路  Source: HypothesisWorks/hypothesis

The following test demonstrates this bug:

@settings(max_examples=1000)
@given(type_=st.from_type(xrange))
def test_from_type_xrange(type_):
    pass

OverflowError: Python int too large to convert to C long

bug

All 4 comments

I think our test suite is missing the following test, which should be added to tests/cover/test_type_lookup.py:

from hypothesis.searchstrategy.types import _global_type_lookup

@pytest.mark.parametrize("typ", sorted(_global_type_lookup, key=str))
@given(data())
def test_can_generate_from_all_registered_types(data, typ):
    ex = data.draw(from_type(typ))
    assert isinstance(ex, typ)

Everything looks fine for Python 2 once I make the xrange fix.

It looks like there are a few complications even on the Python 3 end of things because of the items from the typing module. Calling isinstance with some of these doesn't work. How do you want to proceed with these items:

  • Each of the SupportsXXXX objects we get: TypeError: Protocols cannot be used with isinstance().
  • BytesIO & StringIO values are not instances of their typing counterparts.
  • The draw for typing.Type fails with: where False = isinstance(+CT_co, typing.Type)

I can make a mapping back to the appropriate types that gets used within the test for the first two points, and that should take care of those easily enough. I am not sure what to make of the typing.Type case.

I'd just exclude anything where the __module__ attribute is "typing"; as the runtime issues are more trouble than they're worth and well tested in the py3 tests.

That's a relief. Much simpler.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

garry-jeromson picture garry-jeromson  路  3Comments

sobolevn picture sobolevn  路  8Comments

goodspark picture goodspark  路  8Comments

Zac-HD picture Zac-HD  路  7Comments

whatevergeek picture whatevergeek  路  3Comments