Salome HOME
Updated copyright comment
[modules/yacs.git] / src / pmml / pmml_swig / PMMLBasicsTest.py
old mode 100755 (executable)
new mode 100644 (file)
index a7c17a3..cede650
@@ -1,26 +1,39 @@
+#!/usr/bin/env python3
 # -*- coding: utf-8 -*-
+# Copyright (C) 2007-2024  CEA, EDF
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
 
 # imports Salomé
 from PMML import PMMLlib, kANN, kLR
 
 # imports python
 import unittest
-import exceptions
-from exceptions import RuntimeError
 import os
 import shutil
+import platform
+import tempfile
 
 class PMMLBasicsTest(unittest.TestCase):
 
     def setUp(self):
         self.resourcesDir = ".." + os.sep + "Test" + os.sep + "samples" + os.sep ;
-        self.tmpDir = os.sep + "tmp" + os.sep + os.environ['LOGNAME'] + os.sep ;
-        self.tmpDir += "PmmlUnitTest";
-        self.tmpDir += os.sep ;
-        if ( not os.path.exists(self.tmpDir) ):
-            os.mkdir(self.tmpDir);
-            pass
-        pass
+        self.tmpDir = tempfile.mkdtemp(suffix="PmmlUnitTest")
 
     def tearDown(self):
         if ( os.path.exists(self.tmpDir) ):
@@ -33,13 +46,15 @@ class PMMLBasicsTest(unittest.TestCase):
         model = "sANNName";
         exportPyScript = self.tmpDir + "swigTestExportPythonNeuralNet.py";
         refPyFilename = self.resourcesDir + "unittest_ref_ann_model.py";
-        refLines = file(refPyFilename).readlines(); 
+        with open(refPyFilename,"r") as f:
+            refLines = f.readlines(); 
         #
         p = PMMLlib( pmmlFile );
         p.SetCurrentModel( model, kANN );
         p.ExportPython( exportPyScript, "myTestFunc", 
                         "File used by unit test\n PMMLBasicsTest1::testExportNeuralNetworkPython" );
-        myLines = file(exportPyScript).readlines();
+        with open(exportPyScript,"r") as f:
+            myLines = f.readlines();
         self.assertEqual( len(myLines), len(refLines) );
         for (i,line) in enumerate(myLines):
             self.assertEqual( line, refLines[i] );
@@ -51,13 +66,15 @@ class PMMLBasicsTest(unittest.TestCase):
         model = "Modeler[LinearRegression]Tds[steamplant]Predictor[x6:x8:x6x8:x6x6x8]Target[x1]";
         exportPyScript = self.tmpDir + "swigTestExportPythonRegression.py";
         refPyFilename = self.resourcesDir + "unittest_ref_lr_model.py";
-        refLines = file(refPyFilename).readlines(); 
+        with open(refPyFilename,"r") as f:
+            refLines = f.readlines(); 
         #
         p = PMMLlib( pmmlFile );
         p.SetCurrentModel( model, kLR );
         p.ExportPython( exportPyScript, "myTestFunc", 
                                "File used by unit test\n PMMLBasicsTest1::testExportLinearRegressionPython" );
-        myLines = file(exportPyScript).readlines();
+        with open(exportPyScript,"r") as f:
+            myLines = f.readlines();
         self.assertEqual( len(myLines), len(refLines) );
         for (i,line) in enumerate(myLines):
             self.assertEqual( line, refLines[i] );