Skip to content

Commit

Permalink
py: Use --test_env to permit easier usage of matplotlib in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EricCousineau-TRI committed Mar 26, 2019
1 parent 510c535 commit 39d388a
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 27 deletions.
1 change: 1 addition & 0 deletions bindings/pydrake/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ drake_py_unittest(
drake_py_binary(
name = "math_example",
srcs = ["math_example.py"],
add_test_rule = 1,
isolate = 1,
deps = [
":math_py",
Expand Down
1 change: 0 additions & 1 deletion bindings/pydrake/systems/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ drake_py_binary(
data = [
"//examples/multibody/cart_pole:cart_pole.sdf",
],
test_rule_args = ["--test"],
test_rule_timeout = "moderate",
deps = [
":drawing_py",
Expand Down
17 changes: 3 additions & 14 deletions bindings/pydrake/systems/drawing_graphviz_example.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
import matplotlib.pyplot as plt

from pydrake.common import FindResourceOrThrow
from pydrake.geometry import (ConnectDrakeVisualizer, SceneGraph)
from pydrake.geometry import ConnectDrakeVisualizer, SceneGraph
from pydrake.lcm import DrakeLcm
from pydrake.multibody.tree import UniformGravityFieldElement
from pydrake.multibody.plant import MultibodyPlant
from pydrake.multibody.parsing import Parser
from pydrake.multibody.plant import MultibodyPlant
from pydrake.systems.drawing import plot_system_graphviz
from pydrake.systems.framework import DiagramBuilder

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--test",
action='store_true',
help="Causes the script to run without blocking for "
"user input.",
default=False)
args = parser.parse_args()

file_name = FindResourceOrThrow(
"drake/examples/multibody/cart_pole/cart_pole.sdf")
builder = DiagramBuilder()
Expand All @@ -45,5 +35,4 @@

plot_system_graphviz(diagram, max_depth=2)

if not args.test:
plt.show()
plt.show()
3 changes: 2 additions & 1 deletion common/proto/test/call_python_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def scoped_file(filepath, is_fifo=False):

assert "TEST_TMPDIR" in os.environ, "Must run under `bazel test`"

# Set backend so that the test does not open windows.
# TODO(eric.cousineau): See if it's possible to make test usefully pass for
# "Template" backend.
os.environ["MPLBACKEND"] = "ps"

SIGPIPE_STATUS = 141
Expand Down
1 change: 0 additions & 1 deletion examples/van_der_pol/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ drake_py_binary(
name = "plot_limit_cycle",
srcs = ["plot_limit_cycle.py"],
add_test_rule = 1,
test_rule_args = ["--test"],
deps = [
"//bindings/pydrake",
],
Expand Down
11 changes: 1 addition & 10 deletions examples/van_der_pol/plot_limit_cycle.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import argparse
import matplotlib.pyplot as plt

from pydrake.examples.van_der_pol import VanDerPolOscillator

parser = argparse.ArgumentParser()
parser.add_argument("--test",
action='store_true',
help="Run without blocking for user input.",
default=False)
args = parser.parse_args()

x = VanDerPolOscillator.CalcLimitCycle()

fig, ax = plt.subplots()
Expand All @@ -19,5 +11,4 @@
ax.set_xlabel('q')
ax.set_ylabel('qdot')

if not args.test:
plt.show()
plt.show()
3 changes: 3 additions & 0 deletions tools/bazel.rc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ test --test_env=MOSEKLM_LICENSE_FILE
# instance has a consistent, but non-default, LCM URL.
test --test_env=LCM_DEFAULT_URL=memq://

# Prevent matplotlib from showing windows (#11029).
test --test_env=MPLBACKEND=Template

### A configuration that enables Gurobi. ###
# -- To use this config, the GRB_LICENSE_FILE environment variable must be set
# -- to the location of the Gurobi license key file. On Ubuntu, the GUROBI_PATH
Expand Down

0 comments on commit 39d388a

Please sign in to comment.