Commit 862ff084 authored by Eric Duminil's avatar Eric Duminil
Browse files

Adding tests template

parent a1776570
......@@ -5,6 +5,7 @@
*.step
*.txt
*.pdf
*.pyc
cache
input
plz/plz-5stellig.geojson
......@@ -30,34 +30,34 @@ from shapely.ops import unary_union
INPUT_FOLDER = Path('plz')
PLZ_FILENAME = 'plz-5stellig.geojson'
PLZ_SHAPES = INPUT_FOLDER / PLZ_FILENAME
PLZ_SHAPE_FILE = INPUT_FOLDER / PLZ_FILENAME
def download_if_needed():
if not PLZ_SHAPES.exists():
def _download_plz_shapes_if_needed():
if not PLZ_SHAPE_FILE.exists():
from tqdm import tqdm
import requests
URL = "https://downloads.suche-postleitzahl.org/v2/public/" + PLZ_FILENAME
response = requests.get(URL, stream=True)
INPUT_FOLDER.mkdir(exist_ok=True)
with open(PLZ_SHAPES, "wb") as handle:
with open(PLZ_SHAPE_FILE, "wb") as handle:
for data in tqdm(response.iter_content(chunk_size=1024), unit='kB'):
handle.write(data)
def parse_data():
def _get_plz_shapes():
print("Parsing %s..." % PLZ_FILENAME)
download_if_needed()
_download_plz_shapes_if_needed()
try:
with open(PLZ_SHAPES) as f:
with open(PLZ_SHAPE_FILE) as f:
print(' Done')
return json.load(f)
except json.decoder.JSONDecodeError:
PLZ_SHAPES.unlink()
PLZ_SHAPE_FILE.unlink()
raise AttributeError(f"{PLZ_FILENAME} seems to be damaged. Removing it. Please try again!")
def get_plz(data, plz_patterns):
def _get_coordinates(data, plz_patterns):
geometries = []
for plz_pattern in plz_patterns:
found = False
......@@ -95,9 +95,9 @@ def get_plz(data, plz_patterns):
return wkt_polygon
def main(plzs):
data = parse_data()
get_plz(data, plzs)
def get_coordinates_by_zipcode(plzs):
plz_shapes = _get_plz_shapes()
return _get_coordinates(plz_shapes, plzs)
if __name__ == '__main__':
......@@ -105,4 +105,4 @@ if __name__ == '__main__':
parser.add_argument('plzs', metavar='PLZ', type=str, nargs='+',
help='desired PLZs')
args = parser.parse_args()
main(args.plzs)
get_coordinates_by_zipcode(args.plzs)
import unittest
import get_coordinates_by_zipcode
class TestClass(unittest.TestCase):
def test_method(self):
self.assertEqual('foo'.upper(), 'FOO')
get_coordinates_by_zipcode.get_coordinates_by_zipcode(['70567'])
if __name__ == '__main__':
unittest.main()
Markdown is supported
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