コード例 #1
0
ファイル: test_ext_tools.py プロジェクト: mbentz80/jzigbeercp
    def check_assign_variable_types(self):
        try:
            from numpy.numerix import arange, Float32, Float64
        except:
            # skip this test if numpy.numerix not installed
            return

        import types
        a = arange(10,typecode = Float32)
        b = arange(5,typecode = Float64)
        c = 5
        arg_list = ['a','b','c']
        actual = ext_tools.assign_variable_types(arg_list,locals())
        #desired = {'a':(Float32,1),'b':(Float32,1),'i':(Int32,0)}

        ad = array_converter()
        ad.name, ad.var_type, ad.dims = 'a', Float32, 1
        bd = array_converter()
        bd.name, bd.var_type, bd.dims = 'b', Float64, 1

        cd = c_spec.int_converter()
        cd.name, cd.var_type = 'c', types.IntType
        desired = [ad,bd,cd]
        expr = ""
        print_assert_equal(expr,actual,desired)
コード例 #2
0
ファイル: test_wx_spec.py プロジェクト: mbentz80/jzigbeercp
 def no_check_var_local(self,level=5):
     mod = ext_tools.ext_module('wx_var_local')
     a = 'string'
     code = 'a="hello";'
     var_specs = ext_tools.assign_variable_types(['a'],locals())
     test = ext_tools.ext_function_from_specs('test',code,var_specs)
     mod.add_function(test)
     mod.compile()
     import wx_var_local
     b='bub'
     q={}
     wx_var_local.test(b,q)
     assert('a' == 'string')
コード例 #3
0
ファイル: test_ext_tools.py プロジェクト: apetcho/weave
    def test_assign_variable_types(self):
        a = arange(10, dtype=float32)
        b = arange(5, dtype=float64)
        c = 5
        arg_list = ['a','b','c']
        actual = ext_tools.assign_variable_types(arg_list,locals())

        ad = array_converter()
        ad.name, ad.var_type, ad.dims = 'a', float32, 1
        bd = array_converter()
        bd.name, bd.var_type, bd.dims = 'b', float64, 1

        cd = c_spec.int_converter()
        cd.name, cd.var_type = 'c', types.IntType
        desired = [ad,bd,cd]
        assert_equal(actual,desired)
コード例 #4
0
ファイル: test_ext_tools.py プロジェクト: apetcho/weave
 def test_return_tuple(self):
     # decalaring variables
     a = 2
     # declare module
     mod = ext_tools.ext_module('ext_return_tuple')
     var_specs = ext_tools.assign_variable_types(['a'],locals())
     code = """
            int b;
            b = a + 1;
            py::tuple returned(2);
            returned[0] = a;
            returned[1] = b;
            return_val = returned;
            """
     test = ext_tools.ext_function('test',code,['a'])
     mod.add_function(test)
     mod.compile(location=build_dir)
     import ext_return_tuple
     c,d = ext_return_tuple.test(a)
     assert_(c == a and d == a+1)
コード例 #5
0
 def test_return_tuple(self):
     # decalaring variables
     a = 2
     # declare module
     mod = ext_tools.ext_module('ext_return_tuple')
     var_specs = ext_tools.assign_variable_types(['a'],locals())
     code = """
            int b;
            b = a + 1;
            py::tuple returned(2);
            returned[0] = a;
            returned[1] = b;
            return_val = returned;
            """
     test = ext_tools.ext_function('test',code,['a'])
     mod.add_function(test)
     mod.compile(location=build_dir)
     import ext_return_tuple
     c,d = ext_return_tuple.test(a)
     assert_(c == a and d == a+1)
コード例 #6
0
ファイル: test_ext_tools.py プロジェクト: mbentz80/jzigbeercp
    def check_with_include(self,level=5):
        # decalaring variables
        a = 2.;

        # declare module
        mod = ext_tools.ext_module('ext_module_with_include')
        mod.customize.add_header('<iostream>')

        # function 2 --> a little more complex expression
        var_specs = ext_tools.assign_variable_types(['a'],locals(),globals())
        code = """
               std::cout << std::endl;
               std::cout << "test printing a value:" << a << std::endl;
               """
        test = ext_tools.ext_function_from_specs('test',code,var_specs)
        mod.add_function(test)
        # build module
        mod.compile(location = build_dir)
        import ext_module_with_include
        ext_module_with_include.test(a)
コード例 #7
0
    def test_with_include(self):
        # decalaring variables
        a = 2.

        # declare module
        mod = ext_tools.ext_module('ext_module_with_include')
        mod.customize.add_header('<iostream>')

        # function 2 --> a little more complex expression
        var_specs = ext_tools.assign_variable_types(['a'],locals(),globals())
        code = """
               std::cout.clear(std::ios_base::badbit);
               std::cout << std::endl;
               std::cout << "test printing a value:" << a << std::endl;
               std::cout.clear(std::ios_base::goodbit);
               """
        test = ext_tools.ext_function_from_specs('test',code,var_specs)
        mod.add_function(test)
        # build module
        mod.compile(location=build_dir)
        import ext_module_with_include
        ext_module_with_include.test(a)