]> SALOME platform Git repositories - modules/homard.git/blob - src/tests/Test/test_util.py
Salome HOME
Merge remote branch 'origin/master' into gn/evol_01
[modules/homard.git] / src / tests / Test / test_util.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2011-2016  CEA/DEN, EDF R&D
3 #
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.
8 #
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.
13 #
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
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 """
21 Python script for HOMARD
22 Utilitaires pour les tests
23 """
24 __revision__ = "V1.4"
25
26 import os
27 #========================================================================
28 #========================================================================
29 def remove_dir(directory) :
30   """
31 Empties, then removes a directory.
32 Copyright EDF-R&D 2013
33   """
34 #
35   l_aux = os.listdir(directory)
36   for fic in l_aux :
37     fic_a = os.path.join(directory, fic)
38     if os.path.isdir(fic_a) :
39       remove_dir(fic_a)
40     else :
41       os.remove(fic_a)
42   os.rmdir(directory)
43 #
44   return
45 #
46 #========================================================================
47 #========================================================================
48 def test_results(rep_test, test_name, dircase, n_iter_test_file, n_rep_test_file, destroy_dir = True) :
49   """
50 Test of the result
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
58   """
59   #
60   test_file_suff = "apad.%02d.bilan" % n_iter_test_file
61   rep_test_file = "I%02d" % n_rep_test_file
62   #
63   test_file = os.path.join(rep_test, test_name + "." + test_file_suff)
64   mess_error_ref = "\nReference file: " + test_file
65 #
66 # Existence du fichier de référence
67 #
68   try :
69     file = open (test_file, "r")
70     les_lignes_ref = file.readlines()
71     file.close()
72   except :
73     mess_error = mess_error_ref + "\nThis file does not exist.\n"
74     destroy_dir = False
75     raise Exception(mess_error)
76 #
77 # Existence du fichier de l'exécution courante
78 #
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()
83     file.close()
84   else :
85     mess_error  = "\nResult file: " + test_file
86     mess_error += "\nThis file does not exist.\n"
87     destroy_dir = False
88     raise Exception(mess_error)
89 #
90 # Nombre de lignes identiques
91 #
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"
96     destroy_dir = False
97     raise Exception(mess_error)
98 #
99 # Comparaison des lignes, à l'esception de la date
100 #
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."
107         destroy_dir = False
108         raise Exception(message_erreur)
109 #
110 # Destruction éventuelle du répertoire du calcul
111 #
112   if destroy_dir:
113     remove_dir(dircase)
114 #
115   return
116 #
117 #========================================================================
118 #========================================================================