[glom] Tests: Added glom_evaluate_python_function_implementation() tests.



commit 4b069d006381da2dfd2dca04842eb8af131ecd6d
Author: Murray Cumming <murrayc murrayc com>
Date:   Tue Dec 8 09:36:33 2009 +0100

    Tests: Added glom_evaluate_python_function_implementation() tests.
    
    * Makefile_tests.am:
    * tests/test_python_execute_func.cc:
    * tests/test_python_execute_func_date.cc: Added two unit tests for
    Glom::glom_evaluate_python_function_implementation(). The date one
    currently fails, as in bug #603686.

 ChangeLog                              |   10 ++++++++
 Makefile_tests.am                      |   12 ++++++++-
 tests/test_python_execute_func.cc      |   30 ++++++++++++++++++++++++
 tests/test_python_execute_func_date.cc |   40 ++++++++++++++++++++++++++++++++
 4 files changed, 91 insertions(+), 1 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 1712de4..7101dcc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2009-12-08  Murray Cumming  <murrayc murrayc com>
+
+	Tests: Added glom_evaluate_python_function_implementation() tests.
+
+	* Makefile_tests.am:
+	* tests/test_python_execute_func.cc:
+	* tests/test_python_execute_func_date.cc: Added two unit tests for 
+	Glom::glom_evaluate_python_function_implementation(). The date one 
+	currently fails, as in bug #603686.
+
 2009-12-07  Murray Cumming  <murrayc murrayc com>
 
 	Python: Trying to stop the PyDateTime_Check() crash.
diff --git a/Makefile_tests.am b/Makefile_tests.am
index bbc0d66..51b56d4 100644
--- a/Makefile_tests.am
+++ b/Makefile_tests.am
@@ -26,6 +26,8 @@ check_PROGRAMS =						\
 	tests/test_signal_reemit			\
 	tests/test_load_python_library\
 	tests/test_python_module \
+	tests/test_python_execute_func \
+	tests/test_python_execute_func_date \
 	tests/import/test_parsing\
 	tests/import/test_signals
 
@@ -34,6 +36,8 @@ TESTS =	tests/test_parsing_time	\
         tests/dtd/test_example_sqlite \
 	tests/test_load_python_library \
 	tests/test_python_module \
+	tests/test_python_execute_func \
+	tests/test_python_execute_func_date \
 	tests/import/test_parsing \
 	tests/import/test_signals
 
@@ -49,6 +53,10 @@ tests_test_parsing_time_SOURCES = tests/test_parsing_time.cc
 tests_test_signal_reemit_SOURCES = tests/test_signal_reemit.cc
 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_date_SOURCES = tests/test_python_execute_func_date.cc \
+	glom/python_embed/glom_python.cc
 tests_import_test_parsing_SOURCES =	\
 	glom/import_csv/csv_parser.cc	\
 	glom/import_csv/csv_parser.h	\
@@ -85,6 +93,8 @@ glom_test_pyembed_LDADD = $(LIBGLOM_LIBS) $(PYTHON_LIBS)
 tests_test_parsing_time_LDADD = $(tests_ldadd)
 tests_test_signal_reemit_LDADD = $(LIBGLOM_LIBS)
 tests_test_load_python_library_LDADD = $(LIBGLOM_LIBS)
-tests_test_python_module_LDADD = $(LIBGLOM_LIBS) $(PYTHON_LIBS) glom/libglom/libglom-$(GLOM_ABI_VERSION).la
+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_date_LDADD = $(tests_ldadd) $(GLOM_LIBS) $(PYTHON_LIBS)
 tests_import_test_parsing_LDADD = $(LIBGLOM_LIBS) $(GLOM_LIBS)
 tests_import_test_signals_LDADD = $(LIBGLOM_LIBS) $(GLOM_LIBS)
diff --git a/tests/test_python_execute_func.cc b/tests/test_python_execute_func.cc
new file mode 100644
index 0000000..1cb8269
--- /dev/null
+++ b/tests/test_python_execute_func.cc
@@ -0,0 +1,30 @@
+#include <glom/libglom/init.h>
+#include <glom/python_embed/glom_python.h>
+#include <libglom/data_structure/glomconversions.h>
+
+int main()
+{
+  Glom::libglom_init(); //Also initializes python.
+
+  const char* calculation = "count = 0\nfor i in range(0, 100): count += i\nreturn count";
+  Glom::type_map_fields field_values;
+  Glib::RefPtr<Gnome::Gda::Connection> connection;
+
+  //Execute a python function:
+  const Gnome::Gda::Value value = Glom::glom_evaluate_python_function_implementation(
+    Glom::Field::TYPE_TEXT, calculation, field_values, 
+    0 /* document */, "" /* table name */, connection);
+
+  //std::cout << "type=" << g_type_name(value.get_value_type()) << std::endl;
+
+  //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);
+  g_assert(numeric == 4950.0);
+
+  //std::cout << "value=" << value.to_string() << std::endl;
+
+  return EXIT_SUCCESS;
+}
diff --git a/tests/test_python_execute_func_date.cc b/tests/test_python_execute_func_date.cc
new file mode 100644
index 0000000..60e2318
--- /dev/null
+++ b/tests/test_python_execute_func_date.cc
@@ -0,0 +1,40 @@
+//#include <Python.h> //Include it before anything else to avoid "_POSIX_C_SOURCE redefined".
+//#if PY_VERSION_HEX >= 0x02040000
+//# include <datetime.h> /* From Python */
+//#endif
+
+
+#include <glom/libglom/init.h>
+#include <glom/python_embed/glom_python.h>
+#include <libglom/data_structure/glomconversions.h>
+
+int main()
+{
+  Glom::libglom_init(); //Also initializes python.
+
+  //Py_Initialize();
+  //PyDateTime_IMPORT; //A macro, needed to use PyDate_Check(), PyDateTime_Check(), etc.
+  //g_assert(PyDateTimeAPI); //This should have been set by the PyDateTime_IMPORT macro.
+
+  const char* calculation = "import datetime;return datetime.date.today();";
+  Glom::type_map_fields field_values;
+  Glib::RefPtr<Gnome::Gda::Connection> connection;
+
+  //Execute a python function:
+  const Gnome::Gda::Value value = Glom::glom_evaluate_python_function_implementation(
+    Glom::Field::TYPE_DATE, calculation, field_values, 
+    0 /* document */, "" /* table name */, connection);
+
+  std::cout << "type=" << g_type_name(value.get_value_type()) << std::endl;
+
+  //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);
+  //g_assert(numeric == 4950.0);
+
+  std::cout << "value=" << value.to_string() << std::endl;
+
+  return EXIT_SUCCESS;
+}



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