22 from PMML
import PMMLlib, kANN, kLR
27 from exceptions
import RuntimeError
34 self.
resourcesDir =
".." + os.sep +
"Test" + os.sep +
"samples" + os.sep ;
35 self.
tmpDir = os.sep +
"tmp" + os.sep + os.environ[
'LOGNAME'] + os.sep ;
36 self.
tmpDir +=
"PmmlUnitTest";
38 if (
not os.path.exists(self.
tmpDir) ):
44 if ( os.path.exists(self.
tmpDir) ):
45 shutil.rmtree(self.
tmpDir);
52 exportPyScript = self.
tmpDir +
"swigTestExportPythonNeuralNet.py";
53 refPyFilename = self.
resourcesDir +
"unittest_ref_ann_model.py";
54 refLines = file(refPyFilename).readlines();
57 p.SetCurrentModel( model, kANN );
58 p.ExportPython( exportPyScript,
"myTestFunc",
59 "File used by unit test\n PMMLBasicsTest1::testExportNeuralNetworkPython" );
60 myLines = file(exportPyScript).readlines();
61 self.assertEqual( len(myLines), len(refLines) );
62 for (i,line)
in enumerate(myLines):
63 self.assertEqual( line, refLines[i] );
69 model =
"Modeler[LinearRegression]Tds[steamplant]Predictor[x6:x8:x6x8:x6x6x8]Target[x1]";
70 exportPyScript = self.
tmpDir +
"swigTestExportPythonRegression.py";
71 refPyFilename = self.
resourcesDir +
"unittest_ref_lr_model.py";
72 refLines = file(refPyFilename).readlines();
75 p.SetCurrentModel( model, kLR );
76 p.ExportPython( exportPyScript,
"myTestFunc",
77 "File used by unit test\n PMMLBasicsTest1::testExportLinearRegressionPython" );
78 myLines = file(exportPyScript).readlines();
79 self.assertEqual( len(myLines), len(refLines) );
80 for (i,line)
in enumerate(myLines):
81 self.assertEqual( line, refLines[i] );
86 self.assertRaises( RuntimeError, PMMLlib,
"0.mml" );
93 self.assertRaises( RuntimeError, p.SetCurrentModel, model, kLR );
98 self.assertRaises( RuntimeError, p.Write );