|
1
|
|
|
"""Unit tests for deprecation warnings.""" |
|
2
|
|
|
import datetime as dt |
|
3
|
|
|
import warnings |
|
4
|
|
|
|
|
5
|
|
|
import aacgmv2 |
|
6
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
class TestFutureDepWarning(object): |
|
9
|
|
|
"""Unit tests for deprecation warnings.""" |
|
10
|
|
|
|
|
11
|
|
|
def setup_method(self): |
|
12
|
|
|
"""Create a clean test environment.""" |
|
13
|
|
|
# Initialize the routine to be tested |
|
14
|
|
|
self.test_routine = None |
|
15
|
|
|
self.test_args = [] |
|
16
|
|
|
self.test_kwargs = {} |
|
17
|
|
|
|
|
18
|
|
|
def teardown_method(self): |
|
19
|
|
|
"""Clean up the test environment.""" |
|
20
|
|
|
del self.test_routine, self.test_args, self.test_kwargs |
|
21
|
|
|
|
|
22
|
|
|
def test_future_dep_warning(self): |
|
23
|
|
|
"""Test the implementation of FutureWarning for dupicate routines.""" |
|
24
|
|
|
if self.test_routine is None: |
|
25
|
|
|
assert True |
|
26
|
|
|
else: |
|
27
|
|
|
with warnings.catch_warnings(record=True) as wout: |
|
28
|
|
|
# Cause all warnings to always be triggered. |
|
29
|
|
|
warnings.simplefilter("always") |
|
30
|
|
|
|
|
31
|
|
|
# Trigger a warning. |
|
32
|
|
|
self.test_routine(*self.test_args, **self.test_kwargs) |
|
33
|
|
|
|
|
34
|
|
|
# Verify some things |
|
35
|
|
|
assert len(wout) == 1 |
|
36
|
|
|
assert issubclass(wout[-1].category, FutureWarning) |
|
37
|
|
|
assert "Duplicate routine" in str(wout[-1].message) |
|
38
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
class TestDepAACGMV2Warning(TestFutureDepWarning): |
|
41
|
|
|
"""Unit tests for AACGMV2 deprecation warnings.""" |
|
42
|
|
|
|
|
43
|
|
|
def setup_method(self): |
|
44
|
|
|
"""Create a clean test environment.""" |
|
45
|
|
|
self.dtime = dt.datetime(2015, 1, 1, 0, 0, 0) |
|
46
|
|
|
self.test_routine = None |
|
47
|
|
|
self.test_args = [] |
|
48
|
|
|
self.test_kwargs = {} |
|
49
|
|
|
|
|
50
|
|
|
def teardown_method(self): |
|
51
|
|
|
"""Clean up the test environment.""" |
|
52
|
|
|
del self.dtime, self.test_routine, self.test_args, self.test_kwargs |
|
53
|
|
|
|
|
54
|
|
|
def test_igrf_dipole_axis_warning(self): |
|
55
|
|
|
"""Test future deprecation warning for igrf_dipole_axis.""" |
|
56
|
|
|
self.test_routine = aacgmv2.deprecated.igrf_dipole_axis |
|
57
|
|
|
self.test_args = [self.dtime] |
|
58
|
|
|
self.test_future_dep_warning() |
|
59
|
|
|
|
|
60
|
|
|
def test_subsol_warning(self): |
|
61
|
|
|
"""Test future deprecation warning for subsol.""" |
|
62
|
|
|
self.test_routine = aacgmv2.deprecated.subsol |
|
63
|
|
|
self.test_args = [self.dtime.year, 1, 1.0] |
|
64
|
|
|
self.test_future_dep_warning() |
|
65
|
|
|
|
|
66
|
|
|
def test_gc2gd_lat(self): |
|
67
|
|
|
"""Test future deprecation warning for gc2gd_lat.""" |
|
68
|
|
|
self.test_routine = aacgmv2.deprecated.gc2gd_lat |
|
69
|
|
|
self.test_args = [45.0] |
|
70
|
|
|
self.test_future_dep_warning() |
|
71
|
|
|
|