From 9a8918135f0444c120a2fcaacd1a33837d6cec50 Mon Sep 17 00:00:00 2001 From: Andrew Ekstedt Date: Sat, 29 Sep 2018 11:35:13 -0700 Subject: [PATCH] Region-prefix some locations identifiers, and add a test Unova Routes 19-23 were added in B/W 2 and i forgot to prefix them when we added the locations. Kalos Victory Road used to have a prefix but it got dropped when i re-ripped X/Y locations. Kalos Pokemon League gets a prefix too, since both Sinnoh and Alola also have Pokemon Leagues. Add a test to ensure that we don't forget again in the future. --- pokedex/data/csv/locations.csv | 14 +++++++------- pokedex/tests/test_database_sanity.py | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/pokedex/data/csv/locations.csv b/pokedex/data/csv/locations.csv index 214877f..e97060d 100644 --- a/pokedex/data/csv/locations.csv +++ b/pokedex/data/csv/locations.csv @@ -519,11 +519,11 @@ id,region_id,identifier 535,5,join-avenue 536,5,floccesy-town 537,5,lentimas-town -538,5,route-19 -539,5,route-20 -540,5,route-21 -541,5,route-22 -542,5,route-23 +538,5,unova-route-19 +539,5,unova-route-20 +540,5,unova-route-21 +541,5,unova-route-22 +542,5,unova-route-23 543,5,castelia-sewers 544,5,floccesy-ranch 545,5,virbank-complex @@ -638,8 +638,8 @@ id,region_id,identifier 654,6,dernière-way 655,6,kalos-route-22 656,6,detourner-way -657,6,victory-road -658,6,pokemon-league +657,6,kalos-victory-road +658,6,kalos-pokemon-league 659,6,kiloude-city 660,6,battle-maison 661,6,azure-bay diff --git a/pokedex/tests/test_database_sanity.py b/pokedex/tests/test_database_sanity.py index f5747ca..b65f20f 100644 --- a/pokedex/tests/test_database_sanity.py +++ b/pokedex/tests/test_database_sanity.py @@ -1,6 +1,8 @@ import pytest parametrize = pytest.mark.parametrize +import re + from sqlalchemy.orm import aliased, joinedload, lazyload from sqlalchemy.orm.exc import NoResultFound from sqlalchemy.sql import func @@ -93,3 +95,22 @@ def test_default_forms(session): pytest.fail("species %s has no default pokemon" % species.name) elif num_default_pokemon > 1: pytest.fail("species %s has %d default pokemon" % (species.name, num_default_pokemon)) + +ROUTE_RE = re.compile(ur'route-\d+') + +def test_location_identifiers(session): + """Check that location identifiers for some common locations are prefixed + with the region name, ala kalos-route-2""" + + q = session.query(tables.Location) + q = q.join(tables.Region) + q = q.options(lazyload('*')) + for loc in q: + if (loc.identifier in [u'victory-road', u'pokemon-league', u'safari-zone'] + or ROUTE_RE.match(loc.identifier)): + if loc.region: + region = loc.region.identifier.lower() + suggested_identifier = region + "-" + loc.identifier + pytest.fail("location %d: identifier %s should be prefixed with its region (e.g. %s)" % (loc.id, loc.identifier, suggested_identifier)) + else: + pytest.fail("location %d: identifier %s should be prefixed with its region" % (loc.id, loc.identifier))