From f2b07d907aababf1008ca8f72d02af058a1449ed Mon Sep 17 00:00:00 2001 From: Cathy Wong Date: Wed, 23 Sep 2020 16:33:27 -0400 Subject: [PATCH] dataset UT: check PIL version, delete test_callback_2maps --- tests/ut/python/dataset/test_callbacks.py | 8 -------- tests/ut/python/dataset/util.py | 16 +++++++++++----- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/tests/ut/python/dataset/test_callbacks.py b/tests/ut/python/dataset/test_callbacks.py index 744ed6c097..4ccbe659ee 100644 --- a/tests/ut/python/dataset/test_callbacks.py +++ b/tests/ut/python/dataset/test_callbacks.py @@ -217,13 +217,6 @@ def test_callbacks_all_2cbs(): build_test_case_2cbs(4, 4) -def skip_test_callbacks_2maps(): - logger.info("test_callbacks_2maps") - # This test case is skipped because in rare cases (25 out 1000) it might fail - build_test_case_2maps(5, 10) - build_test_case_2maps(6, 9) - - class MyWaitedCallback(WaitedDSCallback): def __init__(self, events, step_size=1): super().__init__(step_size) @@ -462,7 +455,6 @@ def test_callbacks_one_cb(): if __name__ == '__main__': - skip_test_callbacks_2maps() test_callbacks_all_2cbs() test_callbacks_all_methods() test_callbacks_exceptions() diff --git a/tests/ut/python/dataset/util.py b/tests/ut/python/dataset/util.py index e40e6624b7..99be3de979 100644 --- a/tests/ut/python/dataset/util.py +++ b/tests/ut/python/dataset/util.py @@ -21,6 +21,7 @@ from enum import Enum import numpy as np import matplotlib.pyplot as plt import matplotlib.patches as patches +import PIL # import jsbeautifier import mindspore.dataset as ds from mindspore import log as logger @@ -60,13 +61,18 @@ def _compare_to_golden(golden_ref_dir, result_dict): np.testing.assert_array_equal(test_array, golden_array) -def _compare_to_golden_dict(golden_ref_dir, result_dict): +def _compare_to_golden_dict(golden_ref_dir, result_dict, check_pillow_version=False): """ Compare as dictionaries the test result to the golden result """ golden_array = np.load(golden_ref_dir, allow_pickle=True)['arr_0'] - np.testing.assert_equal(result_dict, dict(golden_array)) - + # Note: The version of PILLOW that is used in Jenkins CI is compared with below + if (not check_pillow_version or PIL.__version__ == '7.1.2'): + np.testing.assert_equal(result_dict, dict(golden_array)) + else: + # Beware: If error, PILLOW version of golden results may be incompatible with current PILLOW version + np.testing.assert_equal(result_dict, dict(golden_array), + 'Items are not equal and problem may be due to PILLOW version incompatibility') def _save_json(filename, parameters, result_dict): """ @@ -103,7 +109,7 @@ def save_and_check_dict(data, filename, generate_golden=False): # Save as the golden result _save_golden_dict(cur_dir, golden_ref_dir, result_dict) - _compare_to_golden_dict(golden_ref_dir, result_dict) + _compare_to_golden_dict(golden_ref_dir, result_dict, False) if SAVE_JSON: # Save result to a json file for inspection @@ -135,7 +141,7 @@ def save_and_check_md5(data, filename, generate_golden=False): # Save as the golden result _save_golden_dict(cur_dir, golden_ref_dir, result_dict) - _compare_to_golden_dict(golden_ref_dir, result_dict) + _compare_to_golden_dict(golden_ref_dir, result_dict, True) def save_and_check_tuple(data, parameters, filename, generate_golden=False):