Skip to content

Commit

Permalink
Add unit tests and a bit of cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
billsacks committed Aug 20, 2021
1 parent 89497d3 commit 77369bb
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
2 changes: 1 addition & 1 deletion python/ctsm/regional_case.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from base_case import BaseCase
from ctsm.base_case import BaseCase

import numpy as np
import xarray as xr
Expand Down
2 changes: 1 addition & 1 deletion python/ctsm/single_point_case.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from base_case import BaseCase
from ctsm.base_case import BaseCase
import os
import numpy as np
import xarray as xr
Expand Down
10 changes: 5 additions & 5 deletions python/ctsm/subset_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@
from getpass import getuser
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter

from base_case import BaseCase
from single_point_case import SinglePointCase
from regional_case import RegionalCase
from ctsm.base_case import BaseCase
from ctsm.single_point_case import SinglePointCase
from ctsm.regional_case import RegionalCase

myname = getuser()

Expand Down Expand Up @@ -373,9 +373,9 @@ def plon_type(x):
"""
x = float(x)
if (-180 < x) and (x < 0):
print ("lon is :", lon)
print ("lon is :", x)
x= x%360
print ("after modulo lon is :", lon)
print ("after modulo lon is :", x)
if (x < 0) or (x > 360):
raise argparse.ArgumentTypeError("ERROR: Latitude of single point should be between 0 and 360 or -180 and 180.")
return x
Expand Down
32 changes: 32 additions & 0 deletions python/ctsm/test/test_unit_subset_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python3

import unittest
import argparse

from ctsm.subset_data import plon_type
from ctsm import unit_testing

# Allow names that pylint doesn't like, because otherwise I find it hard
# to make readable unit test names
# pylint: disable=invalid-name

class TestSubsetData(unittest.TestCase):

def test_plonType_positive(self):
result = plon_type(30)
self.assertEqual(result, 30.)

def test_plonType_negative(self):
result = plon_type(-30)
self.assertEqual(result, 330.)

def test_plonType_outOfBounds(self):
with self.assertRaisesRegex(argparse.ArgumentTypeError,
"Latitude.*should be between"):
_ = plon_type(361)

"""Unit tests for subset_data
"""
if __name__ == '__main__':
unit_testing.setup_for_tests()
unittest.main()

0 comments on commit 77369bb

Please sign in to comment.