diff options
author | Matthew Lemon <matt@matthewlemon.com> | 2021-05-17 08:13:48 +0100 |
---|---|---|
committer | Matthew Lemon <matt@matthewlemon.com> | 2021-05-17 08:13:48 +0100 |
commit | 62617d6ef952c24e134b4bc403263ed990a42ec8 (patch) | |
tree | a991c2758d3acf306284e56ed617e00772a36287 | |
parent | a5b4f46b55ee39409126da978677f54e271060c1 (diff) |
fixed bug whereby month year was not used in creating quarter
-rw-r--r-- | datamaps/api/api.py | 4 | ||||
-rw-r--r-- | datamaps/tests/test_api.py | 31 | ||||
-rw-r--r-- | datamaps/tests/test_month.py | 41 |
3 files changed, 45 insertions, 31 deletions
diff --git a/datamaps/api/api.py b/datamaps/api/api.py index b6d8025..4073fbc 100644 --- a/datamaps/api/api.py +++ b/datamaps/api/api.py @@ -36,5 +36,9 @@ def project_data_from_master_month_api(master_file: str, month: int, year: int): else: pass # TODO: raise exception here + + # from that, we can work out what quarter year we are dealing with + if quarter == 4: + year = year - 1 m = Master(Quarter(quarter, year), master_file, month) return m diff --git a/datamaps/tests/test_api.py b/datamaps/tests/test_api.py index ecb30ac..4c73931 100644 --- a/datamaps/tests/test_api.py +++ b/datamaps/tests/test_api.py @@ -32,34 +32,3 @@ def test_get_project_data_using_month(master): assert m2.quarter.end_date == datetime.date(2021, 9, 30) assert m3.quarter.end_date == datetime.date(2021, 9, 30) assert m4.quarter.end_date == datetime.date(2021, 12, 31) - - -def test_quarter_objects_have_months(): - q = Quarter(1, 2021) - q2 = Quarter(4, 2021) - assert isinstance(q.months[0], Month) - assert q.months[0].start_date == datetime.date(2021, 4, 1) - assert q.months[1].start_date == datetime.date(2021, 5, 1) - assert q.months[2].start_date == datetime.date(2021, 6, 1) - with pytest.raises(IndexError): - q.months[4].start_date == datetime.date(2021, 6, 1) - assert q2.months[0].start_date == datetime.date(2022, 1, 1) - assert q2.months[1].start_date == datetime.date(2022, 2, 1) - assert q2.months[2].start_date == datetime.date(2022, 3, 1) - with pytest.raises(IndexError): - q2.months[4].start_date == datetime.date(2022, 6, 1) - - -def test_month(): - m1 = Month(1, 2021) - assert m1.name == "January" - m2 = Month(9, 2021) - assert m2.name == "September" - assert m2.start_date == datetime.date(2021, 9, 1) - assert m2.end_date == datetime.date(2021, 9, 30) - # test leap year - m3 = Month(2, 2024) - m4 = Month(2, 2028) - assert m3.end_date == datetime.date(2024, 2, 29) - assert m4.end_date == datetime.date(2028, 2, 29) - diff --git a/datamaps/tests/test_month.py b/datamaps/tests/test_month.py new file mode 100644 index 0000000..a533cd0 --- /dev/null +++ b/datamaps/tests/test_month.py @@ -0,0 +1,41 @@ +import datetime + +import pytest + +from ..core.temporal import Month, Quarter + + +def test_quarter_month_objects_leap_years(): + q = Quarter(4, 2023) + assert q.months[1].start_date == datetime.date(2024, 2, 1) + assert q.months[1].end_date == datetime.date(2024, 2, 29) + + +def test_quarter_objects_have_months(): + q = Quarter(1, 2021) + q2 = Quarter(4, 2021) + assert isinstance(q.months[0], Month) + assert q.months[0].start_date == datetime.date(2021, 4, 1) + assert q.months[1].start_date == datetime.date(2021, 5, 1) + assert q.months[2].start_date == datetime.date(2021, 6, 1) + with pytest.raises(IndexError): + q.months[4].start_date == datetime.date(2021, 6, 1) + assert q2.months[0].start_date == datetime.date(2022, 1, 1) + assert q2.months[1].start_date == datetime.date(2022, 2, 1) + assert q2.months[2].start_date == datetime.date(2022, 3, 1) + with pytest.raises(IndexError): + q2.months[4].start_date == datetime.date(2022, 6, 1) + + +def test_month(): + m1 = Month(1, 2021) + assert m1.name == "January" + m2 = Month(9, 2021) + assert m2.name == "September" + assert m2.start_date == datetime.date(2021, 9, 1) + assert m2.end_date == datetime.date(2021, 9, 30) + # test leap year + m3 = Month(2, 2024) + m4 = Month(2, 2028) + assert m3.end_date == datetime.date(2024, 2, 29) + assert m4.end_date == datetime.date(2028, 2, 29) |