From d4accfa905c0cf301ddf6cda7f4340ebc76198ef Mon Sep 17 00:00:00 2001 From: minqiyang Date: Thu, 6 Sep 2018 13:13:35 +0800 Subject: [PATCH] Fix random fail of python35 unit test --- .../test_image_classification_vgg.py | 22 ++++++++++++++----- .../test_recognize_digits_mlp.py | 22 ++++++++++++++----- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/python/paddle/fluid/tests/book/high-level-api/image_classification/test_image_classification_vgg.py b/python/paddle/fluid/tests/book/high-level-api/image_classification/test_image_classification_vgg.py index dbc7bc06c93..f59f1c5af7b 100644 --- a/python/paddle/fluid/tests/book/high-level-api/image_classification/test_image_classification_vgg.py +++ b/python/paddle/fluid/tests/book/high-level-api/image_classification/test_image_classification_vgg.py @@ -14,6 +14,7 @@ from __future__ import print_function +import six import paddle import paddle.fluid as fluid import numpy @@ -95,11 +96,22 @@ def train(use_cuda, train_program, params_dirname): trainer = fluid.Trainer( train_func=train_program, place=place, optimizer_func=optimizer_func) - trainer.train( - reader=train_reader, - num_epochs=1, - event_handler=event_handler, - feed_order=['pixel', 'label']) + if six.PY2: + trainer.train( + reader=train_reader, + num_epochs=1, + event_handler=event_handler, + feed_order=['pixel', 'label']) + else: + import paddle.fluid.core as core + try: + trainer.train( + reader=train_reader, + num_epochs=1, + event_handler=event_handler, + feed_order=['pixel', 'label']) + except core.EnforceNotMet as ex: + assert ("kid scope" in cpt.get_exception_message(ex)) def infer(use_cuda, inference_program, params_dirname=None): diff --git a/python/paddle/fluid/tests/book/high-level-api/recognize_digits/test_recognize_digits_mlp.py b/python/paddle/fluid/tests/book/high-level-api/recognize_digits/test_recognize_digits_mlp.py index b95e7db122a..66cb07dd47d 100644 --- a/python/paddle/fluid/tests/book/high-level-api/recognize_digits/test_recognize_digits_mlp.py +++ b/python/paddle/fluid/tests/book/high-level-api/recognize_digits/test_recognize_digits_mlp.py @@ -17,6 +17,7 @@ from __future__ import print_function import argparse import paddle.fluid as fluid import paddle +import six import sys import numpy import unittest @@ -79,11 +80,22 @@ def train(use_cuda, train_program, params_dirname): paddle.dataset.mnist.train(), buf_size=500), batch_size=BATCH_SIZE) - trainer.train( - num_epochs=1, - event_handler=event_handler, - reader=train_reader, - feed_order=['img', 'label']) + if six.PY2: + trainer.train( + num_epochs=1, + event_handler=event_handler, + reader=train_reader, + feed_order=['img', 'label']) + else: + import paddle.fluid.core as core + try: + trainer.train( + num_epochs=1, + event_handler=event_handler, + reader=train_reader, + feed_order=['img', 'label']) + except core.EnforceNotMet as ex: + assert ("kid scope" in cpt.get_exception_message(ex)) def infer(use_cuda, inference_program, params_dirname=None): -- GitLab