test: add test suite (#7)

* add pre-commit hook
* improve logging of inconsistent data
This commit is contained in:
Felix Spöttel
2022-07-04 13:54:07 +02:00
committed by GitHub
parent 1c5d0f649e
commit d252c6b8f3
17 changed files with 435 additions and 72 deletions

30
tests/encoding.py Normal file
View File

@@ -0,0 +1,30 @@
from geoclustering.clustering import cluster_locations
from geoclustering.encoding import encode_clusters
from tests.helpers import read_fixture_csv, read_fixture_content
df = read_fixture_csv("clustering.csv")
def test_encoders():
clusters = {
0: [
{"id": 1, "name": "Alice", "lat": 52.523955, "lon": 13.442362},
{"id": 2, "name": "Bob", "lat": 52.526659, "lon": 13.448097},
],
1: [
{"id": 3, "name": "Carol", "lat": 52.525626, "lon": 13.419246},
{
"id": 4,
"name": "Dan",
"lat": 52.52443559865125,
"lon": 13.41261723049818,
},
],
}
res = encode_clusters(clusters)
assert res["string"] == read_fixture_content("snapshots/result.txt")
assert res["json"] == read_fixture_content("snapshots/result.json")
assert res["geojson"] == read_fixture_content("snapshots/result.geojson")