test_model.py 888 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import unittest

import pandas as pd
import numpy as np
import xarray as xr
from o3skim import source


model = xr.Dataset(
    data_vars=dict(
        tco3_zm=(["lon", "lat", "time"], np.random.rand(3, 3, 25)),
        vmro3_zm=(["lon", "lat", "plev", "time"], np.random.rand(3, 3, 4, 25))
    ),
    coords=dict(
        lon=[-180, 0, 180],
        lat=[-90, 0, 90],
        plev=[1, 10, 100, 1000],
        time=pd.date_range("2000-01-01", periods=25, freq='A')
    ),
    attrs=dict(description="Test dataset")
)


class TestsModel(unittest.TestCase):

    def assertHasAttr(self, obj, intendedAttr):
        testBool = hasattr(obj, intendedAttr)
        msg = 'obj lacking an attribute. obj: %s, intendedAttr: %s' % (
            obj, intendedAttr)
        self.assertTrue(testBool, msg=msg)

    def test_dataset_has_model_accessor(self):
        self.assertHasAttr(model, 'model')