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))
def test_can_generate_naive_time(): find_any(times(allow_naive=True), lambda d: d.tzinfo is not None)
@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)
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)
def test_can_generate_non_naive_time(): assert minimal( times(allow_naive=True), lambda d: d.tzinfo).tzinfo == pytz.UTC
def test_simplifies_towards_midnight(): d = minimal(times()) assert d.hour == 0 assert d.minute == 0 assert d.second == 0 assert d.microsecond == 0
def test_can_find_non_midnight(): assert minimal(times(), lambda x: x.hour != 0).hour == 1
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)
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)
@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
def test_can_generate_non_utc(): times().filter( lambda d: assume(d.tzinfo) and d.tzinfo.zone != u'UTC' ).example()
def test_can_find_on_the_minute(): find_any(times(), lambda x: x.second == 0)
def test_can_find_midnight(): find_any(times(), lambda x: x.hour == x.minute == x.second == 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
def test_can_find_midnight(): times().filter(lambda x: x.hour == x.minute == x.second == 0).example()
def test_can_find_midnight(): minimal( times(), lambda x: (x.hour == 0 and x.minute == 0 and x.second == 0), )
def test_can_find_on_the_minute(): times().filter(lambda x: x.second == 0).example()
def test_can_find_on_the_minute(): minimal(times(), lambda x: x.second != 0)
def test_can_generate_naive_time(): times(allow_naive=True).filter(lambda d: d.tzinfo is not None).example()
def test_can_generate_naive_time(): minimal(times(allow_naive=True), lambda d: not d.tzinfo)
def test_can_generate_non_utc(): minimal( times(), lambda d: assume(d.tzinfo) and d.tzinfo.zone != u'UTC')
def time_strategy(registry, type, context=None): return hsd.times()