From 87ff40b78acc3d3312d0c0f2197cdc516e17461d Mon Sep 17 00:00:00 2001 From: Yulv-git <34329208+Yulv-git@users.noreply.github.com> Date: Tue, 16 Aug 2022 14:43:27 +0800 Subject: [PATCH] [CodeStyle] Add CI for self.assertTrue(np.allclose(...)) (#45126) * Add CI for assert-allclose. * Update CI script. * Update check_approval. * Specify the destination path for the git diff. * Add test samples. * Add CI for assert-allclose with \n. * Update test samples. * Update ALL_ADDED_LINES_IN_TARGET_PATH. * update GitHub username to userid, test=document_fix * add rfc as a specification, test=document_fix * try to integrate single and multiple rows together, test=document_fix * remove duplicate dirs, test=document_fix * add anchor `#background`, test=document_fix * remove original scripts, test=document_fix * remove test files, test=document_fix Co-authored-by: SigureMo --- tools/check_file_diff_approvals.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/check_file_diff_approvals.sh b/tools/check_file_diff_approvals.sh index 1b0681759a..186b1ec280 100644 --- a/tools/check_file_diff_approvals.sh +++ b/tools/check_file_diff_approvals.sh @@ -259,6 +259,12 @@ if [ "${EMPTY_GRAD_OP_REGISTERED}" != "" ] && [ "${GIT_PT_ID}" != "" ]; then check_approval 1 43953930 46782768 22165420 22361972 fi +INVALID_UNITTEST_ASSERT_CHECK=`echo "$ALL_ADDED_LINES" | grep -zoE '\+\s+self\.assert(True|Equal)\((\s*\+\s*)?(np|numpy)\.(allclose|array_equal)[^+]*' || true` +if [ "${INVALID_UNITTEST_ASSERT_CHECK}" != "" ] && [ "${GIT_PR_ID}" != "" ]; then + echo_line="It is recommended to use 'np.testing.assert_allclose' and 'np.testing.array_equal' instead of 'self.assertTrue(np.allclose(...))' and 'self.assertTrue(np.array_equal(...))'.\nPlease modify the code below. If anything is unclear, please read the specification [ https://github.com/PaddlePaddle/community/blob/master/rfcs/CodeStyle/20220805_code_style_improvement_for_unittest.md#background ]. If it is a mismatch, please request qili93 (Recommend) or luotao1 review and approve.\nThe code that do not meet the specification are as follows:\n${INVALID_UNITTEST_ASSERT_CHECK}\n" + check_approval 1 16605440 6836917 +fi + HAS_MODIFIED_PHI_FILES=`git diff --name-only upstream/$BRANCH | grep "paddle/phi/" || true` PHI_INCLUDE_FLUID_FILES="" for CHANGE_FILE in ${HAS_MODIFIED_PHI_FILES}; do -- GitLab