Commit 93f84b0f authored by Felix Delattre's avatar Felix Delattre
Browse files

Added tests for diff analyzer

parent cb7c105b
Pipeline #29729 failed with stage
in 1 minute and 35 seconds
......@@ -34,3 +34,4 @@ repos:
rev: ecd1e81915cba81f1caa9544adfd188b37fe5deb
- id: codespell
entry: codespell spearhead
......@@ -104,8 +104,7 @@ class DiffAnalyzer:
elif isinstance(n, osmdiff.osm.osm.Relation):
await self.file_handler.write_diff_report(augmented_diff.sequence_number, numbers)
await self._set_buildings_on_message_bus(numbers)
return numbers
async def _set_buildings_on_message_bus(self, numbers: list) -> None:
"""Set a list of building ids on the message bus"""
......@@ -71,8 +71,12 @@ async def get_changed_buildings(config: Configuration):
diff = await diff_analyzer.get_augmented_diff()
# Get identifiers of all buildings that have changed
await diff_analyzer.get_buildings(diff)
numbers = await diff_analyzer.get_buildings(diff)
await diff_analyzer.file_handler.write_diff_report(
diff.sequence_number, numbers
await diff_analyzer._set_buildings_on_message_bus(numbers)
await diff_analyzer.update_state(diff_number + 1)
# Wait until requesting more data
......@@ -18,9 +18,22 @@
import pytest
import osmdiff
from rabotnik import MessageBus
from spearhead.configure import Configuration
def config():
yield Configuration("./tests/config.yml")
def diff_provider():
yield osmdiff.AugmentedDiff()
def message_bus():
yield MessageBus()
This diff is collapsed.
#!/usr/bin/env python3
# Copyright (c) 2021:
# Helmholtz-Zentrum Potsdam Deutsches GeoForschungsZentrum GFZ
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see
import logging
import osmdiff
import random
import pytest
from spearhead.diff_analyzer import DiffAnalyzer
logger = logging.getLogger()
async def test_get_list_of_new_diffs(diff_analyzer):
numbers = await diff_analyzer.get_list_of_new_diffs()
assert numbers[0] == 4749548
async def test_get_augmented_diff(augmented_diff):
assert isinstance(augmented_diff, osmdiff.AugmentedDiff)
assert augmented_diff.sequence_number == 4749548
async def test_update_state(diff_analyzer):
await diff_analyzer.update_state(4749545)
state_number = await diff_analyzer.file_handler.read_state_file()
assert state_number == 4749545
await diff_analyzer.update_state(4749548)
state_number = await diff_analyzer.file_handler.read_state_file()
assert state_number == 4749548
async def test_get_buildings(diff_analyzer, augmented_diff):
buildings = await diff_analyzer.get_buildings(augmented_diff)
assert isinstance(random.choice(buildings), int)
assert len(buildings) == 356
def diff_analyzer(diff_provider, config, message_bus):
return DiffAnalyzer(diff_provider, config, message_bus)
async def augmented_diff(diff_analyzer):
augmented_diff = osmdiff.AugmentedDiff(file="./tests/data/augmented-diff-4749548.xml")
augmented_diff.sequence_number = 4749548
yield augmented_diff
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment