1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
from __future__ import division, absolute_import, unicode_literals |
3
|
|
|
|
4
|
|
|
import logging |
5
|
|
|
import os |
6
|
|
|
import pkgutil |
7
|
|
|
|
8
|
|
|
import aacgmv2 |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
# @pytest.mark.skip(reason="Not meant to be run alone") |
12
|
|
|
class TestModuleStructure: |
13
|
|
|
def setup(self): |
14
|
|
|
|
15
|
|
|
# Define the acceptable output |
16
|
|
|
if not hasattr(self, "reference_list"): |
17
|
|
|
self.reference_list = list() |
18
|
|
|
if not hasattr(self, "module_name"): |
19
|
|
|
self.module_name = None |
20
|
|
|
|
21
|
|
|
def teardown(self): |
22
|
|
|
del self.reference_list, self.module_name |
23
|
|
|
|
24
|
|
|
def test_module_existence(self): |
25
|
|
|
"""Test the module existence""" |
26
|
|
|
|
27
|
|
|
# Get the dictionary of functions for the specified module |
28
|
|
|
retrieved_dict = aacgmv2.__dict__ |
29
|
|
|
|
30
|
|
|
# Submodules only go one level down |
31
|
|
|
if self.module_name is None: |
32
|
|
|
assert True |
33
|
|
|
elif self.module_name != "aacgmv2": |
34
|
|
|
assert self.module_name in retrieved_dict.keys() |
35
|
|
|
else: |
36
|
|
|
assert isinstance(retrieved_dict, dict) |
37
|
|
|
|
38
|
|
|
def test_module_functions(self): |
39
|
|
|
"""Test module function structure""" |
40
|
|
|
|
41
|
|
|
# Get the dictionary of functions for the specified module |
42
|
|
|
retrieved_dict = aacgmv2.__dict__ |
43
|
|
|
|
44
|
|
|
if self.module_name is None: |
45
|
|
|
assert True |
46
|
|
|
else: |
47
|
|
|
if self.module_name != "aacgmv2": |
48
|
|
|
assert self.module_name in retrieved_dict.keys() |
49
|
|
|
retrieved_dict = retrieved_dict[self.module_name].__dict__ |
50
|
|
|
|
51
|
|
|
# Get the functions attached to this module and make sure they |
52
|
|
|
# are supposed to be there |
53
|
|
|
retrieved_list = list() |
54
|
|
|
for name in retrieved_dict.keys(): |
55
|
|
|
if callable(retrieved_dict[name]): |
56
|
|
|
assert name in self.reference_list |
57
|
|
|
retrieved_list.append(name) |
58
|
|
|
|
59
|
|
|
# Test to see if all of the modules match |
60
|
|
|
assert len(retrieved_list) == len(self.reference_list) |
61
|
|
|
|
62
|
|
|
def test_modules(self): |
63
|
|
|
"""Test module submodule structure""" |
64
|
|
|
|
65
|
|
|
if self.module_name is None: |
66
|
|
|
assert True |
67
|
|
|
else: |
68
|
|
|
# Get the submodules and make sure they are supposed to be there |
69
|
|
|
retrieved_list = list() |
70
|
|
|
for imp, name, ispkg in pkgutil.iter_modules(path=aacgmv2.__path__): |
71
|
|
|
assert name in self.reference_list |
72
|
|
|
retrieved_list.append(name) |
73
|
|
|
|
74
|
|
|
# Test to see if all of the modules match |
75
|
|
|
assert len(retrieved_list) == len(self.reference_list) |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
class TestDepStructure(TestModuleStructure): |
79
|
|
|
def setup(self): |
80
|
|
|
self.module_name = None |
81
|
|
|
self.reference_list = ["subsol", "igrf_dipole_axis"] |
82
|
|
|
|
83
|
|
|
def teardown(self): |
84
|
|
|
del self.module_name, self.reference_list |
85
|
|
|
|
86
|
|
|
def test_dep_existence(self): |
87
|
|
|
""" Test the deprecated functions""" |
88
|
|
|
self.module_name = "deprecated" |
89
|
|
|
self.test_module_existence() |
90
|
|
|
|
91
|
|
|
def test_dep_functions(self): |
92
|
|
|
""" Test the deprecated functions""" |
93
|
|
|
self.module_name = "deprecated" |
94
|
|
|
self.test_module_functions() |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
class TestUtilsStructure(TestModuleStructure): |
98
|
|
|
def setup(self): |
99
|
|
|
self.module_name = None |
100
|
|
|
self.reference_list = ["subsol", "igrf_dipole_axis"] |
101
|
|
|
|
102
|
|
|
def teardown(self): |
103
|
|
|
del self.module_name, self.reference_list |
104
|
|
|
|
105
|
|
|
def test_dep_existence(self): |
106
|
|
|
""" Test the utility functions""" |
107
|
|
|
self.module_name = "utils" |
108
|
|
|
self.test_module_existence() |
109
|
|
|
|
110
|
|
|
def test_dep_functions(self): |
111
|
|
|
""" Test the utility functions""" |
112
|
|
|
self.module_name = "utils" |
113
|
|
|
self.test_module_functions() |
114
|
|
|
|
115
|
|
|
|
116
|
|
|
class TestCStructure(TestModuleStructure): |
117
|
|
|
def setup(self): |
118
|
|
|
self.module_name = None |
119
|
|
|
self.reference_list = ["set_datetime", "convert", "inv_mlt_convert", |
120
|
|
|
"inv_mlt_convert_yrsec", "mlt_convert", |
121
|
|
|
"mlt_convert_yrsec", "inv_mlt_convert_arr", |
122
|
|
|
"mlt_convert_arr", "convert_arr"] |
123
|
|
|
|
124
|
|
|
def teardown(self): |
125
|
|
|
del self.module_name, self.reference_list |
126
|
|
|
|
127
|
|
|
def test_c_existence(self): |
128
|
|
|
""" Test the C module existence""" |
129
|
|
|
self.module_name = "_aacgmv2" |
130
|
|
|
self.test_module_existence() |
131
|
|
|
|
132
|
|
|
def test_c_functions(self): |
133
|
|
|
""" Test the C functions""" |
134
|
|
|
self.module_name = "_aacgmv2" |
135
|
|
|
self.test_module_functions() |
136
|
|
|
|
137
|
|
|
|
138
|
|
|
class TestPyStructure(TestModuleStructure): |
139
|
|
|
def setup(self): |
140
|
|
|
self.module_name = None |
141
|
|
|
self.reference_list = ["convert_bool_to_bit", "convert_str_to_bit", |
142
|
|
|
"convert_mlt", "convert_latlon", "test_height", |
143
|
|
|
"convert_latlon_arr", "get_aacgm_coord", |
144
|
|
|
"get_aacgm_coord_arr", "set_coeff_path", |
145
|
|
|
"test_time"] |
146
|
|
|
|
147
|
|
|
def teardown(self): |
148
|
|
|
del self.module_name, self.reference_list |
149
|
|
|
|
150
|
|
|
def test_py_existence(self): |
151
|
|
|
""" Test the python module existence""" |
152
|
|
|
self.module_name = "wrapper" |
153
|
|
|
self.test_module_existence() |
154
|
|
|
|
155
|
|
|
def test_py_functions(self): |
156
|
|
|
""" Test the python functions""" |
157
|
|
|
self.module_name = "wrapper" |
158
|
|
|
self.test_module_functions() |
159
|
|
|
|
160
|
|
|
|
161
|
|
|
class TestTopStructure(TestModuleStructure): |
162
|
|
|
def setup(self): |
163
|
|
|
self.module_name = None |
164
|
|
|
self.reference_list = list() |
165
|
|
|
|
166
|
|
|
def teardown(self): |
167
|
|
|
del self.module_name, self.reference_list |
168
|
|
|
|
169
|
|
|
def test_top_existence(self): |
170
|
|
|
""" Test the top level existence""" |
171
|
|
|
self.module_name = "aacgmv2" |
172
|
|
|
self.test_module_existence() |
173
|
|
|
|
174
|
|
|
def test_top_functions(self): |
175
|
|
|
""" Test the deprecated functions""" |
176
|
|
|
self.module_name = "aacgmv2" |
177
|
|
|
self.reference_list = ["convert_bool_to_bit", "convert_str_to_bit", |
178
|
|
|
"convert_mlt", "convert_latlon", |
179
|
|
|
"convert_latlon_arr", "get_aacgm_coord", |
180
|
|
|
"get_aacgm_coord_arr"] |
181
|
|
|
self.test_module_functions() |
182
|
|
|
|
183
|
|
|
def test_top_modules(self): |
184
|
|
|
""" Test the deprecated functions""" |
185
|
|
|
self.module_name = "aacgmv2" |
186
|
|
|
self.reference_list = ["_aacgmv2", "wrapper", "utils", |
187
|
|
|
"deprecated", "__main__"] |
188
|
|
|
self.test_modules() |
189
|
|
|
|
190
|
|
|
@classmethod |
191
|
|
|
def test_top_parameters(self): |
192
|
|
|
"""Test module constants""" |
193
|
|
|
|
194
|
|
|
path1 = os.path.join("aacgmv2", "aacgmv2", "aacgm_coeffs", |
195
|
|
|
"aacgm_coeffs-12-") |
196
|
|
|
if aacgmv2.AACGM_v2_DAT_PREFIX.find(path1) < 0: |
197
|
|
|
raise AssertionError() |
198
|
|
|
|
199
|
|
|
path2 = os.path.join("aacgmv2", "aacgmv2", "magmodel_1590-2015.txt") |
200
|
|
|
if aacgmv2.IGRF_COEFFS.find(path2) < 0: |
201
|
|
|
raise AssertionError() |
202
|
|
|
|
203
|
|
|
del path1, path2 |
204
|
|
|
|
205
|
|
|
@classmethod |
206
|
|
|
def test_high_alt_variables(self): |
207
|
|
|
""" Test that module altitude limits exist and are appropriate""" |
208
|
|
|
|
209
|
|
|
if not isinstance(aacgmv2.high_alt_coeff, float): |
210
|
|
|
raise TypeError("Coefficient upper limit not float") |
211
|
|
|
|
212
|
|
|
if not isinstance(aacgmv2.high_alt_trace, float): |
213
|
|
|
raise TypeError("Trace upper limit not float") |
214
|
|
|
|
215
|
|
|
if aacgmv2.high_alt_coeff != 2000.0: |
216
|
|
|
raise ValueError("unexpected coefficient upper limit") |
217
|
|
|
|
218
|
|
|
if aacgmv2.high_alt_trace <= aacgmv2.high_alt_trace: |
219
|
|
|
raise ValueError("Trace limit lower than coefficient limit") |
220
|
|
|
|
221
|
|
|
@classmethod |
222
|
|
|
def test_module_logger(self): |
223
|
|
|
""" Test the module logger instance""" |
224
|
|
|
|
225
|
|
|
if not isinstance(aacgmv2.logger, logging.Logger): |
226
|
|
|
raise TypeError("Logger incorrect type") |
227
|
|
|
|