aboutsummaryrefslogtreecommitdiffstats
path: root/datamaps/tests
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2019-09-27 15:12:57 +0100
committerMatthew Lemon <lemon@matthewlemon.com>2019-09-27 15:12:57 +0100
commitd4272b28da76c2d1fe110d611ef08a445f11ceb2 (patch)
treeaf01f431bd39504bb2d9234c7c6a41879b95051f /datamaps/tests
initial commit
Diffstat (limited to '')
-rw-r--r--datamaps/tests/__init__.py0
-rw-r--r--datamaps/tests/conftest.py9
-rw-r--r--datamaps/tests/resources/.~lock.master.xlsx#1
-rw-r--r--datamaps/tests/resources/master.xlsxbin0 -> 5889 bytes
-rw-r--r--datamaps/tests/test_api.py10
-rw-r--r--datamaps/tests/test_cleanser.py41
-rw-r--r--datamaps/tests/test_quarter.py52
7 files changed, 113 insertions, 0 deletions
diff --git a/datamaps/tests/__init__.py b/datamaps/tests/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/datamaps/tests/__init__.py
diff --git a/datamaps/tests/conftest.py b/datamaps/tests/conftest.py
new file mode 100644
index 0000000..22f20bf
--- /dev/null
+++ b/datamaps/tests/conftest.py
@@ -0,0 +1,9 @@
+import os
+
+import pytest
+from pathlib import Path
+
+
+@pytest.fixture
+def master() -> Path:
+ return Path.cwd() / "tests" / "resources" / "master.xlsx"
diff --git a/datamaps/tests/resources/.~lock.master.xlsx# b/datamaps/tests/resources/.~lock.master.xlsx#
new file mode 100644
index 0000000..7fb98fe
--- /dev/null
+++ b/datamaps/tests/resources/.~lock.master.xlsx#
@@ -0,0 +1 @@
+,lemon,grafter.chutney.lan,27.09.2019 14:05,file:///home/lemon/.config/libreoffice/4; \ No newline at end of file
diff --git a/datamaps/tests/resources/master.xlsx b/datamaps/tests/resources/master.xlsx
new file mode 100644
index 0000000..bf5adf0
--- /dev/null
+++ b/datamaps/tests/resources/master.xlsx
Binary files differ
diff --git a/datamaps/tests/test_api.py b/datamaps/tests/test_api.py
new file mode 100644
index 0000000..273f984
--- /dev/null
+++ b/datamaps/tests/test_api.py
@@ -0,0 +1,10 @@
+import datetime
+
+from ..api import project_data_from_master
+
+
+def test_get_project_data(master):
+ master = project_data_from_master(master, 1, 2019)
+ assert master["Chutney Bridge.xlsm"]["Project/Programme Name"] == "Chutney Bridge Ltd"
+ assert master.quarter.quarter == 1
+ assert master.quarter.end_date == datetime.date(2019, 6, 30)
diff --git a/datamaps/tests/test_cleanser.py b/datamaps/tests/test_cleanser.py
new file mode 100644
index 0000000..9d6df1a
--- /dev/null
+++ b/datamaps/tests/test_cleanser.py
@@ -0,0 +1,41 @@
+import datetime
+from ..process.cleansers import Cleanser
+
+
+def test_cleaning_dot_date():
+ ds = "25.1.72"
+ ds_double = "25.01.72"
+ four_year = "25.01.1972"
+ c = Cleanser(ds)
+ c_double = Cleanser(ds_double)
+ c_four = Cleanser(four_year)
+ assert c.clean() == datetime.date(1972, 1, 25)
+ assert c_double.clean() == datetime.date(1972, 1, 25)
+ assert c_four.clean() == datetime.date(1972, 1, 25)
+
+
+def test_cleaning_slash_date():
+ ds = "25/1/72"
+ ds_double = "25/01/72"
+ four_year = "25/01/1972"
+ c = Cleanser(ds)
+ c_double = Cleanser(ds_double)
+ c_four = Cleanser(four_year)
+ assert c.clean() == datetime.date(1972, 1, 25)
+ assert c_double.clean() == datetime.date(1972, 1, 25)
+ assert c_four.clean() == datetime.date(1972, 1, 25)
+
+
+def test_em_dash_key():
+ contains_em_dash = 'Pre 14-15 BL – Income both Revenue and Capital'
+ c = Cleanser(contains_em_dash)
+ assert c.clean() == 'Pre 14-15 BL - Income both Revenue and Capital'
+
+
+def test_double_trailing_space():
+ contains_double_trailing = 'Pre 14-15 BL - Incoming both Revenue and Capital '
+ contains_single_trailing = 'Pre 14-15 BL - Incoming both Revenue and Capital '
+ c = Cleanser(contains_double_trailing)
+ assert c.clean() == 'Pre 14-15 BL - Incoming both Revenue and Capital'
+ c = Cleanser(contains_single_trailing)
+ assert c.clean() == 'Pre 14-15 BL - Incoming both Revenue and Capital'
diff --git a/datamaps/tests/test_quarter.py b/datamaps/tests/test_quarter.py
new file mode 100644
index 0000000..c5b1824
--- /dev/null
+++ b/datamaps/tests/test_quarter.py
@@ -0,0 +1,52 @@
+import datetime
+
+import pytest
+
+from ..core import Quarter
+
+
+def test_initialisation():
+ q = Quarter(1, 2017)
+ assert q.start_date == datetime.date(2017, 4, 1)
+ assert q.end_date == datetime.date(2017, 6, 30)
+ q = Quarter(2, 2017)
+ assert q.start_date == datetime.date(2017, 7, 1)
+ assert q.end_date == datetime.date(2017, 9, 30)
+ q = Quarter(4, 2017)
+ assert q.start_date == datetime.date(2018, 1, 1)
+ assert q.end_date == datetime.date(2018, 3, 31)
+
+
+def test_desc_string():
+ assert str(Quarter(1, 2013)) == "Q1 13/14"
+ assert str(Quarter(2, 2013)) == "Q2 13/14"
+ assert str(Quarter(3, 2013)) == "Q3 13/14"
+ assert str(Quarter(4, 2013)) == "Q4 13/14"
+
+ assert str(Quarter(1, 1998)) == "Q1 98/99"
+ assert str(Quarter(2, 1998)) == "Q2 98/99"
+ assert str(Quarter(3, 1998)) == "Q3 98/99"
+ assert str(Quarter(4, 1998)) == "Q4 98/99"
+
+ assert str(Quarter(1, 1999)) == "Q1 99/00"
+ assert str(Quarter(2, 1999)) == "Q2 99/00"
+ assert str(Quarter(3, 1999)) == "Q3 99/00"
+ assert str(Quarter(4, 1999)) == "Q4 99/00"
+
+
+def test_errors():
+ with pytest.raises(ValueError) as excinfo:
+ Quarter(5, 2017)
+ assert "A quarter must be either 1, 2, 3 or 4" in str(excinfo.value)
+
+ with pytest.raises(ValueError) as excinfo:
+ Quarter(3, 1921)
+ assert "Year must be between 1950 and 2100 - surely that will do?" in str(excinfo.value)
+
+ with pytest.raises(ValueError) as excinfo:
+ Quarter("3", 2016)
+ assert "A quarter must be either 1, 2, 3 or 4" in str(excinfo.value)
+
+ with pytest.raises(ValueError) as excinfo:
+ Quarter(3, "1921")
+ assert "Year must be between 1950 and 2100 - surely that will do?" in str(excinfo.value)