Exemplo n.º 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))
Exemplo n.º 2
0
def test_can_generate_naive_time():
    find_any(times(allow_naive=True), lambda d: d.tzinfo is not None)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 5
0
def test_can_generate_non_naive_time():
    assert minimal(
        times(allow_naive=True), lambda d: d.tzinfo).tzinfo == pytz.UTC
Exemplo n.º 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
Exemplo n.º 7
0
def test_can_find_non_midnight():
    assert minimal(times(), lambda x: x.hour != 0).hour == 1
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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
Exemplo n.º 11
0
def test_can_generate_non_utc():
    times().filter(
        lambda d: assume(d.tzinfo) and d.tzinfo.zone != u'UTC'
    ).example()
Exemplo n.º 12
0
def test_can_generate_naive_time():
    find_any(times(allow_naive=True), lambda d: d.tzinfo is not None)
Exemplo n.º 13
0
def test_can_find_on_the_minute():
    find_any(times(), lambda x: x.second == 0)
Exemplo n.º 14
0
def test_can_find_midnight():
    find_any(times(), lambda x: x.hour == x.minute == x.second == 0)
Exemplo n.º 15
0
def test_can_generate_non_utc():
    times().filter(
        lambda d: assume(d.tzinfo) and d.tzinfo.zone != u'UTC'
    ).example()
Exemplo n.º 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
Exemplo n.º 17
0
def test_can_find_midnight():
    times().filter(lambda x: x.hour == x.minute == x.second == 0).example()
Exemplo n.º 18
0
def test_can_find_midnight():
    minimal(
        times(),
        lambda x: (x.hour == 0 and x.minute == 0 and x.second == 0),
    )
Exemplo n.º 19
0
def test_can_find_on_the_minute():
    times().filter(lambda x: x.second == 0).example()
Exemplo n.º 20
0
def test_can_find_on_the_minute():
    minimal(times(), lambda x: x.second != 0)
Exemplo n.º 21
0
def test_can_generate_naive_time():
    times(allow_naive=True).filter(lambda d: d.tzinfo is not None).example()
Exemplo n.º 22
0
def test_can_generate_naive_time():
    minimal(times(allow_naive=True), lambda d: not d.tzinfo)
Exemplo n.º 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)
Exemplo n.º 24
0
def test_can_generate_non_utc():
    minimal(
        times(),
        lambda d: assume(d.tzinfo) and d.tzinfo.zone != u'UTC')
Exemplo n.º 25
0
def test_can_find_midnight():
    find_any(times(), lambda x: x.hour == x.minute == x.second == 0)
Exemplo n.º 26
0
def test_can_find_on_the_minute():
    find_any(times(), lambda x: x.second == 0)
Exemplo n.º 27
0
def time_strategy(registry, type, context=None):
    return hsd.times()