1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 from inspect import getargspec
24 from re import search
25 import types
26 from unittest import TestCase
27
28
29 import dep_check
30 from generic_fns.structure.api_base import Base_struct_API
31 from generic_fns.structure.internal import Internal
32 from generic_fns.structure.scientific import Scientific_data
33 from status import Status; status = Status()
34
35
37 """Unit tests for the structural API base class."""
38
39 - def __init__(self, methodName='runTest'):
40 """Skip scientific Python tests if not installed.
41
42 @keyword methodName: The name of the test.
43 @type methodName: str
44 """
45
46
47 super(Test_api_base, self).__init__(methodName)
48
49
84
85
87 """The args of the public methods of the Internal structural object must be the same as the API base class."""
88
89
90 base = Base_struct_API()
91 intern = Internal()
92
93
94 for name in dir(intern):
95
96 if search('^_', name):
97 continue
98
99
100 obj_base = getattr(base, name)
101 obj_intern = getattr(intern, name)
102
103
104 if not isinstance(obj_base, types.MethodType):
105 continue
106
107
108 args_base, varargs_base, varkw_base, defaults_base = getargspec(obj_base)
109 args_intern, varargs_intern, varkw_intern, defaults_intern = getargspec(obj_intern)
110
111
112 if args_base != args_intern or varargs_base != varargs_intern or varkw_base != varkw_intern or defaults_base != defaults_intern:
113
114 doc_base = self.format_method(name, args_base, varargs_base, varkw_base, defaults_base)
115 doc_intern = self.format_method(name, args_intern, varargs_intern, varkw_intern, defaults_intern)
116 print(doc_base)
117
118
119 self.fail('The args of the method\n\t' + doc_intern + '\ndo not match those of the API method\n\t' + doc_base)
120
121
123 """Are the initial public objects of the Internal structural object all within the API base class?"""
124
125
126 base = Base_struct_API()
127 internal = Internal()
128
129
130 base_names = dir(base)
131
132
133 for name in dir(internal):
134
135 if search('^_', name):
136 continue
137
138
139 obj = getattr(internal, name)
140
141
142 if name not in base_names:
143 self.fail('The object ' + repr(name) + ' ' + repr(type(obj)) + ' cannot be found in the structural API base class.')
144
145
147 """The args of the public methods of the Scientific structural object must be the same as the API base class."""
148
149
150 base = Base_struct_API()
151 sci = Scientific_data()
152
153
154 for name in dir(sci):
155
156 if search('^_', name):
157 continue
158
159
160 obj_base = getattr(base, name)
161 obj_sci = getattr(sci, name)
162
163
164 if not isinstance(obj_base, types.MethodType):
165 continue
166
167
168 args_base, varargs_base, varkw_base, defaults_base = getargspec(obj_base)
169 args_sci, varargs_sci, varkw_sci, defaults_sci = getargspec(obj_sci)
170
171
172 if args_base != args_sci or varargs_base != varargs_sci or varkw_base != varkw_sci or defaults_base != defaults_sci:
173
174 doc_base = self.format_method(name, args_base, varargs_base, varkw_base, defaults_base)
175 doc_sci = self.format_method(name, args_sci, varargs_sci, varkw_sci, defaults_sci)
176
177
178 self.fail('The args of the method\n\t' + doc_sci + '\ndo not match those of the API method\n\t' + doc_base)
179
180
182 """Are the initial public objects of the Scientific structural object all within the API base class?"""
183
184
185 base = Base_struct_API()
186 sci = Scientific_data()
187
188
189 base_names = dir(base)
190
191
192 for name in dir(sci):
193
194 if search('^_', name):
195 continue
196
197
198 obj = getattr(sci, name)
199
200
201 if name not in base_names:
202 self.fail('The object ' + repr(name) + ' ' + repr(type(obj)) + ' cannot be found in the structural API base class.')
203