-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pydrake: De-boilerplate deprecation unit tests (#10765)
- Loading branch information
1 parent
6a8b847
commit d1e1c97
Showing
12 changed files
with
110 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# -*- python -*- | ||
|
||
load("//tools/lint:lint.bzl", "add_lint_tests") | ||
load( | ||
"@drake//tools/skylark:pybind.bzl", | ||
"get_pybind_package_info", | ||
) | ||
load( | ||
"@drake//tools/skylark:drake_py.bzl", | ||
"drake_py_library", | ||
) | ||
|
||
package(default_visibility = [ | ||
"//bindings/pydrake:__subpackages__", | ||
]) | ||
|
||
# This determines how `PYTHONPATH` is configured. | ||
PACKAGE_INFO = get_pybind_package_info("//bindings") | ||
|
||
drake_py_library( | ||
name = "module_py", | ||
srcs = ["__init__.py"], | ||
imports = PACKAGE_INFO.py_imports, | ||
deps = [ | ||
"//bindings/pydrake/common:module_py", | ||
], | ||
) | ||
|
||
drake_py_library( | ||
name = "deprecation_py", | ||
srcs = ["deprecation.py"], | ||
deps = [":module_py"], | ||
) | ||
|
||
# Package roll-up (for Bazel dependencies). | ||
drake_py_library( | ||
name = "test_utilities", | ||
deps = [ | ||
":deprecation_py", | ||
":module_py", | ||
], | ||
) | ||
|
||
add_lint_tests( | ||
cpplint_data = ["//bindings/pydrake:.clang-format"], | ||
enable_clang_format_lint = True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
""" | ||
Utilities for unit testing. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
""" | ||
Utilities for unit testing deprecation. | ||
""" | ||
|
||
import contextlib | ||
import warnings | ||
|
||
from pydrake.common.deprecation import DrakeDeprecationWarning | ||
|
||
|
||
def _check_expected(caught, expected_count): | ||
if expected_count is None: | ||
return | ||
if len(caught) == expected_count: | ||
return | ||
raise ValueError( | ||
"Expected {} deprecation warnings but got {} instead:\n".format( | ||
expected_count, len(caught)) + "\n".join([str(x) for x in caught])) | ||
|
||
|
||
@contextlib.contextmanager | ||
def catch_drake_warnings(action="always", expected_count=None): | ||
try: | ||
with warnings.catch_warnings(record=True) as caught: | ||
warnings.simplefilter(action, DrakeDeprecationWarning) | ||
yield caught | ||
finally: | ||
_check_expected(caught, expected_count) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.