1 84
from hypothesis import given, assume
2 84
from hypothesis import strategies as st
3

4 84
from dateutil import tz
5 84
from dateutil.parser import isoparse
6

7 84
import pytest
8

9
# Strategies
10 84
TIME_ZONE_STRATEGY = st.sampled_from([None, tz.UTC] +
11
    [tz.gettz(zname) for zname in ('US/Eastern', 'US/Pacific',
12
                                   'Australia/Sydney', 'Europe/London')])
13 84
ASCII_STRATEGY = st.characters(max_codepoint=127)
14

15

16 84
@pytest.mark.isoparser
17 84
@given(dt=st.datetimes(timezones=TIME_ZONE_STRATEGY), sep=ASCII_STRATEGY)
18 27
def test_timespec_auto(dt, sep):
19 84
    if dt.tzinfo is not None:
20
        # Assume offset has no sub-second components
21 84
        assume(dt.utcoffset().total_seconds() % 60 == 0)
22

23 84
    sep = str(sep)          # Python 2.7 requires bytes
24 84
    dtstr = dt.isoformat(sep=sep)
25 84
    dt_rt = isoparse(dtstr)
26

27 84
    assert dt_rt == dt

Read our documentation on viewing source code .

Loading