]> SALOME platform Git repositories - modules/adao.git/blob - test/test1001/Versions.py
Salome HOME
Minor documentation and code review corrections (39)
[modules/adao.git] / test / test1001 / Versions.py
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) 2008-2023 EDF R&D
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 #
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #
21 # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
22 "Test du système et des versions de modules"
23
24 import sys
25 import unittest
26
27 # ==============================================================================
28 #
29 # Versions minimales pour ADAO
30 # ----------------------------
31 minimal_python_version     = "3.5.0"
32 minimal_numpy_version      = "1.14.0"
33 minimal_scipy_version      = "0.19.0"
34 minimal_matplotlib_version = "2.2.0"
35 minimal_nlopt_version      = "2.4.2"
36 #
37 # ==============================================================================
38 class Test_Versions(unittest.TestCase):
39     def test1_minimalVersion(self):
40         "Affichage des versions minimales"
41         print("  Les versions minimales attendues sont :")
42         print("    - Python systeme....: %s"%minimal_python_version)
43         print("    - Numpy.............: %s"%minimal_numpy_version)
44         print("    - Scipy.............: %s"%minimal_scipy_version)
45         print("    - NLopt.............: %s"%minimal_nlopt_version)
46         print("    - Matplotlib........: %s"%minimal_matplotlib_version)
47         print("")
48
49     def test2_Version(self):
50         "Test du système et des versions de modules"
51         print("  Les versions disponibles sont :")
52         v=sys.version.split()
53         print("    - Python systeme....: %s"%v[0])
54         assert compare_versions(sys.version.split()[0], minimal_python_version)
55
56     def test3_Version(self):
57         try:
58             import numpy
59             print("    - Numpy.............: %s"%numpy.version.version)
60             assert compare_versions(numpy.version.version, minimal_numpy_version)
61         except ImportError as e:
62             raise ImportError(str(e))
63
64     def test4_Version(self):
65         try:
66             import scipy
67             print("    - Scipy.............: %s"%scipy.version.version)
68             assert compare_versions(scipy.version.version, minimal_scipy_version)
69         except ImportError as e:
70             raise ImportError(str(e))
71
72     def test5_Version(self):
73         try:
74             import nlopt
75             __version = "%s.%s.%s"%(
76                 nlopt.version_major(),
77                 nlopt.version_minor(),
78                 nlopt.version_bugfix(),
79                 )
80             print("    - NLopt.............: %s"%__version)
81             assert compare_versions(__version, minimal_nlopt_version)
82         except ImportError as e:
83             raise ImportError(str(e))
84
85     def test6_Version(self):
86         try:
87             import matplotlib
88             mplversion = matplotlib.__version__
89             print("    - Matplotlib........: %s"%mplversion)
90             assert compare_versions(mplversion, minimal_matplotlib_version)
91             #
92             print("")
93             backends_OK = []
94             backends_KO = []
95             backend_now = matplotlib.get_backend()
96
97             for backend in [
98                 'bidon', # Pour vérifier le test uniquement
99                 'Agg',
100                 'Cocoa',
101                 'CocoaAgg',
102                 'GTK',
103                 'GTKAgg',
104                 'Qt5',
105                 'Qt5Agg',
106                 'Template',
107                 'TkAgg',
108                 'emf',
109                 'gdk',
110                 'pdf',
111                 'pgf',
112                 'ps',
113                 'svg',
114                 ]:
115                 try:
116                     matplotlib.use(backend)
117                     backends_OK.append(backend)
118                 except ValueError:
119                     backends_KO.append(backend)
120             backends_OK.sort()
121             backends_KO.sort()
122             #
123             print("  Backends disponibles pour Matplotlib %s :"%mplversion)
124             print("    Defaut initial......: '%s'"%backend_now)
125             print("    Fonctionnant........:")
126             for b in backends_OK:
127                 print("                          '%s'"%b)
128             print("    Non fonctionnant....:")
129             for b in backends_KO:
130                 print("                          '%s'"%b)
131             print("    (Le backend 'bidon' n'est ici que pour verifier le test, il n'existe pas)")
132         except ImportError as e:
133             raise ImportError(str(e))
134         print("")
135         print("  Les résultats obtenus sont corrects.")
136         print("")
137
138 def compare_versions(v1,v2):
139     "Comparaison v1 >= v2"
140     for s in ['+', 'rc1', 'rc2', 'rc3']:
141         v1 = v1.replace(s,'',1)
142         v2 = v2.replace(s,'',1)
143     v11,v12,v13 = list(map(float,v1.split('.')))
144     v21,v22,v23 = list(map(float,v2.split('.')))
145     lv1 = 1e6*v11 + 1e3*v12 + v13
146     lv2 = 1e6*v21 + 1e3*v22 + v23
147     return lv1 >= lv2
148
149 #===============================================================================
150 if __name__ == "__main__":
151     print("\nAUTODIAGNOSTIC\n==============")
152     sys.stderr = sys.stdout
153     unittest.main(verbosity=2)