2 # -*- coding: utf-8 -*-
6 from os import path, listdir, system, chdir, environ, remove
7 from argparse import ArgumentParser
12 from execution.telemac_cas import TelemacCas, get_dico
14 # Adding Eficas to PYTHONPATH
15 sys.path.append(environ["EFICAS_NOUVEAU_ROOT"])
18 except ImportError as excp:
19 print("Add the path to eficas to PYTHONPATH")
20 if hasattr(Telemac.prefs, 'encoding'):
21 # Hack pour changer le codage par defaut des strings
24 sys.setdefaultencoding(prefs.encoding)
25 del sys.setdefaultencoding
37 PREFIX = {'telemac2d':'t2d',
44 def diff_cas(cas1, cas2):
46 Diff between two cases will return True if cas.get for each keyword (in
47 both files) returns the same thing
49 @param cas1 (TelemacCas) cas1
50 @param cas2 (TelemacCas) cas2
52 @returns True if identical
55 # Get the list of keys from cas1 and cas2
56 keys = list(cas1.values.keys())
57 keys.extend(key for key in cas2.values.keys() if key not in keys)
65 print("Differences for {}\n{}: {}\n{}:"\
67 path.basename(cas1.file_name),
69 path.basename(cas2.file_name),
76 def read_write_eficas(module, steering_file, eficas_steering):
78 Import a steergin file in Eficas and save it back
80 @param module Name of the telemac-mascaret module
81 @param steering_file Name of the steering file
82 @param eficas_file Name of the steering file written by Eficas
84 from InterfaceQT4.eficas_go import getEficasSsIhm
86 my_eficas = getEficasSsIhm(code='TELEMAC',labelCode=module)
88 handler = my_eficas.fileOpen(steering_file)
90 raise Exception(steering_file, "Eficas crashed")
91 if not handler.isJdcValid():
92 report = handler.getJdcRapport()
93 raise Exception(steering_file, report)
95 handler.fileSaveAs(eficas_steering)
97 def validate_catalog(module, root_dir):
99 Validate a given Catalog for a given module
101 @param module Name of the module
102 @param root_dir Telemac root path
104 print(" "*2, "~> For module", module)
105 examples_dir = path.join(root_dir, 'examples', module)
106 output_dir = path.join(root_dir, 'examples', 'eficas')
108 telemac_dico = path.join(root_dir, 'sources', module, module+'.dico')
112 for example in sorted(listdir(examples_dir)):
113 example_dir = path.join(examples_dir, example)
115 print(" "*3, "~> In example folder ", example_dir)
116 for case in sorted(listdir(example_dir)):
117 if case.endswith('.cas') and \
118 "_reecrit" not in case and \
119 case[0:3] == PREFIX[module] and \
120 "_reecrit" not in case and \
122 # Adding lang extension (.fr for translated french case)
123 print(" "*4, "~> For test case ", case)
124 root, _ = path.splitext(case)
127 eficas_case = root + "_reecrit.cas"
129 # Import and export in eficas
131 read_write_eficas(module, case, eficas_case)
132 except Exception as e:
135 print(" "*8+FAIL+"FAILED"+ENDC)
136 print(" "*8+"Crashed in eficas")
139 ori_cas = TelemacCas(case, telemac_dico)
140 eficas_cas = TelemacCas(eficas_case, telemac_dico)
142 isdiff = diff_cas(ori_cas, eficas_cas)
145 different.append(case)
146 print(" "*8+FAIL+"FAILED"+ENDC)
147 print(" "*8+"Diff in steering case")
153 # Passed the test case
154 print(" "*8+OKGREEN+"PASSED"+ENDC)
157 print("The following test in", module,
158 " crashed in eficas:", crashed)
160 print("The following test in", module,
161 " have a difference with normal run:", different)
169 for module in ['telemac2d', 'telemac3d']:
170 # Testing loading of catalog
171 validate_catalog(module, environ["HOMETEL"])