From 547e311a8bc4ed011b9fa15c1e13f23f04a1f714 Mon Sep 17 00:00:00 2001 From: Mathieu Courtois <mathieu.courtois@edf.fr> Date: Mon, 15 Jan 2024 11:44:52 +0100 Subject: [PATCH] [#33569] check imports order for testcases --- lib/aslint/base_checkers.py | 2 +- lib/aslint/test/test_checkers.py | 30 ++++++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/lib/aslint/base_checkers.py b/lib/aslint/base_checkers.py index 128bb44..4d75507 100644 --- a/lib/aslint/base_checkers.py +++ b/lib/aslint/base_checkers.py @@ -74,7 +74,7 @@ the unittest `build_messages_doc`: .. code-block:: sh - cd $HOME/dev/codeaster/devtools/share/test/aslint + cd $HOME/dev/codeaster/devtools/share/test/test_aslint python3 test_aslint_messages.py -doc TestAslint.build_messages_doc """ diff --git a/lib/aslint/test/test_checkers.py b/lib/aslint/test/test_checkers.py index 1e42b89..6040fd9 100644 --- a/lib/aslint/test/test_checkers.py +++ b/lib/aslint/test/test_checkers.py @@ -64,8 +64,8 @@ class UnsupportedExtension(FilenameCat, GenericMsg): class InvalidFilename(FilenameCat, TextMsgNotFound): """Invalid filename for a testcase - Filenames matching 'aaaaNNNm.*', 'aaaaNNNm_*.comm', 'aaaaNNNm_*.py', - 'subdir/*.py' or 'NNN.med' are expected. + Filenames matching 'aaaaNNNm.\*', 'aaaaNNNm\_\*.comm', 'aaaaNNNm\_\*.py', + 'subdir/\*.py' or 'NNN.med' are expected. See C9002 message for the allowed extensions. """ @@ -572,7 +572,7 @@ class EDFCopyright(FileContentCat, COMM.EDFCopyright): Example: - Copyright 2008 Company ABC - - Copyright 2008-2023 EDF R&D www.code-aster.org + - Copyright 2008-2024 EDF R&D www.code-aster.org """ apply_to = COMM_EXT @@ -587,7 +587,6 @@ class InvalidCharacter(FileContentCat, COMM.InvalidCharacter): class RequiredKeyword(FileContentCat, GenericMsg): - """Required keyword in a command file A testcase must use one of operators DEBUT or POURSUITE and the keyword CODE.""" @@ -623,6 +622,29 @@ class RequiredKeyword(FileContentCat, GenericMsg): return err +class ImportAndAutoStart(FileContentCat, GenericMsg): + """AutoStart should not be used in testcases""" + + apply_ctxt = CheckContext(reponame=["src"], branch="main") + id = "C2401" + fixme = ( + r"sed -i -e 's/from \+code_aster import CA *$//g'" + r" -e 's/from \+code_aster\.Commands.*/from code_aster.Commands import *\nfrom code_aster import CA/g'" + " %(filenames)s" + ) + + def search(self, txt): + """Check imports order""" + recmd = re.compile(r"^from +code_aster\.Commands", re.M) + reca = re.compile(r"^from +code_aster import CA", re.M) + matcmd = recmd.search(txt) + matca = reca.search(txt) + err = [] + if matcmd and matca and matca.start() < matcmd.start(): + err.append(": CA must not be imported before Commands") + return err + + class ReformatSource(FilenameCat, COMM.ReformatPy): """Reformat Python source""" -- GitLab