Salome HOME
Merge branch 'gn/evol'
[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.1"
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) :
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 Copyright EDF-R&D 2014
58   """
59   #
60   destroy_dir = True
61   #
62   test_file_suff = "apad.%02d.bilan" % n_iter_test_file
63   rep_test_file = "I%02d" % n_rep_test_file
64   #
65   test_file = os.path.join(Rep_Test, Test_Name + "." + test_file_suff)
66   mess_error_ref = "\nReference file: " + test_file
67   try :
68     file = open (test_file, "r")
69     mess_ref = file.readlines()
70     file.close()
71   except :
72     mess_error = mess_error_ref + "\nThis file does not exist.\n"
73     destroy_dir = False
74     raise Exception(mess_error)
75   #
76   test_file = os.path.join(dircase, rep_test_file, test_file_suff)
77   if os.path.isfile (test_file) :
78     file = open (test_file, "r")
79     mess = file.readlines()
80     file.close()
81   else :
82     mess_error  = "\nResult file: " + test_file
83     mess_error += "\nThis file does not exist.\n"
84     destroy_dir = False
85     raise Exception(mess_error)
86
87   nblign = len(mess_ref)
88   if ( len(mess) != nblign ):
89     mess_error = mess_error_ref +  "\nResult file: " + test_file
90     mess_error += "\nThe number of lines of the files are not the same.\n"
91     destroy_dir = False
92     raise Exception(mess_error)
93
94   for num in range(nblign) :
95     if (( "creation" not in mess_ref[num] ) and ( mess_ref[num] != mess[num])) :
96       message_erreur = "\nRefe : " + mess_ref[num]
97       message_erreur += "Test : " + mess[num][:-1]
98       message_erreur += "\nThe test is different from the reference."
99       destroy_dir = False
100       raise Exception(message_erreur)
101   #
102   if destroy_dir:
103     remove_dir(dircase)
104 #
105   return
106 #
107 #========================================================================
108 #========================================================================