async def test_mdinterval_reversed(freezer, dummy_local_datetime): freezer.move_to(dummy_local_datetime) result = await date.MDIntervalFunction([ literalvalues.LiteralValue(dummy_local_datetime.month + 1, ''), literalvalues.LiteralValue(dummy_local_datetime.day, ''), literalvalues.LiteralValue(dummy_local_datetime.month - 1, ''), literalvalues.LiteralValue(dummy_local_datetime.day, '') ]).eval(context={}) assert result == 0
async def test_bow_sunday_positive(freezer, dummy_local_datetime, local_tz_info): freezer.move_to(dummy_local_datetime) result = await date.BOWFunction([ literalvalues.LiteralValue(54, ''), literalvalues.LiteralValue(6, '') ]).eval(context={}) dt = datetime.datetime(2020, 3, 22, 0, 0, 0) dt = dt.astimezone(local_tz_info) assert result == dt.timestamp()
async def test_bow_sunday_negative(freezer, dummy_local_datetime, local_tz_info): freezer.move_to(dummy_local_datetime) result = await date.BOWFunction([ literalvalues.LiteralValue(-54, ''), literalvalues.LiteralValue(6, '') ]).eval() dt = datetime.datetime(2018, 2, 25, 0, 0, 0) dt = dt.astimezone(local_tz_info) assert result == dt.timestamp()
async def test_bow_sunday(freezer, dummy_local_datetime, literal_zero, local_tz_info): freezer.move_to(dummy_local_datetime) result = await date.BOWFunction( [literal_zero, literalvalues.LiteralValue(6, '')]).eval() dt = dummy_local_datetime.replace(day=dummy_local_datetime.day - dummy_local_datetime.weekday() - 1, hour=0, minute=0, second=0, microsecond=0) dt = dt.astimezone(local_tz_info) assert result == dt.timestamp()
async def test_bom_positive(freezer, dummy_local_datetime, dummy_timestamp, local_tz_info): freezer.move_to(dummy_local_datetime) result = await date.BOMFunction([literalvalues.LiteralValue(13, '')]).eval(context={}) dt = dummy_local_datetime.replace( year=dummy_local_datetime.year + 1, month=dummy_local_datetime.month + 1, day=1, hour=0, minute=0, second=0, microsecond=0 ) dt = dt.astimezone(local_tz_info) assert result == dt.timestamp()
async def test_mdinterval_limit(freezer, dummy_local_datetime): freezer.move_to(dummy_local_datetime) result = await date.MDIntervalFunction([ literalvalues.LiteralValue(dummy_local_datetime.month, ''), literalvalues.LiteralValue(dummy_local_datetime.day, ''), literalvalues.LiteralValue(dummy_local_datetime.month, ''), literalvalues.LiteralValue(dummy_local_datetime.day + 1, '') ]).eval() assert result == 1 result = await date.MDIntervalFunction([ literalvalues.LiteralValue(dummy_local_datetime.month, ''), literalvalues.LiteralValue(dummy_local_datetime.day - 1, ''), literalvalues.LiteralValue(dummy_local_datetime.month, ''), literalvalues.LiteralValue(dummy_local_datetime.day, '') ]).eval() assert result == 1
async def test_date(dummy_local_datetime, dummy_timestamp): result = await date.DateFunction([ literalvalues.LiteralValue(dummy_local_datetime.year, ''), literalvalues.LiteralValue(dummy_local_datetime.month, ''), literalvalues.LiteralValue(dummy_local_datetime.day, ''), literalvalues.LiteralValue(dummy_local_datetime.hour, ''), literalvalues.LiteralValue(dummy_local_datetime.minute, ''), literalvalues.LiteralValue(dummy_local_datetime.second, '') ]).eval(context={}) assert result == int(dummy_timestamp)
async def test_hmsinterval_reversed(freezer, dummy_local_datetime): freezer.move_to(dummy_local_datetime) result = await date.HMSIntervalFunction([ literalvalues.LiteralValue(dummy_local_datetime.hour + 1, ''), literalvalues.LiteralValue(dummy_local_datetime.minute, ''), literalvalues.LiteralValue(dummy_local_datetime.second, ''), literalvalues.LiteralValue(dummy_local_datetime.hour - 1, ''), literalvalues.LiteralValue(dummy_local_datetime.minute, ''), literalvalues.LiteralValue(dummy_local_datetime.second, '') ]).eval(context={}) assert result == 0
def literal_minus_pi(): return literalvalues.LiteralValue(-3.14159, '-3.14159')
def literal_minus_two(): return literalvalues.LiteralValue(-2, '-2')
def literal_minus_one(): return literalvalues.LiteralValue(-1, '-1')
def literal_one_thousand(): return literalvalues.LiteralValue(1000, '1000')
def literal_true(): return literalvalues.LiteralValue(True, 'true')
def literal_zero_point_five(): return literalvalues.LiteralValue(0.5, '0.5')
def literal_sixteen(): return literalvalues.LiteralValue(16, '16')
def literal_ten_point_fifty_one(): return literalvalues.LiteralValue(10.51, '10.51')
def literal_ten(): return literalvalues.LiteralValue(10, '10')
def literal_pi(): return literalvalues.LiteralValue(3.14159, '3.14159')
def literal_three(): return literalvalues.LiteralValue(3, '3')
def literal_two(): return literalvalues.LiteralValue(2, '2')
def literal_one(): return literalvalues.LiteralValue(1, '1')
def literal_minus_ten_point_fifty_one(): return literalvalues.LiteralValue(-10.51, '-10.51')
def literal_dummy_timestamp(dummy_timestamp): return literalvalues.LiteralValue(dummy_timestamp, str(dummy_timestamp))
async def test_hmsinterval_limit(freezer, dummy_local_datetime): freezer.move_to(dummy_local_datetime) result = await date.HMSIntervalFunction([ literalvalues.LiteralValue(dummy_local_datetime.hour, ''), literalvalues.LiteralValue(dummy_local_datetime.minute, ''), literalvalues.LiteralValue(dummy_local_datetime.second, ''), literalvalues.LiteralValue(dummy_local_datetime.hour, ''), literalvalues.LiteralValue(dummy_local_datetime.minute, ''), literalvalues.LiteralValue(dummy_local_datetime.second + 1, '') ]).eval() assert result == 1 result = await date.HMSIntervalFunction([ literalvalues.LiteralValue(dummy_local_datetime.hour, ''), literalvalues.LiteralValue(dummy_local_datetime.minute, ''), literalvalues.LiteralValue(dummy_local_datetime.second - 1, ''), literalvalues.LiteralValue(dummy_local_datetime.hour, ''), literalvalues.LiteralValue(dummy_local_datetime.minute, ''), literalvalues.LiteralValue(dummy_local_datetime.second, '') ]).eval() assert result == 1
async def test_mdinterval_months(freezer, dummy_local_datetime): freezer.move_to(dummy_local_datetime) result = await date.MDIntervalFunction([ literalvalues.LiteralValue(dummy_local_datetime.month - 1, ''), literalvalues.LiteralValue(1, ''), literalvalues.LiteralValue(dummy_local_datetime.month + 1, ''), literalvalues.LiteralValue(1, '') ]).eval() assert result == 1 result = await date.MDIntervalFunction([ literalvalues.LiteralValue(dummy_local_datetime.month - 2, ''), literalvalues.LiteralValue(1, ''), literalvalues.LiteralValue(dummy_local_datetime.month - 1, ''), literalvalues.LiteralValue(1, '') ]).eval() assert result == 0 result = await date.MDIntervalFunction([ literalvalues.LiteralValue(dummy_local_datetime.month + 1, ''), literalvalues.LiteralValue(1, ''), literalvalues.LiteralValue(dummy_local_datetime.month + 2, ''), literalvalues.LiteralValue(1, '') ]).eval() assert result == 0
def literal_zero(): return literalvalues.LiteralValue(0, '0')
async def test_hmsinterval_minutes(freezer, dummy_local_datetime): freezer.move_to(dummy_local_datetime) result = await date.HMSIntervalFunction([ literalvalues.LiteralValue(dummy_local_datetime.hour, ''), literalvalues.LiteralValue(dummy_local_datetime.minute - 1, ''), literalvalues.LiteralValue(0, ''), literalvalues.LiteralValue(dummy_local_datetime.hour, ''), literalvalues.LiteralValue(dummy_local_datetime.minute + 1, ''), literalvalues.LiteralValue(0, '') ]).eval(context={}) assert result == 1 result = await date.HMSIntervalFunction([ literalvalues.LiteralValue(dummy_local_datetime.hour, ''), literalvalues.LiteralValue(dummy_local_datetime.minute - 2, ''), literalvalues.LiteralValue(0, ''), literalvalues.LiteralValue(dummy_local_datetime.hour, ''), literalvalues.LiteralValue(dummy_local_datetime.minute - 1, ''), literalvalues.LiteralValue(0, '') ]).eval(context={}) assert result == 0 result = await date.HMSIntervalFunction([ literalvalues.LiteralValue(dummy_local_datetime.hour, ''), literalvalues.LiteralValue(dummy_local_datetime.minute + 1, ''), literalvalues.LiteralValue(0, ''), literalvalues.LiteralValue(dummy_local_datetime.hour, ''), literalvalues.LiteralValue(dummy_local_datetime.minute + 2, ''), literalvalues.LiteralValue(0, '') ]).eval(context={}) assert result == 0
def literal_two_hundreds(): return literalvalues.LiteralValue(200, '200')
def literal_one_hundred(): return literalvalues.LiteralValue(100, '100')
def literal_false(): return literalvalues.LiteralValue(False, 'false')