def test_parse_formula_current_date_ymd(): current_date = datetime.datetime.strptime("2019-12-30", "%Y-%m-%d").date() assert "2019-12-30" == parse_formula("CURRENT_DATE", current_date) assert "2019-12-31" == parse_formula("CURRENT_DATE+1", current_date) assert "2019-12-31 00:00:00" == parse_formula( "CURRENT_DATE + 1", current_date, date_format="%Y-%m-%d 00:00:00") assert "2019-12-31 23:59:59" == parse_formula( "CURRENT_DATE + 1", current_date, date_format="%Y-%m-%d 23:59:59")
def test_parse_formula_end_current_month_ymd(): current_date = datetime.datetime.strptime("2019-12-30", "%Y-%m-%d").date() assert "2019-12-31" == parse_formula("END_CURRENT_MONTH", current_date) assert "2020-01-31" == parse_formula("END_CURRENT_MONTH+1", current_date) assert "2019-11-30 00:00:00" == parse_formula( "END_CURRENT_MONTH-1", current_date, date_format="%Y-%m-%d 00:00:00") assert "2019-11-30 23:59:59" == parse_formula( "END_CURRENT_MONTH - 1 ", current_date, date_format="%Y-%m-%d 23:59:59")
def test_parse_formula_start_current_month_ymd(): current_date = datetime.datetime.strptime("2019-12-30", "%Y-%m-%d").date() assert "2019-12-01" == parse_formula("START_CURRENT_MONTH", current_date) assert "2020-01-01" == parse_formula("START_CURRENT_MONTH+1", current_date) assert "2020-01-01 00:00:00" == parse_formula( "START_CURRENT_MONTH+1", current_date, date_format="%Y-%m-%d 00:00:00") assert "2020-01-01 23:59:59" == parse_formula( "START_CURRENT_MONTH + 1", current_date, date_format="%Y-%m-%d 23:59:59")
def test_parse_parameter(): current_date = datetime.datetime.strptime("2019-12-30", "%Y-%m-%d").date() assert "2019-12-30" == parse_parameter("2019-12-30", current_date) assert "2019-12-31" == parse_formula("2019-12-31", current_date) assert "2019-12-31 00:00:00" == parse_formula( "2019-12-31 00:00:00", current_date, date_format="%Y-%m-%d 00:00:00") assert "2019-12-31 23:59:59" == parse_formula( "2019-12-31 23:59:59", current_date, date_format="%Y-%m-%d 23:59:59") assert "field1" == parse_parameter("field1", current_date) assert "55" == parse_parameter("55", current_date) assert "55.2" == parse_parameter("55.2", current_date) assert "" == parse_parameter("", current_date) assert parse_parameter(False, current_date) is False