diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..6de7d3a --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,5 @@ +include LICENSE README.md + +include test/*.py +include test/*/*.py +include test/wrf/minimal.yaml \ No newline at end of file diff --git a/test/all_tests.py b/test/all_tests.py new file mode 100644 index 0000000..7c2550e --- /dev/null +++ b/test/all_tests.py @@ -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) diff --git a/test/gfs/__init__.py b/test/gfs/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/gfs/test_noaa_fetcher.py b/test/gfs/test_noaa_fetcher.py index 14431c5..06637ac 100644 --- a/test/gfs/test_noaa_fetcher.py +++ b/test/gfs/test_noaa_fetcher.py @@ -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() diff --git a/test/radar/__init__.py b/test/radar/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/radar/test_utils.py b/test/radar/test_utils.py index 889465f..a06ab62 100644 --- a/test/radar/test_utils.py +++ b/test/radar/test_utils.py @@ -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): @@ -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) @@ -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() diff --git a/test/wrf/__init__.py b/test/wrf/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/wrf/test_configurator.py b/test/wrf/test_configurator.py index e57e067..2ead06d 100644 --- a/test/wrf/test_configurator.py +++ b/test/wrf/test_configurator.py @@ -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 = [] @@ -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): @@ -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), @@ -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 @@ -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()) @@ -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() @@ -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) @@ -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()