[test] refactor test execution, add test input/output events
Browse files
src/io/coordinates_pixel_conversion.py
CHANGED
@@ -56,8 +56,3 @@ def get_latlng_to_pixel_coordinates(latlng_origin_ne, latlng_origin_sw, latlng_c
|
|
56 |
point = PixelCoordinate(x=diff_coord_x, y=diff_coord_y)
|
57 |
app_logger.info(f"point type - {k}: {point}.")
|
58 |
return point
|
59 |
-
|
60 |
-
|
61 |
-
def get_latlng_coords_list(latlng_point, k: str):
|
62 |
-
latlng_current_point = latlng_point[k]
|
63 |
-
return [latlng_current_point["lat"], latlng_current_point["lng"]]
|
|
|
56 |
point = PixelCoordinate(x=diff_coord_x, y=diff_coord_y)
|
57 |
app_logger.info(f"point type - {k}: {point}.")
|
58 |
return point
|
|
|
|
|
|
|
|
|
|
tests/__init__.py
CHANGED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from src import PROJECT_ROOT_FOLDER
|
2 |
+
|
3 |
+
|
4 |
+
TEST_ROOT_FOLDER = PROJECT_ROOT_FOLDER / "tests"
|
5 |
+
TEST_EVENTS_FOLDER = TEST_ROOT_FOLDER / "events"
|
tests/events/get_latlng2pixel_projection.json
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"europe": {
|
3 |
+
"input": {"latlng": {"lat": 55.82499925397549, "lng": 30.55813798557972}},
|
4 |
+
"output": {"x": 149.73023145641224, "y": 79.93873304907419}
|
5 |
+
},
|
6 |
+
"north_america": {
|
7 |
+
"input": {"latlng": {"lat": 55.73904872165355, "lng": -88.38855385872797}},
|
8 |
+
"output": {"x": 65.14591725601566, "y": 80.04742192145312}
|
9 |
+
},
|
10 |
+
"south_america": {
|
11 |
+
"input": {"latlng": {"lat": -28.07197941598981, "lng": -81.47485480086976}},
|
12 |
+
"output": {"x": 70.06232547493705, "y": 148.8124992861222}
|
13 |
+
},
|
14 |
+
"oceania": {
|
15 |
+
"input": {"latlng": {"lat": -42.10127784960304, "lng": 147.42782020699818}},
|
16 |
+
"output": {"x": 232.8375610360876, "y": 161.06542832667049}
|
17 |
+
}
|
18 |
+
}
|
tests/events/get_point_latlng_to_pixel_coordinates.json
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"europe": {
|
3 |
+
"input": {
|
4 |
+
"latlng": { "lat": 38.26837671763853, "lng": 13.640947603420843 },
|
5 |
+
"zoom": 10
|
6 |
+
},
|
7 |
+
"output": { "x": 141005, "y": 100867 }
|
8 |
+
},
|
9 |
+
"north_america": {
|
10 |
+
"input": {
|
11 |
+
"latlng": { "lat": 49.582282020151446, "lng": -114.91703409765535 },
|
12 |
+
"zoom": 7
|
13 |
+
},
|
14 |
+
"output": { "x": 5923, "y": 11171 }
|
15 |
+
},
|
16 |
+
"south_america": {
|
17 |
+
"input": {
|
18 |
+
"latlng": { "lat": -32.52828619080139, "lng": -73.03714474717113 },
|
19 |
+
"zoom": 7
|
20 |
+
},
|
21 |
+
"output": { "x": 9735, "y": 19517 }
|
22 |
+
},
|
23 |
+
"oceania": {
|
24 |
+
"input": {
|
25 |
+
"latlng": { "lat": -52.32191088594772, "lng": 65.30273437500001 },
|
26 |
+
"zoom": 4
|
27 |
+
},
|
28 |
+
"output": { "x": 2791, "y": 2749 }
|
29 |
+
}
|
30 |
+
}
|
tests/io/test_coordinates_pixel_conversion.py
CHANGED
@@ -1,54 +1,33 @@
|
|
|
|
1 |
from unittest import TestCase
|
2 |
|
|
|
|
|
3 |
|
4 |
-
class Test(TestCase):
|
5 |
-
def test_get_latlng2pixel_projection(self):
|
6 |
-
from src.io.coordinates_pixel_conversion import get_latlng2pixel_projection
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
assert output == {"x": 65.14591725601566, "y": 80.04742192145312}
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
23 |
|
24 |
def test_get_point_latlng_to_pixel_coordinates(self):
|
25 |
-
|
26 |
-
|
27 |
-
# europa
|
28 |
-
output = get_point_latlng_to_pixel_coordinates(
|
29 |
-
latlng={"lat": 38.26837671763853, "lng": 13.640947603420843},
|
30 |
-
zoom=10
|
31 |
-
)
|
32 |
-
assert output == {"x": 141005, "y": 100867}
|
33 |
-
|
34 |
-
# nord america
|
35 |
-
output = get_point_latlng_to_pixel_coordinates(
|
36 |
-
latlng={"lat": 49.582282020151446, "lng": -114.91703409765535},
|
37 |
-
zoom=7
|
38 |
-
)
|
39 |
-
assert output == {"x": 5923, "y": 11171}
|
40 |
-
|
41 |
-
# sud america
|
42 |
-
output = get_point_latlng_to_pixel_coordinates(
|
43 |
-
latlng={"lat": -32.52828619080139, "lng": -73.03714474717113}, zoom=7
|
44 |
-
)
|
45 |
-
assert output == {"x": 9735, "y": 19517}
|
46 |
-
|
47 |
-
# tasmania
|
48 |
-
output = get_point_latlng_to_pixel_coordinates(
|
49 |
-
latlng={"lat": -52.32191088594772, "lng": 65.30273437500001}, zoom=4
|
50 |
-
)
|
51 |
-
assert output == {"x": 2791, "y": 2749}
|
52 |
|
53 |
# def test_get_latlng_to_pixel_coordinates(self):
|
54 |
# self.fail()
|
|
|
1 |
+
import json
|
2 |
from unittest import TestCase
|
3 |
|
4 |
+
from src.io.coordinates_pixel_conversion import get_latlng2pixel_projection, get_point_latlng_to_pixel_coordinates
|
5 |
+
from tests import TEST_EVENTS_FOLDER
|
6 |
|
|
|
|
|
|
|
7 |
|
8 |
+
names_fn_dict = {
|
9 |
+
"get_latlng2pixel_projection": get_latlng2pixel_projection,
|
10 |
+
"get_point_latlng_to_pixel_coordinates": get_point_latlng_to_pixel_coordinates
|
11 |
+
}
|
12 |
+
|
13 |
|
14 |
+
def test_fn_reading_json_inputs_outputs(name_fn):
|
15 |
+
fn = names_fn_dict[name_fn]
|
|
|
16 |
|
17 |
+
with open(TEST_EVENTS_FOLDER / f"{name_fn}.json") as tst_json:
|
18 |
+
inputs_outputs = json.load(tst_json)
|
19 |
+
for k, input_output in inputs_outputs.items():
|
20 |
+
print(f"k:{k}.")
|
21 |
+
output = fn(**input_output["input"])
|
22 |
+
assert output == input_output["output"]
|
23 |
|
24 |
+
|
25 |
+
class Test(TestCase):
|
26 |
+
def test_get_latlng2pixel_projection(self):
|
27 |
+
test_fn_reading_json_inputs_outputs("get_latlng2pixel_projection")
|
28 |
|
29 |
def test_get_point_latlng_to_pixel_coordinates(self):
|
30 |
+
test_fn_reading_json_inputs_outputs("get_point_latlng_to_pixel_coordinates")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
# def test_get_latlng_to_pixel_coordinates(self):
|
33 |
# self.fail()
|