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