def test_constructor():
    a = Address('street', '3')
    assert a.street == 'street'
    assert a.housenumber == Housenumber('3')

    housenumber = Housenumber('42')
    a = Address('street', housenumber)
    assert a.street == 'street'
    assert a.housenumber == housenumber
Exemple #2
0
def test_add():
    file_path, keeper = create_keeper('keeper_addresses_to_be_ignored.csv')
    keeper.add_ignored(
        Address('Ignored Street', '1'),
        IgnoredAddressInformation(False, "building does not exist",
                                  ignore_date))

    ignored = CsvAddressListImport.read_to_be_ignored(file_path)
    assert len(ignored) == 1
    assert ignored[Address('Ignored Street',
                           '1')] == IgnoredAddressInformation(
                               False, "building does not exist", ignore_date)
    def get_addresses(row) -> list:
        street = row.get('addr:street')
        if not isinstance(street, str):
            street = row.get('addr:place', "")
        housenumber_string = str(row['addr:housenumber'])
        try:
            housenumber = Housenumber(housenumber_string)
            return [Address(street, housenumber)]

        except InvalidHousenumber as i:
            housenumbers = HousenumberRangeExpander.expand(housenumber_string)
            if len(housenumbers) == 0:
                raise i
            return [Address(street, h) for h in housenumbers]
Exemple #4
0
def test_diff():
    diff: AddressDiff = create_diff()

    assert len(diff.matches) == 3
    assert len(diff.missing) == 2
    assert len(diff.surplus) == 2
    assert diff.num_matches == 3
    assert diff.num_missing_not_ignored == 1
    assert diff.num_surplus_not_ignored == 1
    assert round(abs(diff.coverage_in_percent - 75.0), 1) == 0

    assert diff.matches[Address('Identical Street', '1')] == MatchInformation(
        OsmPrimitive('way', 1), Coordinate(1.1, 1.2))
    assert diff.matches[Address('Identical Street', '7')] == MatchInformation(
        OsmPrimitive('way', 7), Coordinate(7.1, 7.2))
    assert diff.matches[Address('Identical Street', '13')] == MatchInformation(
        OsmPrimitive('way', 13), Coordinate(13.1, 13.2))
    assert diff.missing[Address('Missing Street',
                                '2')] == MissingAddressInformation(
                                    Coordinate(2.1, 2.2), None)
    assert diff.missing[Address('Missing Street', '3')] == \
           MissingAddressInformation(Coordinate(3.1, 3.2), IgnoredAddressInformation(False, 'building does not exist', ignore_date))
    assert diff.surplus[0] == (Address('Surplus Street', '4'),
                               SurplusInformation(
                                   OsmPrimitive('node', 31),
                                   IgnoredAddressInformation(
                                       True, 'building does exist',
                                       ignore_date)))
    assert diff.surplus[1] == (Address('Surplus Street', '3'),
                               SurplusInformation(OsmPrimitive('way', 32),
                                                  None))

    return diff
def test_import():
    addresses = OverpassAddressListImport().read(349628081)  # industrial area in Leonberg, with relatively few addresses
    assert isinstance(addresses, list)
    assert len(addresses) >= 8
    assert (Address('Am Längenbühl', '12'), OsmPrimitive('way', 684944733)) in addresses
    for (a, p) in addresses:
        assert a.street != ""
        assert isinstance(a.housenumber, Housenumber)
        assert p.type in ['node', 'way', 'relation']
        assert isinstance(p.id, int)
Exemple #6
0
def test_remove():
    file_path, keeper = create_keeper(
        'keeper_addresses_to_be_ignored_not_anymore.csv')
    address = Address('Ignored Street', '1')
    keeper.add_ignored(
        address,
        IgnoredAddressInformation(False, "building does not exist",
                                  ignore_date))
    keeper.remove_ignored(address)

    ignored = CsvAddressListImport.read_to_be_ignored(file_path)
    assert len(ignored) == 0
Exemple #7
0
def create_diff():
    address_diff = AddressDiffComputation()
    reference = {
        Address('Identical Street', '1'): Coordinate(1.1, 1.2),
        Address('Identical Street', '7'): Coordinate(7.1, 7.2),
        Address('Identical Street', '13'): Coordinate(13.1, 13.2),
        Address('Missing Street', '2'): Coordinate(2.1, 2.2),
        Address('Missing Street', '2'):
        Coordinate(2.1, 2.2),  # duplicate in reference set
        Address('Missing Street', '3'): Coordinate(3.1, 3.2)
    }
    actual = [(Address('Identical Street', '1'), OsmPrimitive('way', 1)),
              (Address('Identical Street', '7'), OsmPrimitive('way', 7)),
              (Address('Identical Street', '13'), OsmPrimitive('way', 13)),
              (Address('Surplus Street', '4'), OsmPrimitive('node', 31)),
              (Address('Surplus Street', '3'), OsmPrimitive('way', 32))
              ]  # way and node with same address, to be reported twice
    ignored = {
        Address('Missing Street', '3'):
        IgnoredAddressInformation(False, 'building does not exist',
                                  ignore_date),
        Address('Surplus Street', '4'):
        IgnoredAddressInformation(True, 'building does exist', ignore_date)
    }

    diff: AddressDiff = address_diff.compute(reference, actual, ignored)
    return diff
def test_str():
    a = Address('street', '42')
    assert str(a) == 'street 42'
def test_eq():
    assert Address('street', '3') != Housenumber('42')