X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2Fpmml%2Fpmml_swig%2FPMMLBasicsTest.py;h=cede6506b65024b447871f03b3189c29ae1e8ac6;hb=1894c52d0838df8676e770bef061fc23ca436452;hp=59a4a180b653a5ed9706ac88b39ce0150b0f4b78;hpb=00e3eae1b59a083a31f34e1c6a1b53ca83c72c8b;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 59a4a180b..cede6506b --- a/src/pmml/pmml_swig/PMMLBasicsTest.py +++ b/src/pmml/pmml_swig/PMMLBasicsTest.py @@ -1,28 +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): - pmmlRootDir = os.getenv("YACS_ROOT_DIR"); - self.resourcesDir = os.path.join(pmmlRootDir,"share","salome","resources","pmml"); - self.resourcesDir += os.sep ; - self.tmpDir = "/tmp/"; - self.tmpDir += os.environ['LOGNAME']; # ("USER"); - self.tmpDir += "/PmmlUnitTest/"; - if ( not os.path.exists(self.tmpDir) ): - os.mkdir(self.tmpDir); - pass - pass + self.resourcesDir = ".." + os.sep + "Test" + os.sep + "samples" + os.sep ; + self.tmpDir = tempfile.mkdtemp(suffix="PmmlUnitTest") def tearDown(self): if ( os.path.exists(self.tmpDir) ): @@ -35,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] ); @@ -53,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] );