Example #1
0
def test_env_var_normalization(monkeypatch):
    value = 3
    monkeypatch.setenv('ESMLAB_A_B', value)
    d = {}
    esmlab.config.refresh(config=d)
    assert get('a_b', config=d) == value
    assert get('a-b', config=d) == value
Example #2
0
def test_set_options():
    _config.set({'esmlab.cache_dir': '/tmp/collections'})
    s1 = _config.get('esmlab.cache_dir')
    assert s1 == os.path.abspath(os.path.expanduser('/tmp/collections'))

    with _config.set({'esmlab.cache_dir': '/tmp/collections'}):
        s1 = _config.get('esmlab.cache_dir')
        assert s1 == os.path.abspath(os.path.expanduser('/tmp/collections'))
Example #3
0
def test_get():
    d = {'x': 1, 'y': {'a': 2}}

    assert get('x', config=d) == 1
    assert get('y.a', config=d) == 2
    assert get('y.b', 123, config=d) == 123
    with pytest.raises(KeyError):
        get('y.b', config=d)
Example #4
0
#!/usr/bin/env python
from __future__ import absolute_import, division, print_function

import os

import xarray as xr

from esmlab import config
from esmlab.datasets import open_dataset

_default_cache_dir = config.get('esmlab.sample_data_dir')


def test_open_dataset():
    ds = open_dataset('cesm_pop_yearly')
    assert isinstance(ds, xr.Dataset)


def test_open_dataset_cache():
    ds = open_dataset('ncep_forecast_tseries', cache=False)
    assert isinstance(ds, xr.Dataset)
    filepath = _default_cache_dir + '/ncep_forecast_tseries.nc'
    assert not os.path.exists(os.path.abspath(filepath))
Example #5
0
def test_default_config():
    assert isinstance(_config.get('esmlab.sample-data-dir'), str)