1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2011-2016 CEA/DEN, EDF R&D
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 Python script for HOMARD
22 Utilitaires pour les tests
27 #========================================================================
28 #========================================================================
29 def remove_dir(directory) :
31 Empties, then removes a directory.
32 Copyright EDF-R&D 2013
35 l_aux = os.listdir(directory)
37 fic_a = os.path.join(directory, fic)
38 if os.path.isdir(fic_a) :
46 #========================================================================
47 #========================================================================
48 def test_results(rep_test, test_name, dircase, n_iter_test_file, n_rep_test_file, destroy_dir = True) :
51 rep_test: repertoire des tests
52 test_name: nom du test
53 dircase: repertoire des resultats du test
54 n_iter_test_file: numero de l'iteration a tester
55 n_rep_test_file: numero du repertoire de l'iteration a tester
56 destroy_dir: destruction du repertoire de calcul
57 Copyright EDF-R&D 2014
60 test_file_suff = "apad.%02d.bilan" % n_iter_test_file
61 rep_test_file = "I%02d" % n_rep_test_file
63 test_file = os.path.join(rep_test, test_name + "." + test_file_suff)
64 mess_error_ref = "\nReference file: " + test_file
66 # Existence du fichier de référence
69 file = open (test_file, "r")
70 les_lignes_ref = file.readlines()
73 mess_error = mess_error_ref + "\nThis file does not exist.\n"
75 raise Exception(mess_error)
77 # Existence du fichier de l'exécution courante
79 test_file = os.path.join(dircase, rep_test_file, test_file_suff)
80 if os.path.isfile (test_file) :
81 file = open (test_file, "r")
82 les_lignes = file.readlines()
85 mess_error = "\nResult file: " + test_file
86 mess_error += "\nThis file does not exist.\n"
88 raise Exception(mess_error)
90 # Nombre de lignes identiques
92 nblign = len(les_lignes_ref)
93 if ( len(les_lignes) != nblign ):
94 mess_error = mess_error_ref + "\nResult file: " + test_file
95 mess_error += "\nThe number of lines of the files are not the same.\n"
97 raise Exception(mess_error)
99 # Comparaison des lignes, à l'esception de la date
101 for num in range(nblign) :
102 if ( "creation" not in les_lignes_ref[num] ) :
103 if ( les_lignes_ref[num] != les_lignes[num] ) :
104 message_erreur = "\nRefe : " + les_lignes_ref[num]
105 message_erreur += "Test : " + les_lignes[num][:-1]
106 message_erreur += "\nThe test is different from the reference."
108 raise Exception(message_erreur)
110 # Destruction éventuelle du répertoire du calcul
117 #========================================================================
118 #========================================================================