+#!/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) ):
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] );
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] );