Пример #1
0
    def test_importaftererror(self):
        from caffe2.python import core, lazy_dyndep
        import tempfile

        with tempfile.NamedTemporaryFile() as f:
            lazy_dyndep.RegisterOpsLibrary(f.name)

            def handler(e):
                raise ValueError("test")
            lazy_dyndep.SetErrorHandler(handler)
            with self.assertRaises(ValueError):
                core.RefreshRegisteredOperators()

            def handlernoop(e):
                raise
            lazy_dyndep.SetErrorHandler(handlernoop)
            lazy_dyndep.RegisterOpsLibrary("@/caffe2/caffe2/distributed:file_store_handler_ops")
            core.RefreshRegisteredOperators()
Пример #2
0
    def test_errorhandler(self):
        from caffe2.python import core, lazy_dyndep
        import tempfile

        with tempfile.NamedTemporaryFile() as f:
            lazy_dyndep.RegisterOpsLibrary(f.name)

            def handler(e):
                raise ValueError("test")
            lazy_dyndep.SetErrorHandler(handler)
            with self.assertRaises(ValueError, msg="test"):
                core.RefreshRegisteredOperators()
Пример #3
0
    def test_workspacecreatenet(self):
        from caffe2.python import workspace, lazy_dyndep
        import tempfile

        with tempfile.NamedTemporaryFile() as f:
            lazy_dyndep.RegisterOpsLibrary(f.name)
            called = False

            def handler(e):
                raise ValueError("test")
            lazy_dyndep.SetErrorHandler(handler)
            with self.assertRaises(ValueError, msg="test"):
                workspace.CreateNet("fake")