1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
from __future__ import division, absolute_import, unicode_literals |
3
|
|
|
|
4
|
|
|
import datetime as dt |
5
|
|
|
import numpy as np |
6
|
|
|
import pytest |
7
|
|
|
import aacgmv2 |
8
|
|
|
|
9
|
|
|
#@pytest.mark.skip(reason="Not meant to be run alone") |
10
|
|
|
class TestModuleStructure: |
11
|
|
|
def setup(self): |
12
|
|
|
|
13
|
|
|
# Define the acceptable output |
14
|
|
|
if not hasattr(self, "reference_list"): |
15
|
|
|
self.reference_list = list() |
16
|
|
|
if not hasattr(self, "module_name"): |
17
|
|
|
self.module_name = None |
18
|
|
|
|
19
|
|
|
def teardown(self): |
20
|
|
|
del self.reference_list, self.module_name |
21
|
|
|
|
22
|
|
|
def test_module_existence(self): |
23
|
|
|
"""Test the module existence""" |
24
|
|
|
|
25
|
|
|
# Get the dictionary of functions for the specified module |
26
|
|
|
retrieved_dict = aacgmv2.__dict__ |
27
|
|
|
|
28
|
|
|
# Submodules only go one level down |
29
|
|
|
if self.module_name is None: |
30
|
|
|
assert True |
31
|
|
|
elif self.module_name != "aacgmv2": |
32
|
|
|
assert self.module_name in retrieved_dict.keys() |
33
|
|
|
else: |
34
|
|
|
assert isinstance(retrieved_dict, dict) |
35
|
|
|
|
36
|
|
|
def test_module_functions(self): |
37
|
|
|
"""Test module function structure""" |
38
|
|
|
|
39
|
|
|
# Get the dictionary of functions for the specified module |
40
|
|
|
retrieved_dict = aacgmv2.__dict__ |
41
|
|
|
|
42
|
|
|
if self.module_name is None: |
43
|
|
|
assert True |
44
|
|
|
else: |
45
|
|
|
if self.module_name != "aacgmv2": |
46
|
|
|
assert self.module_name in retrieved_dict.keys() |
47
|
|
|
retrieved_dict = retrieved_dict[self.module_name].__dict__ |
48
|
|
|
|
49
|
|
|
# Get the functions attached to this module and make sure they |
50
|
|
|
# are supposed to be there |
51
|
|
|
retrieved_list = list() |
52
|
|
|
for name in retrieved_dict.keys(): |
53
|
|
|
if callable(retrieved_dict[name]): |
54
|
|
|
assert name in self.reference_list |
55
|
|
|
retrieved_list.append(name) |
56
|
|
|
|
57
|
|
|
# Test to see if all of the modules match |
58
|
|
|
assert len(retrieved_list) == len(self.reference_list) |
59
|
|
|
|
60
|
|
|
def test_modules(self): |
61
|
|
|
"""Test module submodule structure""" |
62
|
|
|
import os |
63
|
|
|
import pkgutil |
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
|
|
|
class TestDepStructure(TestModuleStructure): |
78
|
|
|
def setup(self): |
79
|
|
|
self.module_name = None |
80
|
|
|
self.reference_list = ["convert", "subsol", "gc2gd_lat", |
81
|
|
|
"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
|
|
|
class TestCStructure(TestModuleStructure): |
97
|
|
|
def setup(self): |
98
|
|
|
self.module_name = None |
99
|
|
|
self.reference_list = ["set_datetime", "convert", "inv_mlt_convert", |
100
|
|
|
"inv_mlt_convert_yrsec", "mlt_convert", |
101
|
|
|
"mlt_convert_yrsec"] |
102
|
|
|
|
103
|
|
|
def teardown(self): |
104
|
|
|
del self.module_name, self.reference_list |
105
|
|
|
|
106
|
|
|
def test_c_existence(self): |
107
|
|
|
""" Test the C module existence""" |
108
|
|
|
self.module_name = "_aacgmv2" |
109
|
|
|
self.test_module_existence() |
110
|
|
|
|
111
|
|
|
def test_c_functions(self): |
112
|
|
|
""" Test the C functions""" |
113
|
|
|
self.module_name = "_aacgmv2" |
114
|
|
|
self.test_module_functions() |
115
|
|
|
|
116
|
|
|
|
117
|
|
|
class TestPyStructure(TestModuleStructure): |
118
|
|
|
def setup(self): |
119
|
|
|
self.module_name = None |
120
|
|
|
self.reference_list = ["convert_bool_to_bit", "convert_str_to_bit", |
121
|
|
|
"convert_mlt", "convert_latlon", |
122
|
|
|
"convert_latlon_arr", "get_aacgm_coord", |
123
|
|
|
"get_aacgm_coord_arr", "set_coeff_path"] |
124
|
|
|
|
125
|
|
|
def teardown(self): |
126
|
|
|
del self.module_name, self.reference_list |
127
|
|
|
|
128
|
|
|
def test_py_existence(self): |
129
|
|
|
""" Test the python module existence""" |
130
|
|
|
self.module_name = "wrapper" |
131
|
|
|
self.test_module_existence() |
132
|
|
|
|
133
|
|
|
def test_py_functions(self): |
134
|
|
|
""" Test the python functions""" |
135
|
|
|
self.module_name = "wrapper" |
136
|
|
|
self.test_module_functions() |
137
|
|
|
|
138
|
|
|
|
139
|
|
|
class TestTopStructure(TestModuleStructure): |
140
|
|
|
def setup(self): |
141
|
|
|
self.module_name = None |
142
|
|
|
self.reference_list = list() |
143
|
|
|
|
144
|
|
|
def teardown(self): |
145
|
|
|
del self.module_name, self.reference_list |
146
|
|
|
|
147
|
|
|
def test_top_existence(self): |
148
|
|
|
""" Test the top level existence""" |
149
|
|
|
self.module_name = "aacgmv2" |
150
|
|
|
self.test_module_existence() |
151
|
|
|
|
152
|
|
|
def test_top_functions(self): |
153
|
|
|
""" Test the deprecated functions""" |
154
|
|
|
self.module_name = "aacgmv2" |
155
|
|
|
self.reference_list = ["convert_bool_to_bit", "convert_str_to_bit", |
156
|
|
|
"convert_mlt", "convert_latlon", |
157
|
|
|
"convert_latlon_arr", "get_aacgm_coord", |
158
|
|
|
"get_aacgm_coord_arr", "convert"] |
159
|
|
|
self.test_module_functions() |
160
|
|
|
|
161
|
|
|
def test_top_modules(self): |
162
|
|
|
""" Test the deprecated functions""" |
163
|
|
|
self.module_name = "aacgmv2" |
164
|
|
|
self.reference_list = ["_aacgmv2", "wrapper", |
165
|
|
|
"deprecated", "__main__"] |
166
|
|
|
self.test_modules() |
167
|
|
|
|
168
|
|
|
@classmethod |
169
|
|
|
def test_top_parameters(self): |
170
|
|
|
"""Test module constants""" |
171
|
|
|
from os import path |
172
|
|
|
|
173
|
|
|
path1 = path.join("aacgmv2", "aacgmv2", "aacgm_coeffs", |
174
|
|
|
"aacgm_coeffs-12-") |
175
|
|
|
if aacgmv2.AACGM_v2_DAT_PREFIX.find(path1) < 0: |
176
|
|
|
raise AssertionError() |
177
|
|
|
|
178
|
|
|
path2 = path.join("aacgmv2", "aacgmv2", "magmodel_1590-2015.txt") |
179
|
|
|
if aacgmv2.IGRF_COEFFS.find(path2) < 0: |
180
|
|
|
raise AssertionError() |
181
|
|
|
|
182
|
|
|
del path1, path2 |
183
|
|
|
|