Skip to content

Commit 54420de

Browse files
committed
Clean up outdated tests and fix test config paths
1 parent b1f7afb commit 54420de

File tree

4 files changed

+101
-39
lines changed

4 files changed

+101
-39
lines changed

elevation_mapping_cupy/script/elevation_mapping_cupy/tests/test_elevation_mapping.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
from elevation_mapping_cupy import parameter, elevation_mapping
33
import cupy as cp
44
import numpy as np
5+
from pathlib import Path
6+
7+
8+
TEST_DIR = Path(__file__).resolve().parent
9+
PACKAGE_ROOT = TEST_DIR.parents[2]
10+
CORE_CONFIG_DIR = PACKAGE_ROOT / "config" / "core"
11+
WEIGHT_FILE = CORE_CONFIG_DIR / "weights.dat"
12+
PLUGIN_CONFIG_FILE = CORE_CONFIG_DIR / "plugin_config.yaml"
513

614

715
def encode_max(maxim, index):
@@ -22,8 +30,8 @@ def elmap_ex(add_lay, fusion_alg):
2230
fusion_algorithms = fusion_alg
2331
p = parameter.Parameter(
2432
use_chainer=False,
25-
weight_file="../../../config/weights.dat",
26-
plugin_config_file="../../../config/plugin_config.yaml",
33+
weight_file=str(WEIGHT_FILE),
34+
plugin_config_file=str(PLUGIN_CONFIG_FILE),
2735
)
2836
p.subscriber_cfg["front_cam"]["channels"] = additional_layer
2937
p.subscriber_cfg["front_cam"]["fusion"] = fusion_algorithms
@@ -96,6 +104,8 @@ def test_move(self, elmap_ex):
96104

97105
def test_exists_layer(self, elmap_ex, add_lay):
98106
for layer in add_lay:
107+
assert not elmap_ex.exists_layer(layer)
108+
elmap_ex.semantic_map.add_layer(layer)
99109
assert elmap_ex.exists_layer(layer)
100110

101111
def test_polygon_traversability(self, elmap_ex):

elevation_mapping_cupy/script/elevation_mapping_cupy/tests/test_parameter.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
import pytest
22
from elevation_mapping_cupy.parameter import Parameter
3+
from pathlib import Path
4+
5+
6+
TEST_DIR = Path(__file__).resolve().parent
7+
PACKAGE_ROOT = TEST_DIR.parents[2]
8+
CORE_CONFIG_DIR = PACKAGE_ROOT / "config" / "core"
9+
WEIGHT_FILE = CORE_CONFIG_DIR / "weights.dat"
10+
PLUGIN_CONFIG_FILE = CORE_CONFIG_DIR / "plugin_config.yaml"
311

412

513
def test_parameter():
614
param = Parameter(
715
use_chainer=False,
8-
weight_file="../../../config/weights.dat",
9-
plugin_config_file="../../../config/plugin_config.yaml",
16+
weight_file=str(WEIGHT_FILE),
17+
plugin_config_file=str(PLUGIN_CONFIG_FILE),
1018
)
1119
res = param.resolution
1220
param.set_value("resolution", 0.1)

elevation_mapping_cupy/script/elevation_mapping_cupy/tests/test_plugins.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
import pytest
22
from elevation_mapping_cupy import semantic_map, parameter
33
import cupy as cp
4-
import numpy as np
5-
from elevation_mapping_cupy.plugins.plugin_manager import PluginManager, PluginParams
4+
from elevation_mapping_cupy.plugins.plugin_manager import PluginManager
5+
from pathlib import Path
66

7-
plugin_path = "plugin_config.yaml"
7+
8+
TEST_DIR = Path(__file__).resolve().parent
9+
PACKAGE_ROOT = TEST_DIR.parents[2]
10+
CORE_CONFIG_DIR = PACKAGE_ROOT / "config" / "core"
11+
WEIGHT_FILE = CORE_CONFIG_DIR / "weights.dat"
12+
PLUGIN_PATH = TEST_DIR / "plugin_config.yaml"
813

914

1015
@pytest.fixture()
1116
def semmap_ex(add_lay, fusion_alg):
1217
p = parameter.Parameter(
13-
use_chainer=False, weight_file="../../../config/weights.dat", plugin_config_file=plugin_path,
18+
use_chainer=False, weight_file=str(WEIGHT_FILE), plugin_config_file=str(PLUGIN_PATH),
1419
)
1520
p.subscriber_cfg["front_cam"]["channels"] = add_lay
1621
p.subscriber_cfg["front_cam"]["fusion"] = fusion_alg
@@ -35,7 +40,7 @@ def semmap_ex(add_lay, fusion_alg):
3540
)
3641
def test_plugin_manager(semmap_ex, channels):
3742
manager = PluginManager(202)
38-
manager.load_plugin_settings(plugin_path)
43+
manager.load_plugin_settings(str(PLUGIN_PATH))
3944
elevation_map = cp.zeros((7, 202, 202)).astype(cp.float32)
4045
rotation = cp.eye(3, dtype=cp.float32)
4146
layer_names = [
@@ -49,20 +54,34 @@ def test_plugin_manager(semmap_ex, channels):
4954
]
5055
elevation_map[0] = cp.random.randn(202, 202)
5156
elevation_map[2] = cp.abs(cp.random.randn(202, 202))
52-
elevation_map[0]
53-
manager.layers[0]
5457
manager.update_with_name("min_filter", elevation_map, layer_names)
5558
manager.update_with_name("smooth_filter", elevation_map, layer_names)
56-
manager.update_with_name("semantic_filter", elevation_map, layer_names, semmap_ex, rotation)
57-
manager.update_with_name("semantic_traversability", elevation_map, layer_names, semmap_ex)
59+
manager.update_with_name(
60+
"sem_fil",
61+
elevation_map,
62+
layer_names,
63+
semmap_ex.semantic_map,
64+
semmap_ex.layer_names,
65+
rotation,
66+
semmap_ex.elements_to_shift,
67+
)
68+
manager.update_with_name(
69+
"sem_traversability",
70+
elevation_map,
71+
layer_names,
72+
semmap_ex.semantic_map,
73+
semmap_ex.layer_names,
74+
rotation,
75+
semmap_ex.elements_to_shift,
76+
)
5877
manager.get_map_with_name("smooth")
5978
for lay in manager.get_layer_names():
6079
manager.update_with_name(
6180
lay,
6281
elevation_map,
6382
layer_names,
6483
semmap_ex.semantic_map,
65-
semmap_ex.param,
84+
semmap_ex.layer_names,
6685
rotation,
6786
semmap_ex.elements_to_shift,
6887
)
Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,72 @@
1-
import pytest
2-
from elevation_mapping_cupy import semantic_map, parameter
31
import cupy as cp
4-
import numpy as np
2+
import pytest
3+
from pathlib import Path
4+
5+
from elevation_mapping_cupy import parameter, semantic_map
6+
7+
8+
TEST_DIR = Path(__file__).resolve().parent
9+
PACKAGE_ROOT = TEST_DIR.parents[2]
10+
CORE_CONFIG_DIR = PACKAGE_ROOT / "config" / "core"
11+
WEIGHT_FILE = CORE_CONFIG_DIR / "weights.dat"
12+
PLUGIN_CONFIG_FILE = CORE_CONFIG_DIR / "plugin_config.yaml"
513

614

715
@pytest.fixture()
816
def semmap_ex(sem_lay, fusion_alg):
917
p = parameter.Parameter(
1018
use_chainer=False,
11-
weight_file="../../../config/weights.dat",
12-
plugin_config_file="../../../config/plugin_config.yaml",
19+
weight_file=str(WEIGHT_FILE),
20+
plugin_config_file=str(PLUGIN_CONFIG_FILE),
1321
)
14-
for subs, value in p.subscriber_cfg.items():
15-
value["channels"] = sem_lay
16-
value["fusion"] = fusion_alg
22+
# Explicitly map test channels to the requested fusion modes.
23+
for layer, fusion in zip(sem_lay, fusion_alg):
24+
p.pointcloud_channel_fusions[layer] = fusion
1725
p.update()
18-
e = semantic_map.SemanticMap(p)
19-
return e
26+
return semantic_map.SemanticMap(p)
2027

2128

2229
@pytest.mark.parametrize(
23-
"sem_lay, fusion_alg,channels",
30+
"sem_lay,fusion_alg,channels",
2431
[
2532
(["feat_0", "feat_1"], ["average", "average"], ["feat_0"]),
2633
(["feat_0", "feat_1"], ["average", "average"], []),
27-
(["feat_0", "feat_1", "rgb"], ["average", "average", "color"], ["rgb", "feat_0"],),
28-
(["feat_0", "feat_1", "rgb"], ["class_average", "average", "color"], ["rgb", "feat_0"],),
29-
(["feat_0", "feat_1", "rgb"], ["class_bayesian", "average", "color"], ["rgb", "feat_0"],),
30-
(["feat_0", "feat_1", "rgb"], ["class_bayesian", "average", "color"], ["rgb", "feat_0", "feat_1"],),
31-
(["feat_0", "feat_1", "rgb"], ["class_bayesian", "class_max", "color"], ["rgb", "feat_0", "feat_1"],),
32-
(["max1", "max2", "rgb"], ["class_max", "class_max", "color"], ["rgb", "max1", "max2"],),
34+
(["feat_0", "feat_1", "rgb"], ["average", "average", "color"], ["rgb", "feat_0"]),
35+
(["feat_0", "feat_1", "rgb"], ["class_bayesian", "class_max", "color"], ["rgb", "feat_0", "feat_1"]),
36+
(["max1", "max2", "rgb"], ["class_max", "class_max", "color"], ["rgb", "max1", "max2"]),
3337
],
3438
)
35-
def test_fusion_of_pcl(semmap_ex, channels):
36-
fusion = semmap_ex.get_fusion_of_pcl(channels=channels)
37-
assert len(fusion) <= len(channels)
38-
assert len(fusion) > 0 or len(channels) == 0
39+
def test_get_fusion_current_api(semmap_ex, channels):
40+
process_channels, fusion = semmap_ex.get_fusion(
41+
channels=channels,
42+
channel_fusions=semmap_ex.param.pointcloud_channel_fusions,
43+
layer_specs=semmap_ex.layer_specs_points,
44+
)
45+
assert len(process_channels) == len(fusion)
3946
assert all(isinstance(item, str) for item in fusion)
4047

4148

4249
@pytest.mark.parametrize(
43-
"sem_lay, fusion_alg", [(["feat_0", "feat_1", "rgb"], ["average", "average", "color"]),],
50+
"sem_lay,fusion_alg,channels,target_fusion",
51+
[
52+
(["feat_0", "feat_1", "rgb"], ["average", "average", "color"], ["rgb", "feat_0"], "color"),
53+
(["max1", "max2", "rgb"], ["class_max", "class_max", "color"], ["rgb", "max1", "max2"], "class_max"),
54+
],
4455
)
45-
@pytest.mark.parametrize("channels", [["rgb"], ["rgb", "feat_0"], []])
46-
def test_indices_fusion(semmap_ex, channels, fusion_alg):
47-
pcl_indices, layer_indices = semmap_ex.get_indices_fusion(pcl_channels=channels, fusion_alg=fusion_alg[0])
56+
def test_get_indices_fusion_current_api(semmap_ex, channels, target_fusion):
57+
process_channels, _ = semmap_ex.get_fusion(
58+
channels=channels,
59+
channel_fusions=semmap_ex.param.pointcloud_channel_fusions,
60+
layer_specs=semmap_ex.layer_specs_points,
61+
)
62+
for channel in process_channels:
63+
if channel not in semmap_ex.layer_names:
64+
semmap_ex.add_layer(channel)
65+
66+
pcl_indices, layer_indices = semmap_ex.get_indices_fusion(
67+
pcl_channels=process_channels,
68+
fusion_alg=target_fusion,
69+
layer_specs=semmap_ex.layer_specs_points,
70+
)
71+
assert pcl_indices.dtype == cp.int32
72+
assert layer_indices.dtype == cp.int32

0 commit comments

Comments
 (0)