def test_keep_suffix(self) -> None: """Tests that the * suffix is preserved.""" relations = get_relations() relation = relations.get_relation("gazdagret") normalizers = relation.get_street_ranges() house_number = areas.normalize(relation, "1*", "Budaörs út", normalizers) self.assertEqual([i.get_number() for i in house_number], ["1*"]) house_number = areas.normalize(relation, "2", "Budaörs út", normalizers) self.assertEqual([i.get_number() for i in house_number], ["2"])
def test_separator_interval_parity(self) -> None: """Tests the 5-8 case: means just 5 and 8 as the parity doesn't match.""" relations = get_relations() relation = relations.get_relation("gazdagret") normalizers = relation.get_street_ranges() house_numbers = areas.normalize(relation, "5-8", "Budaörs út", normalizers) self.assertEqual([i.get_number() for i in house_numbers], ["5", "8"])
def test_separator_interval_interp_all(self) -> None: """Tests the 2-5 case: means implicit 3 and 4.""" relations = get_relations() relation = relations.get_relation("gazdagret") normalizers = relation.get_street_ranges() house_numbers = [i.get_number() for i in areas.normalize(relation, "2-5", "Hamzsabégi út", normalizers)] self.assertEqual(house_numbers, ["2", "3", "4", "5"])
def test_separator_semicolon(self) -> None: """Tests the case when ';' is a separator.""" relations = get_relations() relation = relations.get_relation("gazdagret") normalizers = relation.get_street_ranges() house_numbers = areas.normalize(relation, "1;2", "Budaörs út", normalizers) self.assertEqual([i.get_number() for i in house_numbers], ["1", "2"])
def test_separator_interval(self) -> None: """Tests the 2-6 case: means implicit 4.""" relations = get_relations() relation = relations.get_relation("gazdagret") normalizers = relation.get_street_ranges() house_numbers = areas.normalize(relation, "2-6", "Budaörs út", normalizers) self.assertEqual([i.get_number() for i in house_numbers], ["2", "4", "6"])
def test_nofilter(self) -> None: """Tests the case when there is no filter for this street.""" relations = get_relations() relation = relations.get_relation("gazdagret") normalizers = relation.get_street_ranges() house_numbers = areas.normalize(relation, "1", "Budaörs út", normalizers) self.assertEqual([i.get_number() for i in house_numbers], ["1"])
def test_not_a_number(self) -> None: """Tests the case when the house number is not a number.""" relations = get_relations() relation = relations.get_relation("gazdagret") normalizers = relation.get_street_ranges() house_numbers = areas.normalize(relation, "x", "Budaörsi út", normalizers) self.assertEqual(house_numbers, [])
def test_not_in_range(self) -> None: """Tests when the number is not in range.""" relations = get_relations() relation = relations.get_relation("gazdagret") normalizers = relation.get_street_ranges() house_numbers = areas.normalize(relation, "999", "Budaörsi út", normalizers) self.assertEqual(house_numbers, [])
def test_happy(self) -> None: """Tests the happy path.""" relations = get_relations() relation = relations.get_relation("gazdagret") normalizers = relation.get_street_ranges() house_numbers = areas.normalize(relation, "139", "Budaörsi út", normalizers) self.assertEqual([i.get_number() for i in house_numbers], ["139"])
def test_separator_comma(self) -> None: """Tests the case when ',' is a separator.""" relations = get_relations() relation = relations.get_relation("gazdagret") normalizers = relation.get_street_ranges() house_numbers = areas.normalize(relation, "2,6", "Budaörs út", normalizers) # Same as ";", no 4. self.assertEqual([i.get_number() for i in house_numbers], ["2", "6"])
def test_separator_interval_block4(self) -> None: """Tests the case where x-y is only partially useful: x is OK, but y is a suffix.""" relations = get_relations() relation = relations.get_relation("gazdagret") normalizers = relation.get_street_ranges() house_numbers = areas.normalize(relation, "42-1", "Budaörs út", normalizers) # No "1", just "42". self.assertEqual([i.get_number() for i in house_numbers], ["42"])
def test_separator_interval_block3(self) -> None: """Tests the case where x-y is nonsense: x is 0.""" relations = get_relations() relation = relations.get_relation("gazdagret") normalizers = relation.get_street_ranges() house_numbers = areas.normalize(relation, "0-42", "Budaörs út", normalizers) # No expansion like 0, 2, 4, etc. self.assertEqual([i.get_number() for i in house_numbers], ["42"])
def test_separator_interval_block2(self) -> None: """Tests the case where x-y is nonsense: y-x is too large.""" relations = get_relations() relation = relations.get_relation("gazdagret") normalizers = relation.get_street_ranges() house_numbers = areas.normalize(relation, "2-56", "Budaörs út", normalizers) # No expansions for 4, 6, etc. self.assertEqual([i.get_number() for i in house_numbers], ["2", "56"])
def test_not_in_range(self) -> None: """Tests when the number is not in range.""" with unittest.mock.patch('config.get_abspath', get_abspath): relations = get_relations() relation = relations.get_relation("gazdagret") normalizers = relation.get_street_ranges() house_numbers = areas.normalize(relation, "999", "Budaörsi út", normalizers) self.assertEqual(house_numbers, [])
def test_separator_interval_block(self) -> None: """Tests the case where x-y is nonsense: y is too large.""" relations = get_relations() relation = relations.get_relation("gazdagret") normalizers = relation.get_street_ranges() house_numbers = areas.normalize(relation, "2-2000", "Budaörs út", normalizers) # Make sure that we simply ignore 2000: it's larger than the default <998 filter and the # 2-2000 range would be too large. self.assertEqual([i.get_number() for i in house_numbers], ["2"])
def test_separator_interval_filter(self) -> None: """Tests the case where x-y is partially filtered out.""" relations = get_relations() relation = relations.get_relation("gazdagret") normalizers = relation.get_street_ranges() # filter is 137-165 house_numbers = areas.normalize(relation, "163-167", "Budaörsi út", normalizers) # Make sure there is no 167. self.assertEqual([i.get_number() for i in house_numbers], ["163", "165"])