Passed
Push — develop ( 885684...7d5043 )
by Angeline
01:39
created

TestDepAACGMV2.test_subsol_warning()   A

Complexity

Conditions 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nop 1
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 warnings
7
8
import aacgmv2
9
10
11 View Code Duplication
class TestFutureDepWarning:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
12
    def setup(self):
13
        # Initialize the routine to be tested
14
        self.test_routine = None
15
        self.test_args = []
16
        self.test_kwargs = {}
17
18
    def teardown(self):
19
        del self.test_routine, self.test_args, self.test_kwargs
20
21
    def test_future_dep_warning(self):
22
        """Test the implementation of FutureWarning for dupicate routines"""
23
        if self.test_routine is None:
24
            assert True
25
        else:
26
            with warnings.catch_warnings(record=True) as wout:
27
                # Cause all warnings to always be triggered.
28
                warnings.simplefilter("always")
29
30
                # Trigger a warning.
31
                self.test_routine(*self.test_args, **self.test_kwargs)
32
33
                # Verify some things
34
                assert len(wout) == 1
35
                assert issubclass(wout[-1].category, FutureWarning)
36
                assert "Duplicate routine" in str(wout[-1].message)
37
38
39
class TestDepAACGMV2Warning(TestFutureDepWarning):
40
    def setup(self):
41
        self.dtime = dt.datetime(2015, 1, 1, 0, 0, 0)
42
        self.test_routine = None
43
        self.test_args = []
44
        self.test_kwargs = {}
45
46
    def teardown(self):
47
        del self.dtime, self.test_routine, self.test_args, self.test_kwargs
48
49
    def test_igrf_dipole_axis_warning(self):
50
        """Test future deprecation warning for igrf_dipole_axis"""
51
52
        self.test_routine = aacgmv2.deprecated.igrf_dipole_axis
53
        self.test_args = [self.dtime]
54
        self.test_future_dep_warning()
55
56
57
class TestDepAACGMV2:
58
    def setup(self):
59
        """Runs before every method to create a clean testing setup"""
60
        self.dtime = dt.datetime(2015, 1, 1, 0, 0, 0)
61
        self.lat = None
62
        self.lon = None
63
64
    def teardown(self):
65
        """Runs after every method to clean up previous testing"""
66
        del self.dtime, self.lat, self.lon
67
68
    def test_gc2gd_lat(self):
69
        """Test the geocentric to geodetic conversion"""
70
        with warnings.catch_warnings():
71
            warnings.simplefilter("ignore")
72
            self.lat = aacgmv2.deprecated.gc2gd_lat(45.0)
73
74
        np.testing.assert_almost_equal(self.lat, 45.1924, decimal=4)
75
76
    def test_gc2gd_lat_list(self):
77
        """Test the geocentric to geodetic conversion"""
78
        self.lat = [45.0, -45.0]
79
        with warnings.catch_warnings():
80
            warnings.simplefilter("ignore")
81
            self.lat = aacgmv2.deprecated.gc2gd_lat(self.lat)
82
83
        np.testing.assert_allclose(self.lat, [45.1924, -45.1924], rtol=1.0e-4)
84
85
    def test_gc2gd_lat_arr(self):
86
        """Test the geocentric to geodetic conversion"""
87
        self.lat = np.array([45.0, -45.0])
88
        with warnings.catch_warnings():
89
            warnings.simplefilter("ignore")
90
            self.lat = aacgmv2.deprecated.gc2gd_lat(self.lat)
91
92
        np.testing.assert_allclose(self.lat, [45.1924, -45.1924], rtol=1.0e-4)
93
94
    def test_subsol_warning(self):
95
        """Test future deprecation warning for subsol"""
96
97
        self.test_routine = aacgmv2.deprecated.subsol
98
        self.test_args = [self.dtime.year, 1, 1.0]
99
        self.test_future_dep_warning()
100
101