[glom/glom-1-14] Add test of type conversion after python calculations.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom/glom-1-14] Add test of type conversion after python calculations.
- Date: Sun, 2 May 2010 21:37:15 +0000 (UTC)
commit 3496e3c34be5481faec4b90f2f6bc71038d1a474
Author: Murray Cumming <murrayc murrayc com>
Date: Sun May 2 23:05:58 2010 +0200
Add test of type conversion after python calculations.
* Makefile_tests.am:
* tests/test_python_execute_func_change_result_type.cc: Add a test that
calls a python function that returns a number, for a text field, to
check that the conversion is done.
ChangeLog | 9 +++
Makefile_tests.am | 5 ++
.../test_python_execute_func_change_result_type.cc | 56 ++++++++++++++++++++
3 files changed, 70 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 8e8db03..a4f5f74 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
2010-05-01 Murray Cumming <murrayc murrayc com>
+ Add test of type conversion after python calculations.
+
+ * Makefile_tests.am:
+ * tests/test_python_execute_func_change_result_type.cc: Add a test that
+ calls a python function that returns a number, for a text field, to
+ check that the conversion is done.
+
+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]:
diff --git a/Makefile_tests.am b/Makefile_tests.am
index c1df482..08a1568 100644
--- a/Makefile_tests.am
+++ b/Makefile_tests.am
@@ -30,6 +30,7 @@ check_PROGRAMS = \
tests/test_python_execute_func \
tests/test_python_execute_func_bad_syntax \
tests/test_python_execute_func_date \
+ tests/test_python_execute_func_change_result_type \
tests/test_python_execute_script \
tests/import/test_parsing \
tests/import/test_signals \
@@ -50,6 +51,7 @@ TESTS = tests/test_document_load \
tests/test_python_execute_func \
tests/test_python_execute_func_bad_syntax \
tests/test_python_execute_func_date \
+ tests/test_python_execute_func_change_result_type \
tests/test_python_execute_script \
tests/test_selfhosting_new_empty
@@ -85,6 +87,8 @@ tests_test_python_execute_func_bad_syntax_SOURCES = tests/test_python_execute_fu
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_func_change_result_type_SOURCES = tests/test_python_execute_func_change_result_type.cc \
+ glom/python_embed/glom_python.cc
tests_test_python_execute_script_SOURCES = tests/test_python_execute_script.cc \
glom/python_embed/glom_python.cc
tests_import_test_parsing_SOURCES = \
@@ -143,6 +147,7 @@ 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_func_change_result_type_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)
tests_import_test_signals_LDADD = $(LIBGLOM_LIBS) $(GLOM_LIBS)
diff --git a/tests/test_python_execute_func_change_result_type.cc b/tests/test_python_execute_func_change_result_type.cc
new file mode 100644
index 0000000..2d32f8a
--- /dev/null
+++ b/tests/test_python_execute_func_change_result_type.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\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:
+ Gnome::Gda::Value value;
+ Glib::ustring error_message;
+ const Glom::Field::glom_field_type result_type = Glom::Field::TYPE_TEXT;
+ try
+ {
+ //We ask for a text result though the python function actually returns a number.
+ value = Glom::glom_evaluate_python_function_implementation(
+ result_type, 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;
+
+ //Check that there was no python error:
+ g_assert(error_message.empty());
+
+ //Check that the return value is of the expected type:
+ g_assert(Glom::Field::get_glom_type_for_gda_type(value.get_value_type()) == result_type);
+
+ //Check that the return value is of the expected value:
+ const Glib::ustring text = value.get_string();
+ std::cout << "text=" << text << std::endl;
+ g_assert(text == "4950"); //This should always be as per ISO, not according to the user's locale, because it's generally passed to the database. Presentation is separate to calculation or storage.
+
+ //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]