Example #1
0
def test_timezones_are_checked_in_deserialization():
    s = times()
    r = Random(1)
    basic = s.to_basic(s.draw_template(r, s.draw_parameter(r)))
    with pytest.raises(UnsatisfiedAssumption):
        t = times(timezones=[])
        t.reify(t.from_basic(basic))
Example #2
0
def test_can_generate_naive_time():
    find_any(times(allow_naive=True), lambda d: d.tzinfo is not None)
Example #3
0
@checks_deprecated_behaviour
def test_can_generate_non_naive_time():
    assert minimal(
        times(allow_naive=True), lambda d: d.tzinfo).tzinfo == pytz.UTC


@checks_deprecated_behaviour
def test_can_generate_non_utc():
    times().filter(
        lambda d: assume(d.tzinfo) and d.tzinfo.zone != u'UTC'
    ).example()


@checks_deprecated_behaviour
@given(times(timezones=[]))
def test_naive_times_are_naive(dt):
    assert not dt.tzinfo


@checks_deprecated_behaviour
@given(times(allow_naive=False))
def test_timezone_aware_times_are_timezone_aware(dt):
    assert dt.tzinfo


@checks_deprecated_behaviour
def test_restricts_to_allowed_set_of_timezones():
    timezones = list(map(pytz.timezone, list(pytz.all_timezones)[:3]))
    x = minimal(times(timezones=timezones))
    assert any(tz.zone == x.tzinfo.zone for tz in timezones)
Example #4
0
def test_restricts_to_allowed_set_of_timezones():
    timezones = list(map(pytz.timezone, list(pytz.all_timezones)[:3]))
    x = minimal(times(timezones=timezones))
    assert any(tz.zone == x.tzinfo.zone for tz in timezones)
Example #5
0
def test_can_generate_non_naive_time():
    assert minimal(
        times(allow_naive=True), lambda d: d.tzinfo).tzinfo == pytz.UTC
Example #6
0
def test_simplifies_towards_midnight():
    d = minimal(times())
    assert d.hour == 0
    assert d.minute == 0
    assert d.second == 0
    assert d.microsecond == 0
Example #7
0
def test_can_find_non_midnight():
    assert minimal(times(), lambda x: x.hour != 0).hour == 1
Example #8
0
from __future__ import division, print_function, absolute_import

from random import Random

import pytz
import pytest

import hypothesis._settings as hs
from hypothesis import given, assume
from hypothesis.errors import UnsatisfiedAssumption
from hypothesis.strategytests import strategy_test_suite
from hypothesis.extra.datetime import times
from hypothesis.internal.debug import minimal

TestStandardDescriptorFeatures1 = strategy_test_suite(times())


def test_can_find_midnight():
    minimal(
        times(),
        lambda x: (x.hour == 0 and x.minute == 0 and x.second == 0),
    )


def test_can_find_non_midnight():
    assert minimal(times(), lambda x: x.hour != 0).hour == 1


def test_can_find_off_the_minute():
    minimal(times(), lambda x: x.second == 0)
Example #9
0
def test_timezones_are_checked_in_deserialization():
    s = times()
    r = Random(1)
    basic = s.to_basic(s.draw_template(r, s.draw_parameter(r)))
    with pytest.raises(BadData):
        times(timezones=[]).from_basic(basic)
Example #10
0
@test.hypothesis_min_ver
@given(datetimes())
def test_is_to_gregorian(date):
    """Test if a roundtrip of isoclander() -> iso_to_gregorian() is correct"""
    iso_tuple = date.isocalendar()
    new_date  = iso_to_gregorian(*iso_tuple)
    assert date.year  == new_date.year
    assert date.month == new_date.month
    assert date.day   == new_date.day


@test.hypothesis_min_ver
@given(
    datetimes(min_year=2),
    integers(min_value=1, max_value=7),
    times())
def test_round_weekly(date, day_of_week, time):
    """Test if the round function rounds the expected delta"""
    time            = time_remove_tz(time)
    round_date      = date_round_weekly(date, day_of_week, time)
    date_time       = datetime.time(
        hour        = date.hour,
        minute      = date.minute,
        second      = date.second,
        microsecond = date.microsecond,
    )
    # double round
    assert round_date == date_round_weekly(round_date, day_of_week, time)
    if round_date == date:  # pragma: no cover
        # Find tz problems
        assert date_time == time
Example #11
0
def test_can_generate_non_utc():
    times().filter(
        lambda d: assume(d.tzinfo) and d.tzinfo.zone != u'UTC'
    ).example()
Example #12
0
def test_can_generate_naive_time():
    find_any(times(allow_naive=True), lambda d: d.tzinfo is not None)
Example #13
0
def test_can_find_on_the_minute():
    find_any(times(), lambda x: x.second == 0)
Example #14
0
def test_can_find_midnight():
    find_any(times(), lambda x: x.hour == x.minute == x.second == 0)
Example #15
0
def test_can_generate_non_utc():
    times().filter(
        lambda d: assume(d.tzinfo) and d.tzinfo.zone != u'UTC'
    ).example()
Example #16
0
    integers = mock.MagicMock()  # noqa


@test.hypothesis_min_ver
@given(datetimes())
def test_is_to_gregorian(date):
    """Test if a roundtrip of isoclander() -> iso_to_gregorian() is correct"""
    iso_tuple = date.isocalendar()
    new_date = iso_to_gregorian(*iso_tuple)
    assert date.year == new_date.year
    assert date.month == new_date.month
    assert date.day == new_date.day


@test.hypothesis_min_ver
@given(datetimes(min_year=2), integers(min_value=1, max_value=7), times())
def test_round_weekly(date, day_of_week, time):
    """Test if the round function rounds the expected delta"""
    time = time_remove_tz(time)
    round_date = date_round_weekly(date, day_of_week, time)
    date_time = datetime.time(
        hour=date.hour,
        minute=date.minute,
        second=date.second,
        microsecond=date.microsecond,
    )
    # double round
    assert round_date == date_round_weekly(round_date, day_of_week, time)
    if round_date == date:  # pragma: no cover
        # Find tz problems
        assert date_time == time
Example #17
0
def test_can_find_midnight():
    times().filter(lambda x: x.hour == x.minute == x.second == 0).example()
Example #18
0
def test_can_find_midnight():
    minimal(
        times(),
        lambda x: (x.hour == 0 and x.minute == 0 and x.second == 0),
    )
Example #19
0
def test_can_find_on_the_minute():
    times().filter(lambda x: x.second == 0).example()
Example #20
0
def test_can_find_on_the_minute():
    minimal(times(), lambda x: x.second != 0)
Example #21
0
def test_can_generate_naive_time():
    times(allow_naive=True).filter(lambda d: d.tzinfo is not None).example()
Example #22
0
def test_can_generate_naive_time():
    minimal(times(allow_naive=True), lambda d: not d.tzinfo)
Example #23
0
@checks_deprecated_behaviour
def test_can_generate_non_naive_time():
    assert minimal(
        times(allow_naive=True), lambda d: d.tzinfo).tzinfo == pytz.UTC


@checks_deprecated_behaviour
def test_can_generate_non_utc():
    times().filter(
        lambda d: assume(d.tzinfo) and d.tzinfo.zone != u'UTC'
    ).example()


@checks_deprecated_behaviour
@given(times(timezones=[]))
def test_naive_times_are_naive(dt):
    assert not dt.tzinfo


@checks_deprecated_behaviour
@given(times(allow_naive=False))
def test_timezone_aware_times_are_timezone_aware(dt):
    assert dt.tzinfo


@checks_deprecated_behaviour
def test_restricts_to_allowed_set_of_timezones():
    timezones = list(map(pytz.timezone, list(pytz.all_timezones)[:3]))
    x = minimal(times(timezones=timezones))
    assert any(tz.zone == x.tzinfo.zone for tz in timezones)
Example #24
0
def test_can_generate_non_utc():
    minimal(
        times(),
        lambda d: assume(d.tzinfo) and d.tzinfo.zone != u'UTC')
Example #25
0
def test_can_find_midnight():
    find_any(times(), lambda x: x.hour == x.minute == x.second == 0)
Example #26
0
def test_can_find_on_the_minute():
    find_any(times(), lambda x: x.second == 0)
def time_strategy(registry, type, context=None):
    return hsd.times()