提交 46a26946 编写于 作者: M minqiyang

Fix exception problem

上级 c2fce7dd
...@@ -72,3 +72,11 @@ def round(x, d=0): ...@@ -72,3 +72,11 @@ def round(x, d=0):
def floor_division(x, y): def floor_division(x, y):
return x // y return x // y
# exception related functions
def get_exception_message(exc):
if six.PY2:
return exc.message
else:
return str(exc)
...@@ -12,19 +12,21 @@ ...@@ -12,19 +12,21 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import paddle.fluid.compat as cpt
import paddle.fluid.core as core import paddle.fluid.core as core
import unittest import unittest
class TestException(unittest.TestCase): class TestException(unittest.TestCase):
def test_exception(self): def test_exception(self):
ex = None exception = None
try: try:
core.__unittest_throw_exception__() core.__unittest_throw_exception__()
except core.EnforceNotMet as ex: except core.EnforceNotMet as ex:
self.assertIn("test exception", ex.message) self.assertIn("test exception", cpt.get_exception_message(ex))
exception = ex
self.assertIsNotNone(ex) self.assertIsNotNone(exception)
if __name__ == "__main__": if __name__ == "__main__":
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册