Skip to content

Commit

Permalink
STY: rearrange test classes
Browse files Browse the repository at this point in the history
Rearrange test classes to improve coverage.
  • Loading branch information
aburrell committed Jan 20, 2023
1 parent 8da7393 commit bfb5ce2
Showing 1 changed file with 29 additions and 35 deletions.
64 changes: 29 additions & 35 deletions aacgmv2/tests/test_py_aacgmv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@ class TestConvertArray(object):
"""Unit tests for array conversion."""
def setup_method(self):
"""Create a clean test environment."""
self.dtime = dt.datetime(2015, 1, 1, 0, 0, 0)
self.ddate = dt.date(2015, 1, 1)
self.lat_in = [60.0, 61.0]
self.lon_in = [0.0, 0.0]
self.alt_in = [300.0, 300.0]
self.method = 'TRACE'
self.out = None
self.ref = None
self.ref = [[58.22676, 59.31847], [81.16135, 81.60797],
[0.18880, 0.21857]]
self.rtol = 1.0e-4

def teardown_method(self):
"""Clean up the test envrionment."""
del self.out, self.ref, self.rtol
del self.out, self.ref, self.lat_in, self.dtime, self.ddate
del self.lon_in, self.alt_in, self.method, self.rtol

def evaluate_output(self, ind=None):
"""Function used to evaluate convert_latlon_arr output.
Expand All @@ -45,6 +53,7 @@ def evaluate_output(self, ind=None):

class TestConvertLatLon(object):
"""Unit tests for single value conversion."""

def setup_method(self):
"""Create a clean test environment."""
self.dtime = dt.datetime(2015, 1, 1, 0, 0, 0)
Expand Down Expand Up @@ -143,28 +152,14 @@ def test_convert_latlon_failure(self, in_rep, in_irep, msg):

class TestConvertLatLonArr(TestConvertArray):
"""Unit tests for Lat/Lon array conversion."""
def setup_method(self):
"""Create a clean test environment."""
self.dtime = dt.datetime(2015, 1, 1, 0, 0, 0)
self.ddate = dt.date(2015, 1, 1)
self.lat_in = [60.0, 61.0]
self.lon_in = [0.0, 0.0]
self.alt_in = [300.0, 300.0]
self.method = 'TRACE'
self.out = None
self.ref = [[58.2268, 59.3184], [81.1613, 81.6080], [1.0457, 1.0456]]
self.rtol = 1.0e-4

def teardown_method(self):
"""Clean up the test envrionment."""
del self.lat_in, self.lon_in, self.alt_in, self.dtime, self.ddate
del self.method, self.out, self.ref, self.rtol

def test_convert_latlon_arr_single_val(self):
"""Test array latlon conversion for a single value."""
self.out = aacgmv2.convert_latlon_arr(self.lat_in[0], self.lon_in[0],
self.alt_in[0], self.dtime,
self.method)

self.ref[2][0] = 1.0457
self.evaluate_output(ind=0)

def test_convert_latlon_arr_arr_single(self):
Expand All @@ -173,6 +168,8 @@ def test_convert_latlon_arr_arr_single(self):
np.array([self.lon_in[0]]),
np.array([self.alt_in[0]]),
self.dtime, self.method)

self.ref[2][0] = 1.0457
self.evaluate_output(ind=0)

def test_convert_latlon_arr_list_single(self):
Expand All @@ -181,13 +178,17 @@ def test_convert_latlon_arr_list_single(self):
[self.lon_in[0]],
[self.alt_in[0]], self.dtime,
self.method)

self.ref[2][0] = 1.0457
self.evaluate_output(ind=0)

def test_convert_latlon_arr_list(self):
"""Test array latlon conversion for list input."""
self.out = aacgmv2.convert_latlon_arr(self.lat_in, self.lon_in,
self.alt_in, self.dtime,
self.method)

self.ref[2] = [1.0457, 1.0456]
self.evaluate_output()

def test_convert_latlon_arr_arr(self):
Expand All @@ -196,20 +197,26 @@ def test_convert_latlon_arr_arr(self):
np.array(self.lon_in),
np.array(self.alt_in),
self.dtime, self.method)

self.ref[2] = [1.0457, 1.0456]
self.evaluate_output()

def test_convert_latlon_arr_list_mix(self):
"""Test array latlon conversion for mixed types with list."""
self.out = aacgmv2.convert_latlon_arr(self.lat_in, self.lon_in[0],
self.alt_in[0], self.dtime,
self.method)

self.ref[2] = [1.0457, 1.0456]
self.evaluate_output()

def test_convert_latlon_arr_arr_mix(self):
"""Test array latlon conversion for mixed type with an array."""
self.out = aacgmv2.convert_latlon_arr(np.array(self.lat_in),
self.lon_in[0], self.alt_in[0],
self.dtime, self.method)

self.ref[2] = [1.0457, 1.0456]
self.evaluate_output()

def test_convert_latlon_arr_arr_mult_and_single_element(self):
Expand All @@ -218,6 +225,8 @@ def test_convert_latlon_arr_arr_mult_and_single_element(self):
np.array([self.lon_in[0]]),
np.array(self.alt_in),
self.dtime, self.method)

self.ref[2] = [1.0457, 1.0456]
self.evaluate_output()

@pytest.mark.parametrize('method_code,alt,local_ref',
Expand Down Expand Up @@ -262,6 +271,8 @@ def test_convert_latlon_arr_datetime_date(self):
self.out = aacgmv2.convert_latlon_arr(self.lat_in, self.lon_in,
self.alt_in, self.ddate,
self.method)

self.ref[2] = [1.0457, 1.0456]
self.evaluate_output()

def test_convert_latlon_arr_clip(self):
Expand Down Expand Up @@ -376,23 +387,6 @@ def test_get_aacgm_coord_raise_value_error(self, in_index, value):

class TestGetAACGMCoordArr(TestConvertArray):
"""Unit tests for AACGM coordinate array conversion."""
def setup_method(self):
"""Create a clean test environment."""
self.dtime = dt.datetime(2015, 1, 1, 0, 0, 0)
self.ddate = dt.date(2015, 1, 1)
self.lat_in = [60.0, 61.0]
self.lon_in = [0.0, 0.0]
self.alt_in = [300.0, 300.0]
self.method = 'TRACE'
self.out = None
self.ref = [[58.22676, 59.31847], [81.16135, 81.60797],
[0.18880, 0.21857]]
self.rtol = 1.0e-4

def teardown_method(self):
"""Clean up the test envrionment."""
del self.out, self.ref, self.lat_in, self.dtime, self.ddate
del self.lon_in, self.alt_in, self.method, self.rtol

def test_get_aacgm_coord_arr_single_val(self):
"""Test array AACGMV2 calculation for a single value."""
Expand Down

0 comments on commit bfb5ce2

Please sign in to comment.