test_zipcode.py 1.94 KB
Newer Older
Eric Duminil's avatar
Eric Duminil committed
1
import unittest
Eric Duminil's avatar
Eric Duminil committed
2
import pyperclip
3
from get_coordinates_by_zipcode import get_coordinates_by_zipcode
Eric Duminil's avatar
Eric Duminil committed
4
5


6
class TestGetCoordinates(unittest.TestCase):
Eric Duminil's avatar
Eric Duminil committed
7

Eric Duminil's avatar
Eric Duminil committed
8
    def test_get_single_plz(self):
9
        coords = get_coordinates_by_zipcode(['70567'])
Eric Duminil's avatar
Eric Duminil committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
        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']
                               )
Eric Duminil's avatar
Eric Duminil committed
51
52
53
54


if __name__ == '__main__':
    unittest.main()