fix parsing of operator in special phrases

Because of unstripped input, the operators wouldn't match.
This commit is contained in:
Sarah Hoffmann
2021-10-25 19:46:30 +02:00
parent 8e439d3dd9
commit 5a1c3dbea3
2 changed files with 22 additions and 7 deletions

View File

@@ -16,4 +16,5 @@ class SpecialPhrase():
# Hack around a bug where building=yes was imported with quotes into the wiki # Hack around a bug where building=yes was imported with quotes into the wiki
self.p_type = re.sub(r'\"|"', '', p_type.strip()) self.p_type = re.sub(r'\"|"', '', p_type.strip())
# Needed if some operator in the wiki are not written in english # Needed if some operator in the wiki are not written in english
p_operator = p_operator.strip()
self.p_operator = '-' if p_operator not in ('near', 'in') else p_operator self.p_operator = '-' if p_operator not in ('near', 'in') else p_operator

View File

@@ -30,7 +30,7 @@ def test_parse_xml(sp_wiki_loader, xml_wiki_content):
Should return the right SpecialPhrase objects. Should return the right SpecialPhrase objects.
""" """
phrases = sp_wiki_loader.parse_xml(xml_wiki_content) phrases = sp_wiki_loader.parse_xml(xml_wiki_content)
assert check_phrases_content(phrases) check_phrases_content(phrases)
def test_next(sp_wiki_loader): def test_next(sp_wiki_loader):
@@ -40,15 +40,29 @@ def test_next(sp_wiki_loader):
the 'en' special phrases. the 'en' special phrases.
""" """
phrases = next(sp_wiki_loader) phrases = next(sp_wiki_loader)
assert check_phrases_content(phrases) check_phrases_content(phrases)
def check_phrases_content(phrases): def check_phrases_content(phrases):
""" """
Asserts that the given phrases list contains Asserts that the given phrases list contains
the right phrases of the 'en' special phrases. the right phrases of the 'en' special phrases.
""" """
return len(phrases) > 1 \ assert set((p.p_label, p.p_class, p.p_type, p.p_operator) for p in phrases) ==\
and any(p.p_label == 'Embassies' and p.p_class == 'amenity' and p.p_type == 'embassy' {('Zip Line', 'aerialway', 'zip_line', '-'),
and p.p_operator == '-' for p in phrases) \ ('Zip Lines', 'aerialway', 'zip_line', '-'),
and any(p.p_label == 'Zip Line' and p.p_class == 'aerialway' and p.p_type == 'zip_line' ('Zip Line in', 'aerialway', 'zip_line', 'in'),
and p.p_operator == '-' for p in phrases) ('Zip Lines in', 'aerialway', 'zip_line', 'in'),
('Zip Line near', 'aerialway', 'zip_line', 'near'),
('Animal shelter', 'amenity', 'animal_shelter', '-'),
('Animal shelters', 'amenity', 'animal_shelter', '-'),
('Animal shelter in', 'amenity', 'animal_shelter', 'in'),
('Animal shelters in', 'amenity', 'animal_shelter', 'in'),
('Animal shelter near', 'amenity', 'animal_shelter', 'near'),
('Animal shelters near', 'amenity', 'animal_shelter', 'near'),
('Drinking Water near', 'amenity', 'drinking_water', 'near'),
('Water', 'amenity', 'drinking_water', '-'),
('Water in', 'amenity', 'drinking_water', 'in'),
('Water near', 'amenity', 'drinking_water', 'near'),
('Embassy', 'amenity', 'embassy', '-'),
('Embassys', 'amenity', 'embassy', '-'),
('Embassies', 'amenity', 'embassy', '-')}