X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2Fpmml%2Fpmml_swig%2FPMMLBasicsTest.py;h=cede6506b65024b447871f03b3189c29ae1e8ac6;hb=1894c52d0838df8676e770bef061fc23ca436452;hp=a7c17a36f28ee870bf84a28640bd184122436abf;hpb=07cbf3e0c7f678a5d5b0079583d29b18ed9bc8bf;p=modules%2Fyacs.git diff --git a/src/pmml/pmml_swig/PMMLBasicsTest.py b/src/pmml/pmml_swig/PMMLBasicsTest.py old mode 100755 new mode 100644 index a7c17a36f..cede6506b --- a/src/pmml/pmml_swig/PMMLBasicsTest.py +++ b/src/pmml/pmml_swig/PMMLBasicsTest.py @@ -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] );