diff --git a/test/pytriqs/CMakeLists.txt b/test/pytriqs/CMakeLists.txt index 38392411..b19c8eeb 100644 --- a/test/pytriqs/CMakeLists.txt +++ b/test/pytriqs/CMakeLists.txt @@ -1,4 +1,16 @@ enable_testing() find_package(TestScriptHdf) + +# Create a temporary copy of the python modules so that we can run before installation with the test +FILE(GLOB_RECURSE all_py_files RELATIVE ${CMAKE_SOURCE_DIR}/test/pytriqs *.py ) +SET(py_copy_tar ${CMAKE_BINARY_DIR}/test/py_copy_test.tar) +add_custom_command (OUTPUT ${py_copy_tar} DEPENDS ${all_py_files} + COMMAND cd ${CMAKE_SOURCE_DIR}/test/pytriqs && tar cf ${py_copy_tar} ${all_py_files} && cd ${CMAKE_BINARY_DIR}/test/pytriqs && tar xf ${py_copy_tar} ) +add_custom_target(py_copy_test ALL DEPENDS ${py_copy_tar}) + +find_package(PythonWrapperMacro) + +add_custom_target(wrap_clean_test COMMAND find ${CMAKE_BINARY_DIR} -name \"*.cpp\" |xargs rm) + add_all_subdirectories_with_cmakelist() diff --git a/test/pytriqs/parameters/test.py b/test/pytriqs/parameters/test.py deleted file mode 100644 index 4a2d1153..00000000 --- a/test/pytriqs/parameters/test.py +++ /dev/null @@ -1,39 +0,0 @@ -import pytriqs.parameters.parameters as P -p = P.Parameters() -p['i'] = 10 -p['d'] = 2.3 -p['s'] = "my string" - -print p - -print p['i'] -print p['d'] -print p['s'] - -d = { 'a' : 10, 'b' : "good", 'c' : -9.2} -p.update(d) -print p - -import numpy as np -a = np.array([[1,2],[3,4]]) -p['A'] = a -p['Ad'] = 2.5*a - -print " p['A'] = ", p['A'] - -p['A'][0,0] *=10 -print " p['A'] = ", p['A'] - -print p - -p2 = P.Parameters() -p2.update2( a = 4, b= "u") - -p['sub'] = p2 -p['sub2'] = { 'r' : 1, 'rrr' : 3} - -print p['sub'] -print p['sub2'] - -print p - diff --git a/pytriqs/wrap_test/CMakeLists.txt b/test/pytriqs/wrap_test/CMakeLists.txt similarity index 83% rename from pytriqs/wrap_test/CMakeLists.txt rename to test/pytriqs/wrap_test/CMakeLists.txt index 07caa349..9bc0bb9a 100644 --- a/pytriqs/wrap_test/CMakeLists.txt +++ b/test/pytriqs/wrap_test/CMakeLists.txt @@ -18,5 +18,7 @@ add_dependencies(python_wrap_my_moduleB python_wrap_my_module) include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ) -install (FILES ${CMAKE_SOURCE_DIR}/pytriqs/__init__.py.template DESTINATION "include/pytriqs/gf/local" RENAME __init__.py) +# A sample test with text output +add_triqs_test_txt(wrap_a) + diff --git a/pytriqs/wrap_test/__init__.py b/test/pytriqs/wrap_test/__init__.py similarity index 100% rename from pytriqs/wrap_test/__init__.py rename to test/pytriqs/wrap_test/__init__.py diff --git a/pytriqs/wrap_test/a.hpp b/test/pytriqs/wrap_test/a.hpp similarity index 100% rename from pytriqs/wrap_test/a.hpp rename to test/pytriqs/wrap_test/a.hpp diff --git a/pytriqs/wrap_test/aux.py b/test/pytriqs/wrap_test/aux.py similarity index 100% rename from pytriqs/wrap_test/aux.py rename to test/pytriqs/wrap_test/aux.py diff --git a/pytriqs/wrap_test/b.hpp b/test/pytriqs/wrap_test/b.hpp similarity index 100% rename from pytriqs/wrap_test/b.hpp rename to test/pytriqs/wrap_test/b.hpp diff --git a/pytriqs/wrap_test/g.hpp b/test/pytriqs/wrap_test/g.hpp similarity index 100% rename from pytriqs/wrap_test/g.hpp rename to test/pytriqs/wrap_test/g.hpp diff --git a/pytriqs/wrap_test/my_moduleB_desc.py b/test/pytriqs/wrap_test/my_moduleB_desc.py similarity index 62% rename from pytriqs/wrap_test/my_moduleB_desc.py rename to test/pytriqs/wrap_test/my_moduleB_desc.py index f5e16506..46c31a14 100644 --- a/pytriqs/wrap_test/my_moduleB_desc.py +++ b/test/pytriqs/wrap_test/my_moduleB_desc.py @@ -1,9 +1,9 @@ from wrap_generator import * # The module -mod = module_(full_name = "pytriqs.wrap_test.my_moduleB", doc = " Doc of my_module ") +mod = module_(full_name = "my_moduleB", doc = " Doc of my_module ") mod.use_module('my_module') -mod.add_include("") +mod.add_include("") mod.add_include("") mod.add_function (name = "print_a2", signature = "void(A a)", doc = "DOC of print_a") diff --git a/pytriqs/wrap_test/my_module_desc.py b/test/pytriqs/wrap_test/my_module_desc.py similarity index 94% rename from pytriqs/wrap_test/my_module_desc.py rename to test/pytriqs/wrap_test/my_module_desc.py index 56fe9032..04d48202 100644 --- a/pytriqs/wrap_test/my_module_desc.py +++ b/test/pytriqs/wrap_test/my_module_desc.py @@ -1,8 +1,8 @@ from wrap_generator import * # The module -module = module_(full_name = "pytriqs.wrap_test.my_module", doc = " Doc of my_module ") -module.add_include("") +module = module_(full_name = "my_module", doc = " Doc of my_module ") +module.add_include("") module.add_include("") # one class @@ -25,7 +25,7 @@ g.add_method(py_name = "m1", c_name = "m1", signature = "double (int u)", doc = g.add_method(py_name = "m1", c_name = "m2", signature = "double (double u)", doc = "DOC of m1...") # another version of the method, with some pre/post processing written in python -g.add_method(py_name = "m1p", c_name = "m1", signature = "double (int u, double y = 3)", doc = "DOC of mm", python_precall = "pytriqs.wrap_test.aux.ffg", python_postcall = "pytriqs.wrap_test.aux.post1") +g.add_method(py_name = "m1p", c_name = "m1", signature = "double (int u, double y = 3)", doc = "DOC of mm", python_precall = "aux.ffg", python_postcall = "aux.post1") # demo of adding a simple piece of C++ code, there is no C++ method corresponding g.add_method(py_name = "m1_x", calling_pattern = "bool result = (self_c.x >0) && (self_c.x < 10)" , signature = "bool()", doc = "A method which did not exist in C++") diff --git a/pytriqs/wrap_test/test_g_desc.py b/test/pytriqs/wrap_test/test_g_desc.py similarity index 91% rename from pytriqs/wrap_test/test_g_desc.py rename to test/pytriqs/wrap_test/test_g_desc.py index 23c20a36..1e206c78 100644 --- a/pytriqs/wrap_test/test_g_desc.py +++ b/test/pytriqs/wrap_test/test_g_desc.py @@ -2,7 +2,7 @@ from wrap_generator import * # The module module = module_(full_name = "pytriqs.wrap_test.test_g", doc = " Doc of my_module ") -module.add_include("") +module.add_include("") module.add_include("") module.add_function (name = "make_bgf", signature = "block_gf_view (double a)", doc = "DOC of print_a") diff --git a/test/pytriqs/wrap_test/wrap_B.py b/test/pytriqs/wrap_test/wrap_B.py new file mode 100644 index 00000000..503728d4 --- /dev/null +++ b/test/pytriqs/wrap_test/wrap_B.py @@ -0,0 +1,3 @@ +import my_moduleB as B +B.print_a2(2) + diff --git a/test/pytriqs/wrap_test/wrap_a.output b/test/pytriqs/wrap_test/wrap_a.output new file mode 100644 index 00000000..181c7f90 --- /dev/null +++ b/test/pytriqs/wrap_test/wrap_a.output @@ -0,0 +1,23 @@ + calling m1 1 2 +11.0 +calling ffg, with : +(1, 2.0) +{} + calling m1 2 4 +[19.0] +my a is 3 +[0, 1, 2] [0, 2, 4] +[2, 4, 6, 8] +[2, 4, 6] + I am an A with x= 6 +use_fnt ii +5 +use_fnt ii +41 +use_fnt iid +9 +use_fnt iid +45 + rereading from hdf5 I am an A with x= 6.9 +'cmy_module\n__reduce_reconstructor__Ac\np0\n(I1\nF3.0\ntp1\nRp2\n.' + I am an A with x= 3 diff --git a/test/pytriqs/wrap_test/wrap_a.py b/test/pytriqs/wrap_test/wrap_a.py new file mode 100644 index 00000000..bee6c1a5 --- /dev/null +++ b/test/pytriqs/wrap_test/wrap_a.py @@ -0,0 +1,55 @@ +from my_module import * + +a = Ac() +print a.m1(1,2.0) +print a.m1p(1,2.0) + +print_a (a) + +v1 = make_vector(3) +v2 = vector_x2(v1) + +print v1, v2 + +print vector_x2([1,2,3,4]) +print vector_x2((1,2,3)) + +print a+ a +#print_a (8) + +f,s = a.__reduce__() +b = f(*s) + +# lambda <-> std::function +fc = make_fnt_ii() +#print fc +use_fnt_ii(fc) +fp = lambda i,j : i + 20*j +use_fnt_ii(fp) + +fc2 = make_fnt_iid() +#print fc2 +use_fnt_iid(fc2) +fp2 = lambda i,j,a : a+ i + 20*j +use_fnt_iid(fp2) + + +from pytriqs.archive import * +import pytriqs.archive.hdf_archive_schemes + +import numpy +R = HDFArchive('ess.h5', 'w') # Opens the file myfile.h5, in read/write mode +R['a'] = 2.3*a +del R + +R2 = HDFArchive('ess.h5', 'r') +aa = R2['a'] +print " rereading from hdf5 ", aa + +import pickle +s = pickle.dumps(a) +print repr(s) +bb = pickle.loads(s) +print bb + + diff --git a/test/pytriqs/wrap_test/wrap_g.py b/test/pytriqs/wrap_test/wrap_g.py new file mode 100644 index 00000000..38fdc77f --- /dev/null +++ b/test/pytriqs/wrap_test/wrap_g.py @@ -0,0 +1,11 @@ +from pytriqs.wrap_test.test_g import * + +B = make_bgf(2.0) +pass_bgf(B+B) + +# run in python the h5diff between the 2 files... + +g = make_sgf(2.0) +pass_sgf(g) + +