-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit testing for MpasAnalysisConfigParser
- Loading branch information
Showing
2 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
""" | ||
Unit test infrastructure for MpasAnalysisConfigParser | ||
Xylar Asay-Davis | ||
12/05/2016 | ||
""" | ||
|
||
import pytest | ||
from mpas_analysis.test import TestCase, loaddatadir | ||
from mpas_analysis.configuration.MpasAnalysisConfigParser \ | ||
import MpasAnalysisConfigParser | ||
|
||
|
||
@pytest.mark.usefixtures("loaddatadir") | ||
class TestMPASAnalysisConfigParser(TestCase): | ||
def setup_config(self): | ||
configPath = self.datadir.join('config.analysis') | ||
self.config = MpasAnalysisConfigParser() | ||
self.config.read(str(configPath)) | ||
|
||
def check_container(self, container, container_type, item_type): | ||
assert isinstance(container, container_type) | ||
for item in container: | ||
assert isinstance(item, item_type) | ||
|
||
def test_read_config(self): | ||
self.setup_config() | ||
|
||
# check config.get(...) | ||
colorMapName = self.config.get('sst_modelvsobs', 'cmapDiff') | ||
self.assertEqual(colorMapName, 'coolwarm') | ||
|
||
# check config.getint(...), config.getfloat(...), | ||
# config.getboolean(...) | ||
self.assertEqual(self.config.getint('Test', 'testInt'), 15) | ||
self.assertEqual(self.config.getfloat('Test', 'testFloat'), 18.) | ||
self.assertEqual(self.config.getboolean('Test', 'testBool'), True) | ||
|
||
# check config.getExpression(...) for various types | ||
testList = self.config.getExpression('sst_modelvsobs', | ||
'cmapIndicesModelObs') | ||
self.check_container(testList, list, int) | ||
self.assertEqual(testList, [0, 40, 80, 110, 140, 170, 200, 230, 255]) | ||
|
||
testList = self.config.getExpression('sst_modelvsobs', | ||
'comparisonTimes') | ||
self.check_container(testList, list, str) | ||
self.assertEqual(testList, ['JFM', 'JAS', 'ANN']) | ||
|
||
testList = self.config.getExpression('Test', 'testList') | ||
self.check_container(testList, list, float) | ||
self.assertEqual(testList, [0.5, 0.1, 0.5]) | ||
|
||
testTuple = self.config.getExpression('Test', 'testTuple') | ||
assert isinstance(testTuple, tuple) | ||
self.assertEqual(testTuple, (5, 0.1, 'string')) | ||
|
||
testDict = self.config.getExpression('Test', 'testDict') | ||
assert isinstance(testDict, dict) | ||
self.assertEqual(testDict, {'key1': 'string', | ||
'key2': -12, | ||
'key3': False}) | ||
|
||
|
||
# vim: foldmethod=marker ai ts=4 sts=4 et sw=4 ft=python |
34 changes: 34 additions & 0 deletions
34
mpas_analysis/test/test_mpas_config_parser/config.analysis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[sst_modelvsobs] | ||
# colormap for model/observations | ||
cmapModelObs = RdYlBu_r | ||
# colormap for differences | ||
cmapDiff = coolwarm | ||
|
||
# indices into cmapModelObs for contour color | ||
cmapIndicesModelObs = [0, 40, 80, 110, 140, 170, 200, 230, 255] | ||
# indices into cmapModelObs for contour color | ||
cmapIndicesDiff = [0, 40, 80, 120, 140, 170, 210, 255] | ||
|
||
# colormap levels/values for contour boundaries | ||
clevsModelObs = [-2, 0, 2, 6, 10, 16, 22, 26, 28, 32] | ||
clevsDiff = [-5, -3, -2, -1, 0, 1, 2, 3, 5] | ||
|
||
# Times for comparison times (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec, JFM, AMJ, JAS, OND, ANN) | ||
comparisonTimes = ['JFM', 'JAS', 'ANN'] | ||
|
||
[Test] | ||
|
||
testInt = 15 | ||
|
||
testFloat = 18.0 | ||
|
||
testBool = True | ||
|
||
testList = [0.5, 0.1, 0.5] | ||
|
||
testTuple = (5, 0.1, 'string') | ||
|
||
testDict = {'key1': 'string', | ||
'key2': -12, | ||
'key3': False} | ||
|