Salome HOME
[EDF27816] : fix all non regression tests
[modules/yacs.git] / src / py2yacs / Test / Py2yacsTest.cxx
index a86802431931a33af946e0165a458dce1bb9e8fd..e95fe58cdcf64416b1fb515582c84f416684d370 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2006-2016  CEA/DEN, EDF R&D
+// Copyright (C) 2006-2022  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -25,6 +25,7 @@
 #include "py2yacs.hxx"
 #include "Proc.hxx"
 #include "Executor.hxx"
+#include "PythonCppUtils.hxx"
 
 #include "RuntimeSALOME.hxx"
 #include "PythonPorts.hxx"
@@ -168,7 +169,7 @@ void Py2yacsTest::t3()
                          "  print(b)\n"
                          "  print(c)\n";
   const char* input_ports[] = {"a", "b", "c"};
-  const char* output_ports[] = {};
+  const char** output_ports;
   verifyCorrectPycode(code_py, "f1", 3, input_ports, 0, output_ports);
 }
 
@@ -178,7 +179,7 @@ void Py2yacsTest::t4()
                          "  print('toto')\n"
                          "  return\n";
   const char* input_ports[] = {"a", "b", "c"};
-  const char* output_ports[] = {};
+  const char** output_ports;
   verifyCorrectPycode(code_py, "f1", 0, input_ports, 0, output_ports);
 }
 
@@ -220,14 +221,15 @@ void Py2yacsTest::unaccepted_statement()
   verifyWrongPycode(code_py, "f", "not accepted statement");
 }
 
+/* // This is now accepted
 void Py2yacsTest::unaccepted_statement2()
 {
   const char * code_py = "def f(a):\n"
                          "  return a\n"
                          "if __name__ == '__main__':"
-                         "  print 'toto'\n";
+                         "  print('toto')\n";
   verifyWrongPycode(code_py, "f", "not accepted statement");
-}
+}*/
 
 void Py2yacsTest::unaccepted_return()
 {
@@ -294,10 +296,16 @@ void Py2yacsTest::schemaExec()
   // verify the output port value
   YACS::ENGINE::OutputPyPort* var = dynamic_cast<YACS::ENGINE::OutputPyPort*>(n->getOutputPort("x"));
   CPPUNIT_ASSERT(var);
+  double x = -2.0;
   PyObject* pyVal = var->get();
-  CPPUNIT_ASSERT(pyVal);
-  CPPUNIT_ASSERT(PyFloat_Check(pyVal));
-  CPPUNIT_ASSERT_DOUBLES_EQUAL(42., PyFloat_AsDouble(pyVal), 1.E-12);
+  {
+    AutoGIL agil;
+    CPPUNIT_ASSERT(pyVal);
+    x = PyFloat_AsDouble(pyVal);
+    CPPUNIT_ASSERT( PyErr_Occurred()==nullptr );// check pyVal is interpretable as float
+  }
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(42., x, 1.E-12);
+  p->shutdown(10); // kill all the containers
 }
 
 // Test the behaviour when there is an error in the python parser