ipaddress.IPv4Network: st.one_of( _networks(32).map(lambda x: ipaddress.IPv4Network(x, strict=False)), st.sampled_from(SPECIAL_IPv4_RANGES).map(ipaddress.IPv4Network), ), ipaddress.IPv6Network: st.one_of( _networks(128).map(lambda x: ipaddress.IPv6Network(x, strict=False)), st.sampled_from(SPECIAL_IPv6_RANGES).map(ipaddress.IPv6Network), ), os.PathLike: st.builds(PurePath, st.text()), # Pull requests with more types welcome! } if zoneinfo is not None: # pragma: no branch _global_type_lookup[zoneinfo.ZoneInfo] = st.timezones() _global_type_lookup[type] = st.sampled_from( [type(None)] + sorted(_global_type_lookup, key=str)) if sys.version_info[:2] >= (3, 7): # pragma: no branch _global_type_lookup[re.Match] = (st.text().map( lambda c: re.match(".", c, flags=re.DOTALL)).filter(bool)) _global_type_lookup[re.Pattern] = st.builds(re.compile, st.sampled_from(["", b""])) if sys.version_info[:2] >= (3, 9): # pragma: no cover # subclass of MutableMapping, and in Python 3.9 we resolve to a union # which includes this... but we don't actually ever want to build one. _global_type_lookup[os._Environ] = st.just(os.environ) try: # pragma: no cover
precision=st.integers(min_value=1, max_value=38), scale=st.integers(min_value=1, max_value=38)) decimal256_type = st.builds(pa.decimal256, precision=st.integers(min_value=1, max_value=76), scale=st.integers(min_value=1, max_value=76)) numeric_types = st.one_of(integer_types, floating_types, decimal128_type, decimal256_type) date_types = st.sampled_from([pa.date32(), pa.date64()]) time_types = st.sampled_from( [pa.time32('s'), pa.time32('ms'), pa.time64('us'), pa.time64('ns')]) if tzst and zoneinfo: timezones = st.one_of(st.none(), tzst.timezones(), st.timezones()) elif tzst: timezones = st.one_of(st.none(), tzst.timezones()) elif zoneinfo: timezones = st.one_of(st.none(), st.timezones()) else: timezones = st.none() timestamp_types = st.builds(pa.timestamp, unit=st.sampled_from(['s', 'ms', 'us', 'ns']), tz=timezones) duration_types = st.builds(pa.duration, st.sampled_from(['s', 'ms', 'us', 'ns'])) interval_types = st.just(pa.month_day_nano_interval()) temporal_types = st.one_of(date_types, time_types, timestamp_types, duration_types, interval_types)
def test_timezones_argument_validation(kwargs): with pytest.raises(InvalidArgument): st.timezones(**kwargs).validate()
def test_datetimes_stay_within_naive_bounds(data, lo, hi): if lo > hi: lo, hi = hi, lo out = data.draw(st.datetimes(lo, hi, timezones=st.timezones())) assert lo <= out.replace(tzinfo=None) <= hi
def test_can_generate_non_utc(): find_any( st.datetimes( timezones=st.timezones()).filter(lambda d: d.tzinfo.key != "UTC"))
def test_utc_is_minimal(): assert minimal(st.timezones()) is zoneinfo.ZoneInfo("UTC")