Skip to content

Commit 75c747b

Browse files
committed
test-polygons: Fix handling of countries with multiple polygon ids
This aligns with behaviour in modules/Polygon.py, by: - iterating poly_id on index.py to generate each relation - calling get_poly.py with the full poly_id list
1 parent 39d179f commit 75c747b

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

tools/test-polygons.py

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,46 @@
1818

1919
print(' ', c.country, c.polygon_id)
2020

21+
# polygon_id can be an integer, or a list of integers
22+
polygon_id = c.polygon_id
23+
if isinstance(polygon_id, int):
24+
polygon_id = (polygon_id, )
25+
2126
# generate relation boundary
22-
try:
23-
r = requests.post(relation_generation_url, params={'id': c.polygon_id}, data={'refresh': 1}, timeout=120)
24-
except requests.exceptions.Timeout:
25-
print(" Timeout")
26-
fails.append([c.country, c.polygon_id, 'Timeout'])
27-
continue
28-
if r.status_code == 500:
29-
print(" Geom Error -", r.url)
30-
fails.append([c.country, c.polygon_id, 'Geom Error'])
31-
continue
32-
elif r.status_code != 200:
33-
print(" Error -", r.url)
34-
fails.append([c.country, c.polygon_id, 'Error'])
27+
relation_failing = False
28+
for poly_id in polygon_id:
29+
try:
30+
r = requests.post(relation_generation_url, params={'id': str(poly_id)}, data={'refresh': 1}, timeout=120)
31+
except requests.exceptions.Timeout:
32+
print(" Timeout")
33+
fails.append([c.country, polygon_id, 'Timeout'])
34+
relation_failing = True
35+
continue
36+
if r.status_code == 500:
37+
print(" Geom Error -", r.url)
38+
fails.append([c.country, polygon_id, 'Geom Error'])
39+
relation_failing = True
40+
continue
41+
elif r.status_code != 200:
42+
print(" Error -", r.url)
43+
fails.append([c.country, polygon_id, 'Error'])
44+
relation_failing = True
45+
continue
46+
47+
if relation_failing:
3548
continue
3649

3750
# get associated poly file
3851
try:
39-
r = requests.get(polygon_union_url, params={'id': c.polygon_id, 'params': 0}, timeout=120)
52+
poly_id = ",".join(map(str, polygon_id))
53+
r = requests.get(polygon_union_url, params={'id': poly_id, 'params': 0}, timeout=120)
4054
except requests.exceptions.Timeout:
4155
print(" Poly Timeout")
42-
fails.append([c.country, c.polygon_id, 'Poly Timeout'])
56+
fails.append([c.country, polygon_id, 'Poly Timeout'])
4357
continue
4458
if r.status_code != 200:
4559
print(" Bad geom -", r.url)
46-
fails.append([c.country, c.polygon_id, 'Bad geom'])
60+
fails.append([c.country, polygon_id, 'Bad geom'])
4761

4862
if len(fails) > 0:
4963
print(fails)

0 commit comments

Comments
 (0)