Commit f5ca425f authored by Javier Vegas-Regidor's avatar Javier Vegas-Regidor
Browse files

Reorganized tests and added some more

parent 7c4ad073
......@@ -44,13 +44,13 @@ class Attribute(Diagnostic):
self.attributte_value = attributte_value
def __str__(self):
return 'Write attributte output Startdate: {0} Member: {1} Chunk: {2} ' \
'Variable: {3}:{4} Attributte:{5}:{6}'.format(self.startdate, self.member, self.chunk, self.domain,
self.variable, self.attributte_name, self.attributte_value)
return 'Write attributte output Startdate: {0.startdate} Member: {0.member} Chunk: {0.chunk} ' \
'Variable: {0.domain}:{0.variable} Attributte: {0.attributte_name}:{0.attributte_value} ' \
'Grid: {0.grid}'.format(self)
def __eq__(self, other):
return self.startdate == other.startdate and self.member == other.member and self.chunk == other.chunk and \
self.domain == other.domain and self.variable == other.variable and \
self.domain == other.domain and self.variable == other.variable and self.grid == other.grid and \
self.attributte_name == other.attributte_name and self.attributte_value == other.attributte_value
@classmethod
......
......@@ -2,29 +2,25 @@
"""
Script to run the tests for EarthDiagnostics and generate the code coverage report
"""
import coverage
import unittest
import os
cov = coverage.Coverage()
work_path = os.path.abspath('.')
source_path = os.path.join(work_path, '..', 'earthdiagnostics', '*')
print(source_path)
cov = coverage.Coverage(include=source_path)
cov.set_option("run:branch", True)
cov.start()
cov.set_option("html:title", 'Coverage report for ESMValTool')
# noinspection PyPep8
import test.unit
suite = unittest.TestLoader().loadTestsFromModule(test.unit)
cov.start()
suite = unittest.TestLoader().discover('.')
unittest.TextTestRunner(verbosity=2).run(suite)
cov.stop()
cov.save()
source_files = list()
for path, dirs, files in os.walk('earthdiagnostics'):
for filename in files:
if filename.endswith('.py'):
source_files.append(os.path.join(path, filename))
cov.report(source_files)
cov.html_report(source_files)
cov.save()
cov.report()
cov.html_report()
# coding=utf-8
from test_data_manager import TestConversion
# from test.unit.test_variable import TestVariable
from test_constants import TestBasin
from test_box import TestBox
from test_diagnostic import *
from test_cdftools import TestCDFTools
from test_utils import TestTempFile, TestUtils
from test_psi import TestPsi
from test_areamoc import TestAreaMoc
# from test_averagesection import TestAverageSection
from test_cutsection import TestCutSection
from test_convectionsites import TestConvectionSites
from test_frequency import TestFrequency
from test_gyres import TestGyres
# from test_heatcontent import TestHeatContent
from test_heatcontentlayer import TestHeatContentLayer
# from test_interpolate import TestInterpolate
from test_maxmoc import TestMaxMoc
from test_mixedlayerheatcontent import TestMixedLayerHeatContent
from test_mixedlayersaltcontent import TestMixedLayerSaltContent
from test_moc import TestMoc
from test_modelling_realm import TestModellingRealms, TestModellingRealm
from test_siasiesiv import TestSiasiesiv
from test_verticalmean import TestVerticalMean
from test_verticalmeanmeters import TestVerticalMeanMeters
from test_monthlymean import TestMonthlyMean
from test_rewrite import TestRewrite
from test_variable_type import TestVariableType
from test_monthlypercentile import TestMonthlyPercentile
from test_climatologicalpercentile import TestClimatologicalPercentile
from test_variable import TestCMORTable, TestVariableAlias
# coding=utf-8
from unittest import TestCase
from earthdiagnostics.diagnostic import DiagnosticVariableOption
from earthdiagnostics.box import Box
from earthdiagnostics.frequency import Frequencies
from earthdiagnostics.general.attribute import Attribute
from mock import Mock, patch
from earthdiagnostics.modelingrealm import ModelingRealms
class TestAttribute(TestCase):
def setUp(self):
self.data_manager = Mock()
self.diags = Mock()
self.diags.model_version = 'model_version'
self.diags.config.experiment.get_chunk_list.return_value = (('20010101', 0, 0), ('20010101', 0, 1))
self.box = Box()
self.box.min_depth = 0
self.box.max_depth = 100
def fake_parse(self, value):
return value
@patch.object(DiagnosticVariableOption, 'parse', fake_parse)
def test_generate_jobs(self):
jobs = Attribute.generate_jobs(self.diags, ['diagnostic', 'atmos', 'var', 'att', 'value'])
self.assertEqual(len(jobs), 2)
self.assertEqual(jobs[0], Attribute(self.data_manager, '20010101', 0, 0, ModelingRealms.atmos, 'var', '',
'att', 'value'))
self.assertEqual(jobs[1], Attribute(self.data_manager, '20010101', 0, 1, ModelingRealms.atmos, 'var', '',
'att', 'value'))
jobs = Attribute.generate_jobs(self.diags, ['diagnostic', 'seaice', 'var', 'att', 'value', 'grid'])
self.assertEqual(len(jobs), 2)
self.assertEqual(jobs[0], Attribute(self.data_manager, '20010101', 0, 0, ModelingRealms.seaIce, 'var', 'grid',
'att', 'value'))
self.assertEqual(jobs[1], Attribute(self.data_manager, '20010101', 0, 1, ModelingRealms.seaIce, 'var', 'grid',
'att', 'value'))
with self.assertRaises(Exception):
Attribute.generate_jobs(self.diags, ['diagnostic'])
with self.assertRaises(Exception):
Attribute.generate_jobs(self.diags, ['diagnostic', '0', '0', '0', '0', '0', '0', '0'])
def test_str(self):
mixed = Attribute(self.data_manager, '20010101', 0, 0, ModelingRealms.atmos, 'var', 'grid', 'att', 'value')
self.assertEquals(str(mixed), 'Write attributte output Startdate: 20010101 Member: 0 Chunk: 0 Variable: atmos:var '
'Attributte: att:value Grid: grid')
# coding=utf-8
from unittest import TestCase
from earthdiagnostics.diagnostic import DiagnosticVariableOption
from earthdiagnostics.box import Box
from earthdiagnostics.frequency import Frequencies
from earthdiagnostics.general.dailymean import DailyMean
from mock import Mock, patch
from earthdiagnostics.modelingrealm import ModelingRealms
class TestDailyMean(TestCase):
def setUp(self):
self.data_manager = Mock()
self.diags = Mock()
self.diags.model_version = 'model_version'
self.diags.config.experiment.get_chunk_list.return_value = (('20010101', 0, 0), ('20010101', 0, 1))
self.box = Box()
self.box.min_depth = 0
self.box.max_depth = 100
def fake_parse(self, value):
return value
@patch.object(DiagnosticVariableOption, 'parse', fake_parse)
def test_generate_jobs(self):
jobs = DailyMean.generate_jobs(self.diags, ['diagnostic', 'atmos', 'var', '6hr'])
self.assertEqual(len(jobs), 2)
self.assertEqual(jobs[0], DailyMean(self.data_manager, '20010101', 0, 0, ModelingRealms.atmos, 'var',
Frequencies.six_hourly, ''))
self.assertEqual(jobs[1], DailyMean(self.data_manager, '20010101', 0, 1, ModelingRealms.atmos, 'var',
Frequencies.six_hourly, ''))
jobs = DailyMean.generate_jobs(self.diags, ['diagnostic', 'seaice', 'var', '3h', 'grid'])
self.assertEqual(len(jobs), 2)
self.assertEqual(jobs[0], DailyMean(self.data_manager, '20010101', 0, 0, ModelingRealms.seaIce, 'var',
Frequencies.three_hourly, 'grid'))
self.assertEqual(jobs[1], DailyMean(self.data_manager, '20010101', 0, 1, ModelingRealms.seaIce, 'var',
Frequencies.three_hourly, 'grid'))
with self.assertRaises(Exception):
DailyMean.generate_jobs(self.diags, ['diagnostic'])
with self.assertRaises(Exception):
DailyMean.generate_jobs(self.diags, ['diagnostic', '0', '0', '0', '0', '0', '0', '0'])
def test_str(self):
mixed = DailyMean(self.data_manager, '20000101', 1, 1, ModelingRealms.ocean, 'var', 'freq', '')
self.assertEquals(str(mixed), 'Calculate daily mean Startdate: 20000101 Member: 1 Chunk: 1 '
'Variable: ocean:var Original frequency: freq Grid: ')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment