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

test_dep_aacgmv2   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 100
Duplicated Lines 26 %

Importance

Changes 0
Metric Value
wmc 17
eloc 62
dl 26
loc 100
rs 10
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A TestDepAACGMV2Warning.setup() 0 5 1
A TestDepAACGMV2Warning.teardown() 0 2 1
A TestFutureDepWarning.setup() 5 5 1
A TestFutureDepWarning.teardown() 2 2 1
A TestFutureDepWarning.test_future_dep_warning() 16 16 3
A TestDepAACGMV2Warning.test_igrf_dipole_axis_warning() 0 6 1
A TestDepAACGMV2.test_gc2gd_lat_list() 0 8 2
A TestDepAACGMV2.teardown() 0 3 1
A TestDepAACGMV2.test_gc2gd_lat_arr() 0 8 2
A TestDepAACGMV2.test_gc2gd_lat() 0 7 2
A TestDepAACGMV2.test_subsol_warning() 0 6 1
A TestDepAACGMV2.setup() 0 5 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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