Skip to content

Commit 9958ca7

Browse files
committed
Parameterize estimator strategy to facilitate manual testing
1 parent 6385b23 commit 9958ca7

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

tests/conftest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@
1818
import pytest
1919

2020

21+
# 3D gripping point detection strategy
22+
def pytest_addoption(parser):
23+
parser.addoption(
24+
"--strategy", action="store", default="centroid", help="Gripping point strategy"
25+
)
26+
27+
28+
@pytest.fixture
29+
def strategy(request):
30+
return request.config.getoption("--strategy")
31+
32+
2133
@pytest.fixture
2234
def test_config_toml():
2335
"""

tests/tools/ros2/test_gripping_points.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
The demo app and rivz2 need to be started before running the test. The test will fail if the gripping points are not found.
2323
2424
Usage:
25-
pytest tests/tools/ros2/test_gripping_points.py::test_gripping_points_manipulation_demo -m "" -s -v
25+
pytest tests/tools/ros2/test_gripping_points.py::test_gripping_points_manipulation_demo -m "manual" -s -v --strategy <strategy>
2626
"""
2727

2828
import time
@@ -246,14 +246,9 @@ def save_annotated_image(
246246
cv2.imwrite(filename, annotated_image)
247247

248248

249-
def main(config_name: str = "manipulation-demo", test_object: str = "cube"):
249+
def main(config: dict, test_object: str = "cube", strategy: str = None):
250250
"""Enhanced test with visualization and better error handling."""
251251

252-
# Get test configuration
253-
config = TEST_CONFIGS[config_name]
254-
255-
print(f"Config: {config_name}")
256-
257252
# Initialize ROS2
258253
rclpy.init()
259254
connector = ROS2Connector(executor_type="single_threaded")
@@ -273,7 +268,9 @@ def main(config_name: str = "manipulation-demo", test_object: str = "cube"):
273268
algo_config = config["algorithms"]
274269

275270
# Create gripping estimator with strategy-specific parameters
276-
estimator_config = algo_config["estimator"]
271+
estimator_config = algo_config["estimator"].copy()
272+
if strategy:
273+
estimator_config["strategy"] = strategy
277274
gripping_estimator = GrippingPointEstimator(**estimator_config)
278275

279276
# Create point cloud filter
@@ -297,7 +294,9 @@ def main(config_name: str = "manipulation-demo", test_object: str = "cube"):
297294
print(f"elapsed time: {time.time() - start_time} seconds")
298295

299296
# Test the tool directly
300-
print(f"\nTesting GetGrippingPointTool with object '{test_object}'")
297+
print(
298+
f"\nTesting GetGrippingPointTool with object '{test_object}', strategy '{strategy}'"
299+
)
301300

302301
result = gripping_tool._run(test_object)
303302
gripping_points = extract_gripping_points(result)
@@ -321,7 +320,7 @@ def main(config_name: str = "manipulation-demo", test_object: str = "cube"):
321320
)
322321
print("✅ Debug data published")
323322

324-
annotated_image_path = f"{test_object}_gripping_points.jpg"
323+
annotated_image_path = f"{test_object}_{strategy}_gripping_points.jpg"
325324
save_annotated_image(
326325
connector, gripping_points, config, annotated_image_path
327326
)
@@ -340,12 +339,14 @@ def main(config_name: str = "manipulation-demo", test_object: str = "cube"):
340339

341340

342341
@pytest.mark.manual
343-
def test_gripping_points_manipulation_demo():
342+
def test_gripping_points_manipulation_demo(strategy):
344343
"""Manual test requiring manipulation-demo app to be started."""
345-
main("manipulation-demo", "apple")
344+
config = TEST_CONFIGS["manipulation-demo"]
345+
main(config, "cube", strategy)
346346

347347

348348
@pytest.mark.manual
349-
def test_gripping_points_maciej_demo():
349+
def test_gripping_points_maciej_demo(strategy):
350350
"""Manual test requiring demo app to be started."""
351-
main("maciej-test-demo", "box")
351+
config = TEST_CONFIGS["maciej-test-demo"]
352+
main(config, "box", strategy)

0 commit comments

Comments
 (0)