Commit 101dc71b authored by Eric Duminil's avatar Eric Duminil
Browse files

Very basic download tests

parent 0a5d84d9
No related merge requests found
Showing with 50 additions and 2 deletions
+50 -2
......@@ -85,7 +85,7 @@ def coordinates_to_grid(longitude: float, latitude: float) -> tuple[int, int]:
return (x + 1, y)
def wkt_polygon_to_grid_coords(location_name: str, wkt_str: str) -> tuple[int, int, int, int]:
def wkt_polygon_to_bounding_box(location_name: str, wkt_str: str) -> tuple[int, int, int, int]:
"""Returns (x, y) of lower-left and bottom-right tiles, containing a given region."""
if 'POLYGON' not in wkt_str:
raise ValueError(f"wkt for {location_name} should be a WKT POLYGON or MULTIPOLYGON")
......@@ -262,7 +262,7 @@ def main(location_name: str, wkt_or_zipcode: str, download_only: bool = False,
wkt_str = get_wkt(wkt_or_zipcode)
# Get grid coordinates
x1, x2, y1, y2 = wkt_polygon_to_grid_coords(location_name, wkt_str)
x1, x2, y1, y2 = wkt_polygon_to_bounding_box(location_name, wkt_str)
# Download region
download_whole_region(output_folder, wkt_str, x1, x2, y1, y2)
......
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()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment