[glom/glom-1-14] Python scripts and calcuations: Test buttons now show python errors.



commit b360b8b5cbad2aecee17432f736c2a5ac1ba2d64
Author: Murray Cumming <murrayc murrayc com>
Date:   Sat May 1 23:13:53 2010 +0200

    Python scripts and calcuations: Test buttons now show python errors.
    
    	* glom/python_embed/glom_python.[h|cc]:
    	glom_execute_python_function_implementation(),
    	glom_evaluate_python_function_implementation(): Add an error_message output
    	parameter, to report syntax errors, for instance.
    	* glom/mode_design/fields/dialog_fieldcalculation.cc:
      * glom/mode_design/layout/layout_item_dialogs/dialog_buttonscript.cc:
      Show the python error, if any, when pressing the Test button.
      * Other files: Adapt, ignoring the error message for now.
      * Makefile_tests.am:
    	* tests/test_python_execute_func_bad_syntax.cc: Added a test of the new
    	error_message parameter.

 ChangeLog                                          |   16 ++++++
 Makefile_tests.am                                  |    5 ++
 glom/application.cc                                |    4 +-
 glom/base_db.cc                                    |    4 +-
 glom/base_db_table_data.cc                         |    4 +-
 glom/mode_data/box_data.cc                         |    4 +-
 glom/mode_design/dialog_database_preferences.cc    |    6 ++-
 glom/mode_design/fields/dialog_fieldcalculation.cc |   11 +++-
 .../layout_item_dialogs/dialog_buttonscript.cc     |    8 +++-
 glom/python_embed/glom_python.cc                   |   46 +++++++++-------
 glom/python_embed/glom_python.h                    |    6 ++-
 po/POTFILES.in                                     |    1 +
 tests/test_python_execute_func.cc                  |    9 +++-
 tests/test_python_execute_func_bad_syntax.cc       |   56 ++++++++++++++++++++
 tests/test_python_execute_func_date.cc             |   14 ++++-
 tests/test_python_execute_script.cc                |    6 ++-
 16 files changed, 163 insertions(+), 37 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 638deaa..8e8db03 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
 2010-05-01  Murray Cumming  <murrayc murrayc com>
 
+	Python scripts and calcuations: Test buttons now show python errors.
+	
+	* glom/python_embed/glom_python.[h|cc]: 
+	glom_execute_python_function_implementation(), 
+	glom_evaluate_python_function_implementation(): Add an error_message output 
+	parameter, to report syntax errors, for instance.
+	* glom/mode_design/fields/dialog_fieldcalculation.cc:
+  * glom/mode_design/layout/layout_item_dialogs/dialog_buttonscript.cc:
+  Show the python error, if any, when pressing the Test button.
+  * Other files: Adapt, ignoring the error message for now.
+  * Makefile_tests.am:
+	* tests/test_python_execute_func_bad_syntax.cc: Added a test of the new 
+	error_message parameter. 
+
+2010-05-01  Murray Cumming  <murrayc murrayc com>
+
 	Fix a possible crash when showing choices.
 
 	* glom/mode_data/datawidget/combo.cc: set_text(): Don't show a warning if 
diff --git a/Makefile_tests.am b/Makefile_tests.am
index 9576ff0..c1df482 100644
--- a/Makefile_tests.am
+++ b/Makefile_tests.am
@@ -28,6 +28,7 @@ check_PROGRAMS =						\
 	tests/test_load_python_library\
 	tests/test_python_module \
 	tests/test_python_execute_func \
+	tests/test_python_execute_func_bad_syntax \
 	tests/test_python_execute_func_date \
 	tests/test_python_execute_script \
 	tests/import/test_parsing \
@@ -47,6 +48,7 @@ TESTS =	tests/test_document_load	\
 	tests/test_load_python_library \
 	tests/test_python_module \
 	tests/test_python_execute_func \
+	tests/test_python_execute_func_bad_syntax \
 	tests/test_python_execute_func_date \
 	tests/test_python_execute_script \
 	tests/test_selfhosting_new_empty
@@ -79,6 +81,8 @@ tests_test_load_python_library_SOURCES = tests/test_load_python_library.cc
 tests_test_python_module_SOURCES = tests/test_python_module.cc
 tests_test_python_execute_func_SOURCES = tests/test_python_execute_func.cc \
 	glom/python_embed/glom_python.cc
+tests_test_python_execute_func_bad_syntax_SOURCES = tests/test_python_execute_func_bad_syntax.cc \
+	glom/python_embed/glom_python.cc
 tests_test_python_execute_func_date_SOURCES = tests/test_python_execute_func_date.cc \
 	glom/python_embed/glom_python.cc
 tests_test_python_execute_script_SOURCES = tests/test_python_execute_script.cc \
@@ -137,6 +141,7 @@ tests_test_signal_reemit_LDADD = $(LIBGLOM_LIBS)
 tests_test_load_python_library_LDADD = $(LIBGLOM_LIBS)
 tests_test_python_module_LDADD = $(tests_ldadd) $(PYTHON_LIBS)
 tests_test_python_execute_func_LDADD = $(tests_ldadd) $(GLOM_LIBS) $(PYTHON_LIBS)
+tests_test_python_execute_func_bad_syntax_LDADD = $(tests_ldadd) $(GLOM_LIBS) $(PYTHON_LIBS)
 tests_test_python_execute_func_date_LDADD = $(tests_ldadd) $(GLOM_LIBS) $(PYTHON_LIBS)
 tests_test_python_execute_script_LDADD = $(tests_ldadd) $(GLOM_LIBS) $(PYTHON_LIBS)
 tests_import_test_parsing_LDADD = $(LIBGLOM_LIBS) $(GLOM_LIBS)
diff --git a/glom/application.cc b/glom/application.cc
index e9b4e30..087ae43 100644
--- a/glom/application.cc
+++ b/glom/application.cc
@@ -1230,6 +1230,7 @@ bool Application::on_document_load()
   const Glib::ustring script = pDocument->get_startup_script();
   if(!script.empty())
   {
+    Glib::ustring error_message; //TODO: Check this and tell the user.
     ConnectionPool* connection_pool = ConnectionPool::get_instance();
     sharedptr<SharedConnection> sharedconnection = connection_pool->connect();
     AppPythonUICallbacks callbacks;
@@ -1239,7 +1240,8 @@ bool Application::on_document_load()
       Glib::ustring() /* table_name */,
       sharedptr<Field>(), Gnome::Gda::Value(), // primary key - only used when there is a current table and record.
       sharedconnection->get_gda_connection(),
-      callbacks);
+      callbacks,
+      error_message);
   }
 
 #ifndef GLOM_ENABLE_CLIENT_ONLY
diff --git a/glom/base_db.cc b/glom/base_db.cc
index 3aa2a32..e51f8e7 100644
--- a/glom/base_db.cc
+++ b/glom/base_db.cc
@@ -2479,6 +2479,7 @@ void Base_DB::calculate_field(const LayoutFieldInRecord& field_in_record)
 
           g_assert(sharedconnection);
 
+          Glib::ustring error_message; //TODO: Check this.
           refCalcProgress.m_value =
             glom_evaluate_python_function_implementation(field->get_glom_type(),
               field->get_calculation(),
@@ -2486,7 +2487,8 @@ void Base_DB::calculate_field(const LayoutFieldInRecord& field_in_record)
               get_document(),
               field_in_record.m_table_name,
               field_in_record.m_key, field_in_record.m_key_value,
-              sharedconnection->get_gda_connection());
+              sharedconnection->get_gda_connection(),
+              error_message);
 
           refCalcProgress.m_calc_finished = true;
           refCalcProgress.m_calc_in_progress = false;
diff --git a/glom/base_db_table_data.cc b/glom/base_db_table_data.cc
index 271799d..574ba1b 100644
--- a/glom/base_db_table_data.cc
+++ b/glom/base_db_table_data.cc
@@ -127,6 +127,7 @@ bool Base_DB_Table_Data::record_new(bool use_entered_data, const Gnome::Gda::Val
             // Don't evaluate function on error
 #endif // GLIBMM_EXCEPTIONS_ENABLED
 
+            Glib::ustring error_message; //TODO: Check this.
             const Gnome::Gda::Value value =
               glom_evaluate_python_function_implementation(
                 field->get_glom_type(),
@@ -135,7 +136,8 @@ bool Base_DB_Table_Data::record_new(bool use_entered_data, const Gnome::Gda::Val
                 document,
                 m_table_name,
                 fieldPrimaryKey, primary_key_value,
-                sharedconnection->get_gda_connection());
+                sharedconnection->get_gda_connection(),
+                error_message);
             set_entered_field_data(layout_item, value);
 #ifndef GLIBMM_EXCEPTIONS_ENABLED
           }
diff --git a/glom/mode_data/box_data.cc b/glom/mode_data/box_data.cc
index dc611c3..19dc718 100644
--- a/glom/mode_data/box_data.cc
+++ b/glom/mode_data/box_data.cc
@@ -370,12 +370,14 @@ void Box_Data::execute_button_script(const sharedptr<const LayoutItem_Button>& l
     //Allow this UI to respond to UI change requests from the Python code:
     AppPythonUICallbacks callbacks;
 
+    Glib::ustring error_message; //TODO: Check this.
     glom_execute_python_function_implementation(layout_item->get_script(),
       field_values, //TODO: Maybe use the field's type here.
       get_document(),
       get_table_name(), field_primary_key, primary_key_value,
       sharedconnection->get_gda_connection(),
-      callbacks);
+      callbacks,
+      error_message);
 #ifndef GLIBMM_EXCEPTIONS_ENABLED
   }
 #endif // !GLIBMM_EXCEPTIONS_ENABLED
diff --git a/glom/mode_design/dialog_database_preferences.cc b/glom/mode_design/dialog_database_preferences.cc
index 257d220..993c9f8 100644
--- a/glom/mode_design/dialog_database_preferences.cc
+++ b/glom/mode_design/dialog_database_preferences.cc
@@ -252,14 +252,16 @@ void Dialog_Database_Preferences::on_button_test_script()
   //We need the connection when we run the script, so that the script may use it.
   sharedptr<SharedConnection> sharedconnection = connect_to_server(this /* parent window */);
 
+  Glib::ustring error_message; //TODO: Check this and tell the user.
   PythonUICallbacks callbacks;
   glom_execute_python_function_implementation(calculation,
-     type_map_fields(),
+    type_map_fields(),
     document,
     Glib::ustring() /* table_name */,
     sharedptr<Field>(), Gnome::Gda::Value(), // primary key - only used when setting values in the DB, which we would not encourage in a test.
     sharedconnection->get_gda_connection(),
-    callbacks);
+    callbacks,
+    error_message);
 }
 
 
diff --git a/glom/mode_design/fields/dialog_fieldcalculation.cc b/glom/mode_design/fields/dialog_fieldcalculation.cc
index 9a82282..da91c0c 100644
--- a/glom/mode_design/fields/dialog_fieldcalculation.cc
+++ b/glom/mode_design/fields/dialog_fieldcalculation.cc
@@ -23,6 +23,7 @@
 #include "../../box_db_table.h"
 #include <glom/frame_glom.h>
 #include <glom/python_embed/glom_python.h>
+#include <glom/utils_ui.h>
 #include <libglom/data_structure/glomconversions.h>
 #include <gtksourceviewmm/sourcelanguagemanager.h>
 
@@ -128,6 +129,7 @@ void Dialog_FieldCalculation::on_button_test()
   //We need the connection when we run the script, so that the script may use it.
   sharedptr<SharedConnection> sharedconnection = connect_to_server(this /* parent window */);
 
+  Glib::ustring error_message;
   const Gnome::Gda::Value value = glom_evaluate_python_function_implementation(
     Field::TYPE_TEXT,
     calculation,
@@ -135,10 +137,13 @@ void Dialog_FieldCalculation::on_button_test()
     document,
     m_table_name,
     sharedptr<Field>(), Gnome::Gda::Value(), // primary key - only used when setting values in the DB.
-    sharedconnection->get_gda_connection());
-
-  Frame_Glom::show_ok_dialog(_("Calculation result"), _("The result of the calculation is:\n") + value.to_string(), *this);
+    sharedconnection->get_gda_connection(),
+    error_message);
 
+  if(error_message.empty())
+    Utils::show_ok_dialog(_("Calculation result"), _("The result of the calculation is:\n") + value.to_string(), *this, Gtk::MESSAGE_INFO);
+  else
+    Utils::show_ok_dialog(_("Calculation failed"), _("The calculation failed with this error:\n") + error_message, *this, Gtk::MESSAGE_ERROR);
 
   //Show what fields would trigger the recalculation:
   sharedptr<Field> temp = sharedptr<Field>::create();
diff --git a/glom/mode_design/layout/layout_item_dialogs/dialog_buttonscript.cc b/glom/mode_design/layout/layout_item_dialogs/dialog_buttonscript.cc
index 0ac3132..8e2e20d 100644
--- a/glom/mode_design/layout/layout_item_dialogs/dialog_buttonscript.cc
+++ b/glom/mode_design/layout/layout_item_dialogs/dialog_buttonscript.cc
@@ -21,6 +21,7 @@
 
 #include "dialog_buttonscript.h"
 #include <glom/python_embed/glom_python.h>
+#include <glom/utils_ui.h>
 #include <libglom/data_structure/glomconversions.h>
 #include <gtksourceviewmm/sourcelanguagemanager.h>
 
@@ -121,6 +122,7 @@ void Dialog_ButtonScript::on_button_test_script()
   //We need the connection when we run the script, so that the script may use it.
   sharedptr<SharedConnection> sharedconnection = connect_to_server(this /* parent window */);
 
+  Glib::ustring error_message;
   PythonUICallbacks callbacks;
   glom_execute_python_function_implementation(calculation,
     field_values, //TODO: Maybe use the field's type here.
@@ -128,7 +130,11 @@ void Dialog_ButtonScript::on_button_test_script()
     m_table_name,
     sharedptr<Field>(), Gnome::Gda::Value(), // primary key - only used when setting values in the DB, which we would not encourage in a test.
     sharedconnection->get_gda_connection(),
-    callbacks);
+    callbacks,
+    error_message);
+    
+  if(!error_message.empty())
+    Utils::show_ok_dialog(_("Calculation failed"), _("The calculation failed with this error:\n") + error_message, *this, Gtk::MESSAGE_ERROR);
 }
 
 } //namespace Glom
diff --git a/glom/python_embed/glom_python.cc b/glom/python_embed/glom_python.cc
index f3d79bd..6ec9cb8 100644
--- a/glom/python_embed/glom_python.cc
+++ b/glom/python_embed/glom_python.cc
@@ -64,14 +64,14 @@ static std::list<Glib::ustring> ustring_tokenize(const Glib::ustring& msg, const
 }
 
 // Use this for errors not (directly) caused by the user
-void HandlePythonError()
+static void HandlePythonError()
 {
   if(PyErr_Occurred())
     PyErr_Print();
 }
 
 // Show python coding errors of the user
-void ShowTrace()
+static Glib::ustring get_traceback()
 {
   // Python equivilant:
   // import traceback, sys
@@ -102,7 +102,7 @@ void ShowTrace()
       if(!tbList)
       {
         std::cerr << "Glom: format_exception failed while trying to show Python TraceBack." << std::endl;
-        return;
+        return "<traceback failed>";
       }
 
       boost::python::str emptyString("");
@@ -125,17 +125,20 @@ void ShowTrace()
     Py_XDECREF(value);
     Py_XDECREF(traceback);
 
+  Glib::ustring result;
   if(chrRetval)
   {
-    std::cerr << "Glom: Python Error:" << std::endl << chrRetval << std::endl;
-
-    //TODO: Move this to the caller.
-    //Glib::ustring message = _("Python Error: \n");
-    //message += chrRetval;
-    //Gtk::MessageDialog dialog(message, false, Gtk::MESSAGE_ERROR);
-    //dialog.run();
+    result = chrRetval;
+    g_free(chrRetval);
   }
-  g_free(chrRetval);
+  
+  return result;
+}
+
+static void ShowTrace()
+{
+    std::cerr << "Glom: Python Error:" << std::endl << get_traceback() << std::endl;
+
 }
 
 /** Import a python module, warning about exceptions.
@@ -179,6 +182,7 @@ bool gda_python_module_is_available()
 static boost::python::object glom_python_call(Field::glom_field_type result_type,
   Document* pDocument,
   const Glib::ustring& func_impl, 
+  Glib::ustring& error_message,
   const boost::python::object& param1, 
   const boost::python::object& param2 = boost::python::object())
 {
@@ -224,7 +228,7 @@ static boost::python::object glom_python_call(Field::glom_field_type result_type
   if(!pDict)
   {
      std::cerr << "glom_evaluate_python_function_implementation(): pDict is null" << std::endl;
-     ShowTrace();
+     error_message = get_traceback();
      return boost::python::object();
   }
 
@@ -298,14 +302,14 @@ static boost::python::object glom_python_call(Field::glom_field_type result_type
   catch(const boost::python::error_already_set& ex)
   {
     std::cerr << "glom_evaluate_python_function_implementation():  boost::python::exec() threw error_already_set when using text= " << std::endl << func_def << std::endl;
-    ShowTrace();
+    error_message = get_traceback();
     return boost::python::object();
   }
 
   if(!pyValue.ptr())
   {
     std::cerr << "glom_evaluate_python_function_implementation(): boost::python::exec failed." << std::endl;
-    ShowTrace();
+    error_message = get_traceback();
     return boost::python::object();
   }
 
@@ -318,7 +322,7 @@ static boost::python::object glom_python_call(Field::glom_field_type result_type
   catch(const boost::python::error_already_set& ex)
   {
     std::cerr << "glom_evaluate_python_function_implementation():  pDict[func_name] threw error_already_set when func_name= " << std::endl << func_name << std::endl;
-    ShowTrace();
+    error_message = get_traceback();
     return boost::python::object();
   }
 
@@ -353,7 +357,7 @@ static boost::python::object glom_python_call(Field::glom_field_type result_type
   catch(const boost::python::error_already_set& ex)
   {
     std::cerr << "Glom: Exception caught from pFunc(objRecord). func_name=" << std::endl << func_name << std::endl;
-    ShowTrace();
+    error_message = get_traceback();
   }
 
   if(!(pyResultCpp.ptr()))
@@ -378,7 +382,8 @@ void glom_execute_python_function_implementation(const Glib::ustring& func_impl,
   const sharedptr<const Field>& key_field,
   const Gnome::Gda::Value& key_field_value,
   const Glib::RefPtr<Gnome::Gda::Connection>& opened_connection,
-  const PythonUICallbacks& callbacks)
+  const PythonUICallbacks& callbacks,
+  Glib::ustring& error_message)
 {
   //Import the glom module so that boost::python::object(new PyGlomRecord) can work.
   boost::python::object module_glom = import_module("glom_" GLOM_ABI_VERSION_UNDERLINED);
@@ -406,7 +411,7 @@ void glom_execute_python_function_implementation(const Glib::ustring& func_impl,
   //Pass an additional ui parameter for use by scripts:
   boost::python::object objUI(new PyGlomUI(callbacks));
 
-  glom_python_call(Field::TYPE_TEXT, pDocument, func_impl, objRecord, objUI);
+  glom_python_call(Field::TYPE_TEXT, pDocument, func_impl, error_message, objRecord, objUI);
 }
 
 Gnome::Gda::Value glom_evaluate_python_function_implementation(Field::glom_field_type result_type,
@@ -416,7 +421,8 @@ Gnome::Gda::Value glom_evaluate_python_function_implementation(Field::glom_field
   const Glib::ustring& table_name,
   const sharedptr<const Field>& key_field,
   const Gnome::Gda::Value& key_field_value,
-  const Glib::RefPtr<Gnome::Gda::Connection>& opened_connection)
+  const Glib::RefPtr<Gnome::Gda::Connection>& opened_connection,
+  Glib::ustring& error_message)
 {
   //Import the glom module so that boost::python::object(new PyGlomRecord) can work.
   boost::python::object module_glom = import_module("glom_" GLOM_ABI_VERSION_UNDERLINED);
@@ -442,7 +448,7 @@ Gnome::Gda::Value glom_evaluate_python_function_implementation(Field::glom_field
     pParam->set_fields(field_values, pDocument, table_name, key_field, key_field_value, opened_connection);
   }
   
-  const boost::python::object pyResultCpp = glom_python_call(result_type, pDocument, func_impl, objRecord);
+  const boost::python::object pyResultCpp = glom_python_call(result_type, pDocument, func_impl, error_message, objRecord);
   
   //Deal with the various possible return types:
   Gnome::Gda::Value valueResult;
diff --git a/glom/python_embed/glom_python.h b/glom/python_embed/glom_python.h
index f45abb4..445e33d 100644
--- a/glom/python_embed/glom_python.h
+++ b/glom/python_embed/glom_python.h
@@ -52,7 +52,8 @@ void glom_execute_python_function_implementation(const Glib::ustring& func_impl,
   const sharedptr<const Field>& key_field,
   const Gnome::Gda::Value& key_field_value,
   const Glib::RefPtr<Gnome::Gda::Connection>& opened_connection,
-  const PythonUICallbacks& callbacks);
+  const PythonUICallbacks& callbacks,
+  Glib::ustring& error_message);
 
 /** Run a python calculation, returning the python return value.
  * @param for_script: If this is true then the record object will be writable, 
@@ -65,7 +66,8 @@ Gnome::Gda::Value glom_evaluate_python_function_implementation(Field::glom_field
   const Glib::ustring& table_name,
   const sharedptr<const Field>& key_field,
   const Gnome::Gda::Value& key_field_value,
-  const Glib::RefPtr<Gnome::Gda::Connection>& opened_connection);
+  const Glib::RefPtr<Gnome::Gda::Connection>& opened_connection,
+  Glib::ustring& error_message);
 
 } //namespace Glom
 
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 3e45f27..532544f 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -84,6 +84,7 @@ glom/mode_design/layout/dialog_layout_list.cc
 glom/mode_design/layout/dialog_layout_list_related.cc
 glom/mode_design/layout/layout_item_dialogs/box_formatting.cc
 glom/mode_design/layout/layout_item_dialogs/combo_summarytype.cc
+glom/mode_design/layout/layout_item_dialogs/dialog_buttonscript.cc
 glom/mode_design/layout/layout_item_dialogs/dialog_field_layout.cc
 glom/mode_design/layout/layout_item_dialogs/dialog_field_summary.cc
 glom/mode_design/layout/layout_item_dialogs/dialog_formatting.cc
diff --git a/tests/test_python_execute_func.cc b/tests/test_python_execute_func.cc
index c90c0a7..d6b4b46 100644
--- a/tests/test_python_execute_func.cc
+++ b/tests/test_python_execute_func.cc
@@ -14,13 +14,15 @@ int main()
 
   //Execute a python function:
   Gnome::Gda::Value value;
+  Glib::ustring error_message;
   try
   {
     value = Glom::glom_evaluate_python_function_implementation(
-      Glom::Field::TYPE_TEXT, calculation, field_values,
+      Glom::Field::TYPE_NUMERIC, calculation, field_values,
       0 /* document */, "" /* table name */,
       Glom::sharedptr<Glom::Field>(), Gnome::Gda::Value(), // primary key details. Not used in this test.
-      connection);
+      connection,
+      error_message);
   }
   catch(const std::exception& ex)
   {
@@ -36,6 +38,9 @@ int main()
 
   //std::cout << "type=" << g_type_name(value.get_value_type()) << std::endl;
 
+  //Check that there was no python error:
+  g_assert(error_message.empty());
+  
   //Check that the return value is of the expected type:
   g_assert(value.get_value_type() == GDA_TYPE_NUMERIC);
 
diff --git a/tests/test_python_execute_func_bad_syntax.cc b/tests/test_python_execute_func_bad_syntax.cc
new file mode 100644
index 0000000..500067e
--- /dev/null
+++ b/tests/test_python_execute_func_bad_syntax.cc
@@ -0,0 +1,56 @@
+#include <glom/libglom/init.h>
+#include <glom/python_embed/glom_python.h>
+#include <libglom/data_structure/glomconversions.h>
+
+#include <boost/python.hpp>
+
+int main()
+{
+  Glom::libglom_init(); //Also initializes python.
+
+  const char* calculation = 
+    "count = 0\n"
+    "return cownt";
+  Glom::type_map_fields field_values;
+  Glib::RefPtr<Gnome::Gda::Connection> connection;
+
+  //Execute a python function:
+  Gnome::Gda::Value value;
+  Glib::ustring error_message;
+  try
+  {
+    value = Glom::glom_evaluate_python_function_implementation(
+      Glom::Field::TYPE_NUMERIC, calculation, field_values,
+      0 /* document */, "" /* table name */,
+      Glom::sharedptr<Glom::Field>(), Gnome::Gda::Value(), // primary key details. Not used in this test.
+      connection,
+      error_message);
+  }
+  catch(const std::exception& ex)
+  {
+    std::cerr << "Exception: " << ex.what() << std::endl;
+    return EXIT_FAILURE;
+  }
+  catch(const boost::python::error_already_set& ex)
+  {
+    std::cerr << "Exception: boost::python::error_already_set" << std::endl;
+    return EXIT_FAILURE;
+  }
+
+
+  //std::cout << "type=" << g_type_name(value.get_value_type()) << std::endl;
+  //std::cout << "value=" << value.to_string() << std::endl;
+  
+  //Check that we received a traceback error:
+  g_assert(!error_message.empty());
+  
+  //Check that the return value is of the expected type:
+  g_assert(value.get_value_type() == GDA_TYPE_NUMERIC);
+
+  //Check that the return value is of the expected value:
+  const double numeric = Glom::Conversions::get_double_for_gda_value_numeric(value);
+  //std::cout << "numeric=" << value.to_string() << std::endl;
+  g_assert(numeric == 0);
+
+  return EXIT_SUCCESS;
+}
diff --git a/tests/test_python_execute_func_date.cc b/tests/test_python_execute_func_date.cc
index f72ee0a..50b3e12 100644
--- a/tests/test_python_execute_func_date.cc
+++ b/tests/test_python_execute_func_date.cc
@@ -15,14 +15,19 @@ void execute_func_with_date_return_value()
   Glib::RefPtr<Gnome::Gda::Connection> connection;
 
   //Execute a python function:
+  Glib::ustring error_message;
   const Gnome::Gda::Value value = Glom::glom_evaluate_python_function_implementation(
     Glom::Field::TYPE_DATE, calculation, field_values,
     0 /* document */, "" /* table name */,
     Glom::sharedptr<Glom::Field>(), Gnome::Gda::Value(), // primary key details. Not used in this test.
-    connection);
+    connection,
+    error_message);
 
   //std::cout << "type=" << g_type_name(value.get_value_type()) << std::endl;
 
+  //Check that there was no python error:
+  g_assert(error_message.empty());
+  
   //Check that the return value is of the expected type:
   g_assert(value.get_value_type() == G_TYPE_DATE);
 
@@ -45,14 +50,19 @@ void execute_func_with_date_input_value()
   Glib::RefPtr<Gnome::Gda::Connection> connection;
 
   //Execute a python function:
+  Glib::ustring error_message;
   const Gnome::Gda::Value value = Glom::glom_evaluate_python_function_implementation(
     Glom::Field::TYPE_NUMERIC, calculation, field_values,
     0 /* document */, "" /* table name */,
     Glom::sharedptr<Glom::Field>(), Gnome::Gda::Value(), // primary key details. Not used in this test.
-    connection);
+    connection,
+    error_message);
 
   //std::cout << "type=" << g_type_name(value.get_value_type()) << std::endl;
 
+  //Check that there was no python error:
+  g_assert(error_message.empty());
+  
   //Check that the return value is of the expected type:
   g_assert(value.get_value_type() == GDA_TYPE_NUMERIC);
 
diff --git a/tests/test_python_execute_script.cc b/tests/test_python_execute_script.cc
index 84ed165..8b0720a 100644
--- a/tests/test_python_execute_script.cc
+++ b/tests/test_python_execute_script.cc
@@ -71,6 +71,7 @@ int main()
     sigc::ptr_fun(&on_script_ui_start_new_record);
 
   //Execute a python script:
+  Glib::ustring error_message;
   try
   {
     Glom::glom_execute_python_function_implementation(
@@ -78,7 +79,8 @@ int main()
       0 /* document */, table_name_input,
       Glom::sharedptr<Glom::Field>(), Gnome::Gda::Value(), // primary key details. Not used in this test.
       connection,
-      callbacks);
+      callbacks,
+      error_message);
   }
   catch(const std::exception& ex)
   {
@@ -91,6 +93,8 @@ int main()
     return EXIT_FAILURE;
   }
 
+  g_assert(error_message.empty());
+  
   //Check that the callbacks received the expected values:
   g_assert(result_table_name_list == table_name_input);
   g_assert(result_table_name_details == table_name_details_input);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]