Skip to content

Commit

Permalink
add manifest; fix unit test setup
Browse files Browse the repository at this point in the history
  • Loading branch information
simleo committed Jan 22, 2019
1 parent 3e946f8 commit 567f694
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 41 deletions.
5 changes: 5 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include LICENSE README.md

include test/*.py
include test/*/*.py
include test/wrf/minimal.yaml
18 changes: 18 additions & 0 deletions test/all_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2018-2019 CRS4
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest

if __name__ == '__main__':
unittest.main(module=None)
Empty file added test/gfs/__init__.py
Empty file.
12 changes: 10 additions & 2 deletions test/gfs/test_noaa_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest
from tdm.gfs.noaa import noaa_fetcher

# TBD

class TestNOAAFetcher(unittest.TestCase):

def runTest(self):
# TBD
self.assertIsNotNone(noaa_fetcher)


if __name__ == "__main__":
print(noaa_fetcher)
unittest.main()
Empty file added test/radar/__init__.py
Empty file.
23 changes: 5 additions & 18 deletions test/radar/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@


THIS_DIR = os.path.dirname(os.path.abspath(__file__))
DATA_DIR = os.path.join(THIS_DIR, "data")


class TestEvents(unittest.TestCase):
Expand Down Expand Up @@ -173,14 +174,15 @@ def test_get_all_grouped(self):
self.assertEqual(res, exp_res)


@unittest.skipUnless(os.path.isdir(DATA_DIR), "requires sample data")
class TestSave(unittest.TestCase):

def setUp(self):
self.wd = tempfile.mkdtemp(prefix="tdm_")
self.raw_fn = os.path.join(
THIS_DIR, "data", "signal", "2018-05-01_23:00:04.png"
DATA_DIR, "signal", "2018-05-01_23:00:04.png"
)
self.template = os.path.join(THIS_DIR, "data", "radarfootprint.tif")
self.template = os.path.join(DATA_DIR, "radarfootprint.tif")

def tearDown(self):
shutil.rmtree(self.wd)
Expand Down Expand Up @@ -213,20 +215,5 @@ def test_gtiff(self):
self.assertTrue(np.ma.allclose(ma2, ma))


CASES = [
TestEvents,
TestGetImages,
TestSave,
]


def suite():
ret = unittest.TestSuite()
test_loader = unittest.TestLoader()
for c in CASES:
ret.addTest(test_loader.loadTestsFromTestCase(c))
return ret


if __name__ == '__main__':
unittest.TextTestRunner(verbosity=2).run((suite()))
unittest.main()
Empty file added test/wrf/__init__.py
Empty file.
34 changes: 13 additions & 21 deletions test/wrf/test_configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import unittest
import yaml

from tdm.wrf import configurator, configuration_checker

THIS_DIR = os.path.dirname(os.path.abspath(__file__))


def flatten_flat(assigned):
f = []
Expand All @@ -41,15 +45,15 @@ def flatten_domains(assigned):
return f


class test_configurator(unittest.TestCase):
class TestConfigurator(unittest.TestCase):

def setUp(self):
with open('minimal.yaml') as f:
with open(os.path.join(THIS_DIR, 'minimal.yaml')) as f:
assigned = yaml.load(f.read())
self.assigned = assigned
self.c = configurator.make(assigned)

def check_minimal(self):
def test_minimal(self):
c = self.c
assigned = self.assigned
for i, d in enumerate(c.domains_sequence):
Expand All @@ -66,7 +70,7 @@ def check_minimal(self):
for k, v in test_vals.items():
self.assertEqual(v, c[k])

def check_update(self):
def test_update(self):
c = self.c
updates = [('@base.geometry.e_we', 131),
('@dom1.geometry.e_we', 202),
Expand All @@ -85,7 +89,7 @@ def check_update(self):
else:
self.assertEqual(c[kd], v)

def check_time_step(self):
def test_time_step(self):
c = self.c
v = 44.1902
iv, iv_f_n, iv_f_d = 44, 951, 5000
Expand All @@ -100,7 +104,7 @@ def check_time_step(self):
self.assertEqual(c['global.running.time_step_fract_num'], iv_f_n)
self.assertEqual(c['global.running.time_step_fract_den'], iv_f_d)

def check_checker(self):
def test_checker(self):
c = self.c
cc = configuration_checker(c)
self.assertTrue(cc.check())
Expand All @@ -110,7 +114,7 @@ def check_checker(self):
cc = configuration_checker(c)
self.assertFalse(cc.check())

def check_generation(self):
def test_generation(self):
c = self.c
c.generate_share()
c.generate_geogrid()
Expand All @@ -125,7 +129,7 @@ def check_generation(self):
c.generate_grib2()
c.generate_namelist_quilt()

def check_domains(self):
def test_domains(self):
c = self.c
for dn, dv in c.domains.items():
self.assertEqual(dn, dv.name)
Expand All @@ -139,17 +143,5 @@ def check_domains(self):
(360000.0, 720000.0))


def suite():
suite_ = unittest.TestSuite()
suite_.addTest(test_configurator('check_minimal'))
suite_.addTest(test_configurator('check_update'))
suite_.addTest(test_configurator('check_time_step'))
suite_.addTest(test_configurator('check_generation'))
suite_.addTest(test_configurator('check_domains'))
suite_.addTest(test_configurator('check_checker'))
return suite_


if __name__ == '__main__':
_RUNNER = unittest.TextTestRunner(verbosity=2)
_RUNNER.run((suite()))
unittest.main()

0 comments on commit 567f694

Please sign in to comment.