From e136c0f25bd95b47ef01dde4f3df04cc06558ebf Mon Sep 17 00:00:00 2001
From: Eric Duminil <eric.duminil@gmail.com>
Date: Thu, 4 Jul 2024 14:19:44 +0200
Subject: [PATCH] Writing more tests

---
 requirements.txt |  1 +
 test_zipcode.py  | 44 +++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/requirements.txt b/requirements.txt
index 0083c46..6842336 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -2,3 +2,4 @@ pyproj
 requests
 pyperclip
 tqdm
+shapely
diff --git a/test_zipcode.py b/test_zipcode.py
index 9766856..189ee2f 100644
--- a/test_zipcode.py
+++ b/test_zipcode.py
@@ -1,11 +1,53 @@
 import unittest
+import pyperclip
 from get_coordinates_by_zipcode import get_coordinates_by_zipcode
 
 
 class TestGetCoordinates(unittest.TestCase):
 
-    def test_get_mohringen(self):
+    def test_get_single_plz(self):
         coords = get_coordinates_by_zipcode(['70567'])
+        self.assertTrue(coords.startswith('POLYGON ((9.'))
+        self.assertTrue(' 48.7' in coords)
+        self.assertTrue(' 9.15' in coords)
+
+    def test_get_multiple_plz(self):
+        # Multiple PLZs
+        coords = get_coordinates_by_zipcode(['70567', '70569'])
+        self.assertTrue(coords.startswith('POLYGON ((9.'))
+        self.assertTrue(' 48.7' in coords)
+        self.assertTrue(' 9.15' in coords)
+
+    def test_get_multiple_disjoint_plz(self):
+        # Multiple PLZs, separate
+        coords = get_coordinates_by_zipcode(['70567', '10178'])
+        self.assertTrue(coords.startswith('MULTIPOLYGON ((('))
+        self.assertTrue(' 48.7' in coords)
+        self.assertTrue(' 9.15' in coords)
+        self.assertTrue(' 52.5' in coords)
+        self.assertTrue(' 13.4' in coords)
+
+    def test_get_plz_with_hole(self):
+        # 70469 missing in the middle
+        coords = get_coordinates_by_zipcode(['70469', '70193',
+                                             '70176', '70174', '70191'])
+        self.assertTrue(coords.startswith('POLYGON ((9'))
+        self.assertTrue('), (' in coords)
+
+    def test_get_coords_in_clipboard(self):
+        pyperclip.copy("")
+        self.assertEquals(pyperclip.paste(), "")
+        get_coordinates_by_zipcode(['70567'])
+        coords = pyperclip.paste()
+        self.assertTrue(coords.startswith('POLYGON ((9.'))
+        self.assertTrue(' 48.7' in coords)
+        self.assertTrue(' 9.15' in coords)
+
+    def test_get_unknown_plz(self):
+        # Incorrect PLZ
+        self.assertRaisesRegex(AttributeError, "no information could be found",
+                               get_coordinates_by_zipcode, ['1234567']
+                               )
 
 
 if __name__ == '__main__':
-- 
GitLab