def test_deprecation_pybind(self):
     """Test C++ usage in `deprecation_pybind.h`."""
     from deprecation_example.cc_module import (
         ExampleCppClass, emit_deprecation)
     with warnings.catch_warnings(record=True) as w:
         warnings.simplefilter("once", DrakeDeprecationWarning)
         # This is a descriptor, so it will trigger on class access.
         ExampleCppClass.DeprecatedMethod
         self.assertEqual(len(w), 1)
         self._check_warning(w[0], "Do not use DeprecatedMethod()", False)
         # Same for a property.
         ExampleCppClass.deprecated_prop
         self.assertEqual(len(w), 2)
         self._check_warning(w[1], "Do not use deprecated_prop", False)
         # Call good overload; no new warnings.
         obj = ExampleCppClass()
         obj.overload()
         self.assertEqual(len(w), 2)
         # Call bad overload.
         obj.overload(10)
         self.assertEqual(len(w), 3)
         self._check_warning(w[2], "Do not use overload(int)", False)
         # Call bad constructors.
         ExampleCppClass(1)
         self.assertEqual(len(w), 4)
         self._check_warning(w[3], "Do not use ExampleCppClass(int)", False)
         # - Factory.
         ExampleCppClass(2.0)
         self.assertEqual(len(w), 5)
         self._check_warning(
             w[4], "Do not use ExampleCppClass(double)", False)
         # Explicit call.
         emit_deprecation()
         self.assertEqual(len(w), 6)
         self._check_warning(w[5], "Example emitting of deprecation", False)
Beispiel #2
0
 def test_deprecation_pybind(self):
     """Test C++ usage in `deprecation_pybind.h`, as is used in
     `cc_module_py.cc`."""
     from deprecation_example.cc_module import (
         ExampleCppClass,
         ExampleCppStruct,
         emit_deprecation,
     )
     # TODO(eric.cousineau): Break these apart.
     with warnings.catch_warnings(record=True) as w:
         warnings.simplefilter("once", DrakeDeprecationWarning)
         # This is a descriptor, so it will trigger on class access.
         ExampleCppClass.DeprecatedMethod
         self.assertEqual(len(w), 1)
         self._check_warning(w[0], "Do not use DeprecatedMethod()", False)
         # Same for a property.
         ExampleCppClass.deprecated_prop
         self.assertEqual(len(w), 2)
         self._check_warning(w[1], "Do not use deprecated_prop", False)
         # Call good overload; no new warnings.
         obj = ExampleCppClass()
         obj.overload()
         self.assertEqual(len(w), 2)
         # Call bad overload.
         obj.overload(10)
         self.assertEqual(len(w), 3)
         self._check_warning(w[2], "Do not use overload(int)", False)
         # Call bad constructors.
         ExampleCppClass(1)
         self.assertEqual(len(w), 4)
         self._check_warning(w[3], "Do not use ExampleCppClass(int)", False)
         # - Factory.
         ExampleCppClass(2.0)
         self.assertEqual(len(w), 5)
         self._check_warning(w[4], "Do not use ExampleCppClass(double)",
                             False)
         # Explicit call.
         emit_deprecation()
         self.assertEqual(len(w), 6)
         self._check_warning(w[5], "Example emitting of deprecation", False)
         # Param init (regardless of arguments).
         ExampleCppStruct()
         self.assertEqual(len(w), 7)
         self._check_warning(w[6], "Deprecated as of 2038-01-19", False)