Salome HOME
Correction and support extension of YACS/TUI export (4)
[modules/adao.git] / test / test1001 / Versions.py
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) 2008-2020 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 Calibre9/Jessie
30 # ----------------------------------
31 minimal_python_version     = "2.7.9"
32 minimal_numpy_version      = "1.8.2"
33 minimal_scipy_version      = "0.14.0"
34 minimal_matplotlib_version = "1.4.2"
35 minimal_nlopt_version      = "2.4.2"
36 #
37 # ==============================================================================
38 class Test_Adao(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 ['bidon', 'pdf', 'pgf', 'Qt4Agg', 'GTK', 'GTKAgg', 'ps',
98                             'agg', 'cairo', 'MacOSX', 'GTKCairo', 'WXAgg',
99                             'template', 'TkAgg', 'GTK3Cairo', 'GTK3Agg', 'svg',
100                             'WebAgg', 'CocoaAgg', 'emf', 'gdk', 'WX']:
101                 try:
102                     matplotlib.use(backend)
103                     backends_OK.append(backend)
104                 except ValueError:
105                     backends_KO.append(backend)
106             #
107             print("  Backends disponibles pour Matplotlib %s :"%mplversion)
108             print("    Defaut initial......: '%s'"%backend_now)
109             print("    Fonctionnant........:")
110             for b in backends_OK:
111                 print("                          '%s'"%b)
112             print("    Non fonctionnant....:")
113             for b in backends_KO:
114                 print("                          '%s'"%b)
115             print("    (Le backend 'bidon' n'est ici que pour verifier le test, il n'existe pas)")
116         except ImportError as e:
117             raise ImportError(str(e))
118         print("")
119         print("  Les résultats obtenus sont corrects.")
120         print("")
121         #
122         return 0
123
124 def compare_versions(v1,v2):
125     "Comparaison v1 >= v2"
126     for s in ['+', 'rc1', 'rc2', 'rc3']:
127         v1 = v1.replace(s,'',1)
128         v2 = v2.replace(s,'',1)
129     v11,v12,v13 = list(map(float,v1.split('.')))
130     v21,v22,v23 = list(map(float,v2.split('.')))
131     lv1 = 1e6*v11 + 1e3*v12 + v13
132     lv2 = 1e6*v21 + 1e3*v22 + v23
133     return lv1 >= lv2
134
135 #===============================================================================
136 if __name__ == "__main__":
137     print("\nAUTODIAGNOSTIC\n==============")
138     sys.stderr = sys.stdout
139     unittest.main(verbosity=2)