Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Dynamic Exposure
OpenBuildingMap
spearhead
Commits
eb84e99a
Commit
eb84e99a
authored
Nov 01, 2021
by
Felix Delattre
Browse files
Added tests for diff analyzer
parent
72539dd1
Pipeline
#29744
failed with stage
in 1 minute and 41 seconds
Changes
6
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
.pre-commit-config.yaml
View file @
eb84e99a
...
...
@@ -34,3 +34,4 @@ repos:
rev
:
ecd1e81915cba81f1caa9544adfd188b37fe5deb
hooks
:
-
id
:
codespell
entry
:
codespell --skip="./tests/data/*.xml"
spearhead/diff_analyzer.py
View file @
eb84e99a
...
...
@@ -104,8 +104,7 @@ class DiffAnalyzer:
elif
isinstance
(
n
,
osmdiff
.
osm
.
osm
.
Relation
):
numbers
.
append
(
-
int
(
n
.
attribs
.
get
(
"id"
)))
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"""
...
...
spearhead/spearhead.py
View file @
eb84e99a
...
...
@@ -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
...
...
tests/conftest.py
View file @
eb84e99a
...
...
@@ -18,9 +18,22 @@
import
pytest
import
osmdiff
from
rabotnik
import
MessageBus
from
spearhead.configure
import
Configuration
@
pytest
.
fixture
()
def
config
():
yield
Configuration
(
"./tests/config.yml"
)
@
pytest
.
fixture
()
def
diff_provider
():
yield
osmdiff
.
AugmentedDiff
()
@
pytest
.
fixture
()
def
message_bus
():
yield
MessageBus
()
tests/data/augmented-diff-4749548.xml
0 → 100644
View file @
eb84e99a
This diff is collapsed.
Click to expand it.
tests/test_diff_analyzer.py
0 → 100644
View file @
eb84e99a
#!/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
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# 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 http://www.gnu.org/licenses/.
import
logging
import
osmdiff
import
random
import
pytest
from
spearhead.diff_analyzer
import
DiffAnalyzer
logger
=
logging
.
getLogger
()
@
pytest
.
fixture
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
@
pytest
.
fixture
def
diff_analyzer
(
diff_provider
,
config
,
message_bus
):
return
DiffAnalyzer
(
diff_provider
,
config
,
message_bus
)
@
pytest
.
mark
.
asyncio
async
def
test_get_list_of_new_diffs
(
diff_analyzer
):
numbers
=
await
diff_analyzer
.
get_list_of_new_diffs
()
assert
numbers
[
0
]
==
4749548
@
pytest
.
mark
.
asyncio
async
def
test_get_augmented_diff
(
augmented_diff
):
assert
isinstance
(
augmented_diff
,
osmdiff
.
AugmentedDiff
)
assert
augmented_diff
.
sequence_number
==
4749548
@
pytest
.
mark
.
asyncio
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
@
pytest
.
mark
.
asyncio
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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment