Exemple #1
0
    def testCV2ImshowDisabled(self):
        _cv2._register_hook()

        cv2 = importlib.import_module("cv2")

        self.assertNotIn("COLAB_CV2_IMPORT_HOOK_EXCEPTION", os.environ)
        self.assertIn("cv2", sys.modules)

        # Calling the function leads to the custom error.
        with self.assertRaises(_cv2.DisabledFunctionError) as err:
            cv2.imshow()
        self.assertIn(_cv2._OpenCVImportHook.reason.format("cv2"),
                      str(err.exception))

        # After Enabling, we get a TypeError (because we pass no arguments).
        os.environ[_cv2._OpenCVImportHook.env_var] = "true"
        with self.assertRaises(TypeError) as err:
            cv2.imshow()
Exemple #2
0
def _register_hooks():
  _altair._register_hook()  # pylint:disable=protected-access
  _bokeh._register_hook()  # pylint:disable=protected-access
  _cv2._register_hook()  # pylint:disable=protected-access