Skip to content

Commit

Permalink
[examples] Fix some smoke test path snafus (#21452)
Browse files Browse the repository at this point in the history
Hard-coding paths to runfiles is incompatible with bzlmod. We should
always use python.runfiles, or (in the case of acrobot) just use our
simple add_test_rule pattern.
  • Loading branch information
jwnimmer-tri authored May 20, 2024
1 parent 2959d85 commit 8c20802
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 25 deletions.
16 changes: 5 additions & 11 deletions examples/acrobot/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,15 @@ drake_cc_binary(
drake_py_binary(
name = "optimizer_demo",
srcs = ["optimizer_demo.py"],
add_test_rule = True,
data = [
":spong_sim_main_cc",
":test/example_stochastic_scenario.yaml",
],
test_rule_args = [
"--ensemble_size=3",
"--num_evaluations=3",
],
deps = [
":acrobot_io",
":metrics",
Expand Down Expand Up @@ -424,17 +429,6 @@ drake_cc_googletest(
],
)

sh_test(
name = "optimizer_demo_smoke_test",
srcs = ["test/optimizer_demo_smoke_test.sh"],
data = [
":optimizer_demo",
],
tags = [
"no_memcheck", # This wraps python; python is memcheck-exempt.
],
)

drake_py_unittest(
name = "spong_sim_lib_py_test",
deps = [
Expand Down
4 changes: 0 additions & 4 deletions examples/acrobot/test/optimizer_demo_smoke_test.sh

This file was deleted.

3 changes: 3 additions & 0 deletions examples/allegro_hand/joint_control/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ drake_py_unittest(
":run_twisting_mug",
],
flaky = True,
deps = [
"@rules_python//python/runfiles",
],
)

add_lint_tests(enable_clang_format_lint = False)
22 changes: 12 additions & 10 deletions examples/allegro_hand/joint_control/test/run_twisting_mug_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import time
import unittest

from python.runfiles import Create as CreateRunfiles


def _unique_lcm_url(path):
"""Returns a unique LCM url given a path."""
Expand All @@ -19,20 +21,20 @@ def _unique_lcm_url(path):

class TestRunTwistingMug(unittest.TestCase):

def _find_resource(self, basename):
respath = f"drake/examples/allegro_hand/joint_control/{basename}"
runfiles = CreateRunfiles()
result = runfiles.Rlocation(respath)
self.assertTrue(result, respath)
self.assertTrue(os.path.exists(result), respath)
return result

def setUp(self):
# Fail-fast if these are not set.
self._test_srcdir = os.environ["TEST_SRCDIR"]
self._test_tmpdir = os.environ["TEST_TMPDIR"]

# Find the two binaries under test.
self._sim = os.path.join(
self._test_srcdir, "drake/examples/allegro_hand/joint_control",
"allegro_single_object_simulation")
self._control = os.path.join(
self._test_srcdir, "drake/examples/allegro_hand/joint_control",
"run_twisting_mug")
assert os.path.exists(self._sim)
assert os.path.exists(self._control)
self._sim = self._find_resource("allegro_single_object_simulation")
self._control = self._find_resource("run_twisting_mug")

# Let the sim and controller talk to (only) each other.
self._env = dict(**os.environ)
Expand Down

0 comments on commit 8c20802

Please sign in to comment.