Skip to content

Commit

Permalink
call_python: Test plotting.
Browse files Browse the repository at this point in the history
  • Loading branch information
EricCousineau-TRI committed Dec 22, 2017
1 parent d30c751 commit 71a8ed2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
16 changes: 10 additions & 6 deletions common/proto/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,26 @@ drake_cc_googletest(
],
)

# TODO(eric.cousineau): Remove --no_plotting once we can open `$DISPLAY` on CI.
# TODO(eric.cousineau): Add a test which will use an interactive matplotlib
# backend on CI only.
sh_test(
name = "call_python_full_test",
srcs = ["test/call_python_full_test.sh"],
args = [
"--no_plotting",
"$(location :call_python_test)",
"$(location :call_python_client_cli)",
],
data = [
":call_python_client_cli",
":call_python_test",
],
# Certain versions of Mac don't like this script using `ps`. For this
# reason, make the test run locally.
local = 1,
# TODO(eric.cousineau): The `call_python_test` binary is flaky with asan /
# lsan; however, when the binary fails, it simply aborts without
# diagnostic information. When this is resolved, these tags should be
# removed.
tags = [
"no_asan",
"no_lsan",
],
)

drake_cc_googletest(
Expand Down
8 changes: 4 additions & 4 deletions common/proto/call_python_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ def producer_loop():
self._execute_message(msg)
# Spin busy for a bit, let matplotlib (or whatever) flush its
# event queue.
pause(0.001)
pause(0.01)
except KeyboardInterrupt:
# User pressed Ctrl+C.
self._done = True
Expand Down Expand Up @@ -549,9 +549,9 @@ def main(argv):
parser.add_argument(
"--no_threading", action='store_true',
help="Disable threaded dispatch.")
parser.add_argument("--stop_on_error", action='store_true',
help="Stop client if there is an error when " +
"executing a call.")
parser.add_argument(
"--stop_on_error", action='store_true',
help="Stop client if there is an error when executing a call.")
parser.add_argument("-f", "--file", type=str, default=None)
args = parser.parse_args(argv)

Expand Down
32 changes: 25 additions & 7 deletions common/proto/test/call_python_full_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,27 @@ set -e -u
# @file
# @brief Tests the `call_python_client` CLI and `call_python` test together.

cc_bin_flags=
while [[ $# -gt 2 ]]; do
no_plotting=
# By default, set backend so that the test does not open windows.
export MPLBACKEND="ps"

while [[ $# -gt 0 ]]; do
case ${1} in
--no_plotting)
cc_bin_flags='--gtest_filter=-TestCallPython.Plot*'
no_plotting=1
shift;;
--matplotlib_backend)
export MPLBACKEND=${2}
shift; shift;;
*)
echo "Bad argument: ${1}" >&2
exit 1;;
esac
done

cc_bin=${1}
py_client_cli=${2}
cur=$(dirname $0)
cc_bin=${cur}/call_python_test
py_client_cli=${cur}/call_python_client_cli
# TODO(eric.cousineau): Use `tempfile` once we can choose which file C++
# uses.
filename=$(mktemp)
Expand All @@ -26,6 +33,17 @@ done_file=${filename}_done
is_mac=
if [[ "${OSTYPE}" == "darwin"* ]]; then
is_mac=1
# Do not test if Mac has matplotlib 2.1.0:
# @ref https://github.com/matplotlib/matplotlib/issues/9345
mpl_ver=$(python -c "import matplotlib as mpl; print(mpl.__version__)")
if [[ ${mpl_ver} == "2.1.0" ]]; then
no_plotting=1
fi
fi

cc_bin_flags=
if [[ ${no_plotting} == 1 ]]; then
cc_bin_flags='--gtest_filter=-TestCallPython.Plot*'
fi

py-error() {
Expand All @@ -35,7 +53,7 @@ py-error() {

pause() {
# General busy-spinning.
sleep 0.5
sleep 0.05
}

should-fail() {
Expand Down Expand Up @@ -136,7 +154,7 @@ threading-loop() {
# TODO(eric.cousineau): In script form, this generally works well (only
# one interrupt needed); however, interactively we need a few more.
while ps -p ${pid} > /dev/null; do
kill -INT ${pid}
kill -INT ${pid} || :
pause
done
fi
Expand Down

0 comments on commit 71a8ed2

Please sign in to comment.