Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added checks for loggers and repr + updated setup.py test commands #147

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
import io
import os
import re
from setuptools import Command, find_packages, setup
import shutil
import sys

from setuptools import Command, find_packages, setup


class PyCleanBuild(Command):
Expand Down Expand Up @@ -63,7 +65,7 @@ def run(self):
os.remove('../{}'.format(file_))


class PyTest(Command):
class Unittest(Command):
user_options = []

def initialize_options(self):
Expand All @@ -74,7 +76,8 @@ def finalize_options(self):

def run(self):
import subprocess
errno = subprocess.call(['pytest'])
errno = subprocess.call([sys.executable,
'-m', 'unittest', 'discover'])
raise SystemExit(errno)


Expand All @@ -91,10 +94,9 @@ def run(self):
import subprocess

errno = subprocess.call(['coverage', 'run',
'--source=geomet_data_registry',
'-m', 'unittest',
'geomet_data_registry.tests.run_tests'])
errno = subprocess.call(['coverage', 'report', '-m'])
'-m', 'unittest', 'discover'])
errno = subprocess.call(['coverage', 'report', '-m',
'--include=geomet_data_registry/layer/*.py'])
raise SystemExit(errno)


Expand Down Expand Up @@ -156,7 +158,7 @@ def get_package_version():
'Programming Language :: Python'
],
cmdclass={
'test': PyTest,
'test': Unittest,
'coverage': PyCoverage,
'cleanbuild': PyCleanBuild
}
Expand Down
26 changes: 21 additions & 5 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ def test_is_valid_interval(self):

self.assertListEqual(return_list, [True, True, False])

def test_repr(self):
self.assertEqual(
repr(self.base_layer),
'<BaseLayer> model_gem_global'
)


class TestRegister(unittest.TestCase, Setup):
def setUp(self):
Expand All @@ -191,10 +197,15 @@ def tearDown(self):
def test_register_no_items(self):
"""
Test that when no items are identified
geomet_data_registry.layer.base.register() returns False.
geomet_data_registry.layer.base.register()
returns False and an error is logged.
"""

self.assertFalse(self.base_layer.register())
with self.assertLogs(
'geomet_data_registry.layer.base', level='ERROR'
) as err:
self.assertFalse(self.base_layer.register())
# assert a single LOGGER.error was called
self.assertEqual(len(err.records), 1)

def test_register_one_item(self):
"""
Expand Down Expand Up @@ -354,7 +365,7 @@ def test_update_count_expected_81(self):
def test_update_count_incomplete_mr(self):
"""
Test that the appropriate model run count is reset when an imcomplete
model run is identified.
model run is identified and an error is logged.
"""

# store.get_key() will return these values in sequence like a generator
Expand All @@ -372,7 +383,12 @@ def test_update_count_incomplete_mr(self):
call('model_gem_global_TMP_TGL_2_12Z_count', 0),
]

self.base_layer.update_count(self.item, 201)
with self.assertLogs(
'geomet_data_registry.layer.base', level='ERROR'
) as err:
self.base_layer.update_count(self.item, 201)
# assert a single LOGGER.error was called
self.assertEqual(len(err.records), 1)

self.mocked_load_plugin.return_value.set_key.assert_has_calls(calls)

Expand Down
18 changes: 16 additions & 2 deletions tests/test_cansips.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ def test_super_init(self):
# assert super().__init__() was called with the correct provider def
self.mocked_base_init.assert_called_with({'name': 'cansips'})

def test_repr(self):
self.assertEqual(
repr(self.layer_handler['cansips']),
'<ModelCanSIPSLayer> cansips'
)


class TestIdentify(unittest.TestCase, Setup):
def setUp(self):
Expand Down Expand Up @@ -161,9 +167,17 @@ def test_items_identify(self):
)

def test_unsuccessful_identify(self):
# assert identify returns False when the wx_variable isn't correct
# assert identify returns False when the wx_variable
# isn't correct and a warning is logged.
self.filepath = self.filepath.replace('PRATE_SFC_0', 'Not_wx_variable')
self.assertFalse(self.layer_handler['cansips'].identify(self.filepath))
with self.assertLogs(
'geomet_data_registry.layer.cansips', level='WARNING'
) as warn:
self.assertFalse(
self.layer_handler['cansips'].identify(self.filepath)
)
# assert a single LOGGER.warning was called
self.assertEqual(len(warn.records), 1)


class TestAddTimeKey(unittest.TestCase, Setup):
Expand Down
18 changes: 16 additions & 2 deletions tests/test_cgsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ def test_super_init(self):
# assert super().__init__() was called with the correct provider def
self.mocked_base_init.assert_called_with({'name': 'cgsl'})

def test_repr(self):
self.assertEqual(
repr(self.layer_handler['cgsl']),
'<ModelCgslGlobalLayer> cgsl'
)


class TestIdentify(unittest.TestCase, Setup):
def setUp(self):
Expand Down Expand Up @@ -174,9 +180,17 @@ def test_invalid_interval_identify(self):
)

def test_unsuccessful_identify(self):
# assert identify returns False when the wx_variable isn't correct
# assert identify returns False when the wx_variable
# isn't correct and a warning is logged.
self.filepath = self.filepath.replace('ocean', 'Not_wx_variable')
self.assertFalse(self.layer_handler['cgsl'].identify(self.filepath))
with self.assertLogs(
'geomet_data_registry.layer.cgsl', level='WARNING'
) as warn:
self.assertFalse(
self.layer_handler['cgsl'].identify(self.filepath)
)
# assert a single LOGGER.warning was called
self.assertEqual(len(warn.records), 1)


if __name__ == '__main__':
Expand Down
18 changes: 16 additions & 2 deletions tests/test_gdwps.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ def test_super_init(self):
# assert super().__init__() was called with the correct provider def
self.mocked_base_init.assert_called_with({'name': 'gdwps'})

def test_repr(self):
self.assertEqual(
repr(self.layer_handler['gdwps']),
'<ModelGdwpsLayer> gdwps'
)


class TestIdentify(unittest.TestCase, Setup):
def setUp(self):
Expand Down Expand Up @@ -258,9 +264,17 @@ def test_invalid_interval_identify(self):
)

def test_unsuccessful_identify(self):
# assert identify returns False when the wx_variable isn't correct
# assert identify returns False when the wx_variable
# isn't correct and a warning is logged.
self.filepath = self.filepath.replace('HTSGW_Sfc', 'Not_wx_variable')
self.assertFalse(self.layer_handler['gdwps'].identify(self.filepath))
with self.assertLogs(
'geomet_data_registry.layer.gdwps', level='WARNING'
) as warn:
self.assertFalse(
self.layer_handler['gdwps'].identify(self.filepath)
)
# assert a single LOGGER.warning was called
self.assertEqual(len(warn.records), 1)


if __name__ == '__main__':
Expand Down
18 changes: 16 additions & 2 deletions tests/test_geps.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ def test_super_init(self):
# assert super().__init__() was called with the correct provider def
self.mocked_base_init.assert_called_with({'name': 'geps'})

def test_repr(self):
self.assertEqual(
repr(self.layer_handler['geps']),
'<ModelGEPSLayer> geps'
)


class TestIdentify(unittest.TestCase, Setup):
def setUp(self):
Expand Down Expand Up @@ -226,11 +232,19 @@ def test_invalid_interval_identify(self):
)

def test_unsuccessful_identify(self):
# assert identify returns False when the wx_variable isn't correct
# assert identify returns False when the wx_variable
# isn't correct and a warning is logged.
self.filepath = self.filepath.replace(
'HEATX_TGL_2m', 'Not_wx_variable'
)
self.assertFalse(self.layer_handler['geps'].identify(self.filepath))
with self.assertLogs(
'geomet_data_registry.layer.geps', level='WARNING'
) as warn:
self.assertFalse(
self.layer_handler['geps'].identify(self.filepath)
)
# assert a single LOGGER.warning was called
self.assertEqual(len(warn.records), 1)


if __name__ == '__main__':
Expand Down
18 changes: 16 additions & 2 deletions tests/test_hrdpa.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ def test_super_init(self):
# assert super().__init__() was called with the correct provider def
self.mocked_base_init.assert_called_with({'name': 'hrdpa'})

def test_repr(self):
self.assertEqual(
repr(self.layer_handler['hrdpa']),
'<HrdpaLayer> hrdpa'
)


class TestIdentify(unittest.TestCase, Setup):
def setUp(self):
Expand Down Expand Up @@ -154,11 +160,19 @@ def test_items_identify(self):
self.assertListEqual(expected_items, self.layer_handler['hrdpa'].items)

def test_unsuccessful_identify(self):
# assert identify returns False when the wx_variable isn't correct
# assert identify returns False when the wx_variable
# isn't correct and a warning is logged.
self.filepath = self.filepath.replace(
'APCP-006-0100cutoff_SFC_0', 'Not_wx_variable'
)
self.assertFalse(self.layer_handler['hrdpa'].identify(self.filepath))
with self.assertLogs(
'geomet_data_registry.layer.hrdpa', level='WARNING'
) as warn:
self.assertFalse(
self.layer_handler['hrdpa'].identify(self.filepath)
)
# assert a single LOGGER.warning was called
self.assertEqual(len(warn.records), 1)


class TestAddTimeKey(unittest.TestCase, Setup):
Expand Down
20 changes: 16 additions & 4 deletions tests/test_model_gem_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ def test_super_init(self):
# assert super().__init__() was called with the correct provider def
self.mocked_base_init.assert_called_with({'name': 'model_gem_global'})

def test_repr(self):
self.assertEqual(
repr(self.layer_handler['model_gem_global']),
'<ModelGemGlobalLayer> model_gem_global'
)


class TestIdentify(unittest.TestCase, Setup):
def setUp(self):
Expand Down Expand Up @@ -253,11 +259,17 @@ def test_invalid_interval_identify(self):
)

def test_unsuccessful_identify(self):
# assert identify returns False when the wx_variable isn't correct
# assert identify returns False when the wx_variable
# isn't correct and a warning is logged.
self.filepath = self.filepath.replace('UGRD_ISBL_1015', 'Not wx_var')
self.assertFalse(
self.layer_handler['model_gem_global'].identify(self.filepath)
)
with self.assertLogs(
'geomet_data_registry.layer.model_gem_global', level='WARNING'
) as warn:
self.assertFalse(
self.layer_handler['model_gem_global'].identify(self.filepath)
)
# assert a single LOGGER.warning was called
self.assertEqual(len(warn.records), 1)


if __name__ == '__main__':
Expand Down
21 changes: 17 additions & 4 deletions tests/test_model_gem_regional.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ def test_super_init(self):
{'name': 'model_gem_regional'}
)

def test_repr(self):
self.assertEqual(
repr(self.layer_handler['model_gem_regional']),
'<ModelGemRegionalLayer> model_gem_regional'
)


class TestIdentify(unittest.TestCase, Setup):
def setUp(self):
Expand Down Expand Up @@ -253,13 +259,20 @@ def test_invalid_interval_identify(self):
)

def test_unsuccessful_identify(self):
# assert identify returns False when the wx_variable isn't correct
# assert identify returns False when the wx_variable
# isn't correct and a warning is logged.
self.filepath = self.filepath.replace(
'ABSV_ISBL_250', 'Not_wx_variable'
)
self.assertFalse(
self.layer_handler['model_gem_regional'].identify(self.filepath)
)
with self.assertLogs(
'geomet_data_registry.layer.model_gem_regional', level='WARNING'
) as warn:
self.assertFalse(
self.layer_handler['model_gem_regional']
.identify(self.filepath)
)
# assert a single LOGGER.warning was called
self.assertEqual(len(warn.records), 1)


if __name__ == '__main__':
Expand Down
Loading