test_download_lod2.py 1.74 KiB
import unittest
import tempfile
import shutil
from pathlib import Path
import download_LoD2_from_LGL_BW as bw_data
class TestUtils(unittest.TestCase):
    def test_simstadt_is_available(self):
        self.assertIsNotNone(bw_data.find_simstadt_folder(),
                             "SimStadt folder should be on the Desktop in order for tests to run"
    def test_coordinates_to_grid(self):
        self.assertEqual(bw_data.coordinates_to_grid(9.180, 48.778),
                         (513, 5402))  # Stuttgart - Schloßplatz
        self.assertEqual(bw_data.coordinates_to_grid(7.853, 47.990),
                         (413, 5314))  # Freiburg - Dreisam
    def test_get_bounding_box(self):
        freiburg_to_stuttgart = "POLYGON ((7.853 47.990, 9.180 48.778, 7.853 47.990))"
        self.assertEqual(bw_data.wkt_polygon_to_bounding_box("Just a line", freiburg_to_stuttgart),
                         (413, 513, 5314, 5402))
class TestGetOpenData(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.tempFolder = Path(tempfile.mkdtemp())
    def test_get_schlossplatz(self):
        # Stuttgart - Schloßplatz
        stuttgart_wkt = "POLYGON ((9.179206 48.779454, 9.179292 48.777644, 9.178498 48.776753, 9.18118 48.775933, 9.181952 48.77705, 9.182768 48.77862, 9.179206 48.779454))"
        bw_data.main("Schlossplatz", stuttgart_wkt)
    def test_get_schwarzwald(self):
        # Reichental
        reichental_wkt = "POLYGON ((8.424282 48.745889, 8.381882 48.737286, 8.382397 48.721773, 8.439903 48.726869, 8.424282 48.745889))"
        bw_data.main("Reichental", reichental_wkt)
    @classmethod
    def tearDownClass(cls):
        shutil.rmtree(cls.tempFolder)
if __name__ == '__main__':
    unittest.main()