File: test_wx_spec.py

package info (click to toggle)
python-scipy 0.5.2-0.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 33,888 kB
  • ctags: 44,231
  • sloc: ansic: 156,256; cpp: 90,347; python: 89,604; fortran: 73,083; sh: 1,318; objc: 424; makefile: 342
file content (94 lines) | stat: -rw-r--r-- 3,105 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"""
check_var_in -- tests whether a variable is passed in correctly
                and also if the passed in variable can be reassigned
check_var_local -- tests wheter a variable is passed in , modified,
                   and returned correctly in the local_dict dictionary
                   argument
check_return -- test whether a variable is passed in, modified, and
                then returned as a function return value correctly
"""

from numpy.testing import *
set_package_path()
from weave import ext_tools, wx_spec
restore_path()

import wxPython
import wxPython.wx

class test_wx_converter(ScipyTestCase):
    def check_type_match_string(self,level=5):
        s = wx_spec.wx_converter()
        assert(not s.type_match('string') )
    def check_type_match_int(self,level=5):
        s = wx_spec.wx_converter()
        assert(not s.type_match(5))
    def check_type_match_float(self,level=5):
        s = wx_spec.wx_converter()
        assert(not s.type_match(5.))
    def check_type_match_complex(self,level=5):
        s = wx_spec.wx_converter()
        assert(not s.type_match(5.+1j))
    def check_type_match_complex(self,level=5):
        s = wx_spec.wx_converter()
        assert(not s.type_match(5.+1j))
    def check_type_match_wxframe(self,level=5):
        s = wx_spec.wx_converter()
        f=wxPython.wx.wxFrame(wxPython.wx.NULL,-1,'bob')
        assert(s.type_match(f))

    def check_var_in(self,level=5):
        mod = ext_tools.ext_module('wx_var_in',compiler='msvc')
        a = wxPython.wx.wxFrame(wxPython.wx.NULL,-1,'bob')
        code = """
               a->SetTitle(wxString("jim"));
               """
        test = ext_tools.ext_function('test',code,['a'],locals(),globals())
        mod.add_function(test)
        mod.compile()
        import wx_var_in
        b=a
        wx_var_in.test(b)
        assert(b.GetTitle() == "jim")
        try:
            b = 1.
            wx_var_in.test(b)
        except TypeError:
            pass
        try:
            b = 1
            wx_var_in.test(b)
        except TypeError:
            pass

    def no_check_var_local(self,level=5):
        mod = ext_tools.ext_module('wx_var_local')
        a = 'string'
        var_specs = ext_tools.assign_variable_types(['a'],locals())
        code = 'a=Py::String("hello");'
        test = ext_tools.ext_function('test',var_specs,code)
        mod.add_function(test)
        mod.compile()
        import wx_var_local
        b='bub'
        q={}
        wx_var_local.test(b,q)
        assert(q['a'] == 'hello')
    def no_check_return(self,level=5):
        mod = ext_tools.ext_module('wx_return')
        a = 'string'
        var_specs = ext_tools.assign_variable_types(['a'],locals())
        code = """
               a= Py::wx("hello");
               return_val = Py::new_reference_to(a);
               """
        test = ext_tools.ext_function('test',var_specs,code)
        mod.add_function(test)
        mod.compile()
        import wx_return
        b='bub'
        c = wx_return.test(b)
        assert( c == 'hello')

if __name__ == "__main__":
    ScipyTest().run()