Salome HOME
15035462959a01a9590ee71c59abab3b75060256
[modules/homard.git] / tests / test_util.py
1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2011-2014  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 Copyright EDF-R&D 2014
23 Test test_1
24 """
25 __revision__ = "V1.2"
26
27 import os
28 #========================================================================
29 #========================================================================
30 def remove_dir(directory) :
31   """
32 Empties, then removes a directory.
33 Copyright EDF-R&D 2013
34   """
35 #
36   l_aux = os.listdir(directory)
37   for fic in l_aux :
38     fic_a = os.path.join(directory, fic)
39     if os.path.isdir(fic_a) :
40       remove_dir(fic_a)
41     else :
42       os.remove(fic_a)
43   os.rmdir(directory)
44 #
45   return
46 #
47 #========================================================================
48 #========================================================================
49 def test_results(Rep_Test, Test_Name, dircase, n_iter_test_file, n_rep_test_file, destroy_dir = True) :
50   """
51 Test of the result
52 Rep_Test: repertoire des tests
53 Test_Name: nom du test
54 dircase: repertoire des resultats du test
55 n_iter_test_file: numero de l'iteration a tester
56 n_rep_test_file: numero du repertoire de l'iteration a tester
57 destroy_dir: destruction du repertoire de calcul
58 Copyright EDF-R&D 2014
59   """
60   #
61   test_file_suff = "apad.%02d.bilan" % n_iter_test_file
62   rep_test_file = "I%02d" % n_rep_test_file
63   #
64   test_file = os.path.join(Rep_Test, Test_Name + "." + test_file_suff)
65   mess_error_ref = "\nReference file: " + test_file
66   try :
67     file = open (test_file, "r")
68     mess_ref = file.readlines()
69     file.close()
70   except :
71     mess_error = mess_error_ref + "\nThis file does not exist.\n"
72     destroy_dir = False
73     raise Exception(mess_error)
74   #
75   test_file = os.path.join(dircase, rep_test_file, test_file_suff)
76   if os.path.isfile (test_file) :
77     file = open (test_file, "r")
78     mess = file.readlines()
79     file.close()
80   else :
81     mess_error  = "\nResult file: " + test_file
82     mess_error += "\nThis file does not exist.\n"
83     destroy_dir = False
84     raise Exception(mess_error)
85
86   nblign = len(mess_ref)
87   if ( len(mess) != nblign ):
88     mess_error = mess_error_ref +  "\nResult file: " + test_file
89     mess_error += "\nThe number of lines of the files are not the same.\n"
90     destroy_dir = False
91     raise Exception(mess_error)
92
93   for num in range(nblign) :
94     if (( "creation" not in mess_ref[num] ) and ( mess_ref[num] != mess[num])) :
95       message_erreur = "\nRefe : " + mess_ref[num]
96       message_erreur += "Test : " + mess[num][:-1]
97       message_erreur += "\nThe test is different from the reference."
98       destroy_dir = False
99       raise Exception(message_erreur)
100   #
101   if destroy_dir:
102     remove_dir(dircase)
103 #
104   return
105 #
106 #========================================================================
107 #========================================================================