<commit_before>import nose.tools
from unittest import TestCase
from nose import SkipTest
from nose.plugins.attrib import attr

from __init__ import TESTDATA, SERVICE

class OCGISTestCase(TestCase):

    @classmethod
    def setUpClass(cls):
        import os
        from os.path import join
        # TODO: set GDAL_DATA in a save way
        os.environ['GDAL_DATA'] = join(os.environ['HOME'], 'anaconda', 'share/gdal')
        from urllib2 import urlparse
        url_parts = urlparse.urlparse(
            TESTDATA['tas_EUR-11_ICHEC-EC-EARTH_rcp45_r1i1p1_KNMI-RACMO22E_v1_mon_200601-201012.nc'])
        cls.tas_nc = url_parts.path

    @attr('testdata')
    def test_ocgis_inspect(self):
        import ocgis
        rd = ocgis.RequestDataset(self.tas_nc, 'tas')
        rd.inspect()
        

    
<commit_msg>ocgis test for su added<commit_after>import nose.tools
from unittest import TestCase
from nose import SkipTest
from nose.plugins.attrib import attr

from __init__ import TESTDATA, SERVICE

import tempfile
from netCDF4 import Dataset

# ocgis needs GDAL_DATA on import
import os
from os.path import join
# TODO: set GDAL_DATA in a save way
os.environ['GDAL_DATA'] = join(os.environ['HOME'], 'anaconda', 'share', 'gdal')
import ocgis

class OCGISTestCase(TestCase):

    @classmethod
    def setUpClass(cls):
        cls.output_format = 'nc'

        # TODO: ocgis does not like file:// urls
        from urllib2 import urlparse
        # tas
        url_parts = urlparse.urlparse(
            TESTDATA['tas_EUR-11_ICHEC-EC-EARTH_rcp45_r1i1p1_KNMI-RACMO22E_v1_mon_200601-201012.nc'])
        cls.tas_nc = url_parts.path
        # tasmax
        url_parts = urlparse.urlparse(
            TESTDATA['tasmax_WAS-44_MPI-M-MPI-ESM-LR_historical_r1i1p1_MPI-CSC-REMO2009_v1_day_20010101-20051231.nc'])
        cls.tasmax_nc = url_parts.path

    @attr('testdata')
    def test_ocgis_inspect(self):
        rd = ocgis.RequestDataset(self.tas_nc, 'tas')
        rd.inspect()

    @attr('testdata')
    def test_ocgis_su_tasmax(self):
        out_dir = tempfile.mkdtemp()
        prefix = 'tasmax_su'
        
        calc_icclim = [{'func':'icclim_SU','name':'SU'}]
        rd = ocgis.RequestDataset(self.tasmax_nc, "tasmax") # TODO: time_range=[dt1, dt2]
        SU_file = ocgis.OcgOperations(
            dataset=rd,
            calc=calc_icclim,
            calc_grouping=['year'],
            prefix=prefix,
            output_format=self.output_format,
            dir_output=out_dir,
            add_auxiliary_files=False).execute()

        result = Dataset(join(out_dir, prefix + '.' + self.output_format))
        # SU variable must be in result
        nose.tools.ok_('SU' in result.variables, result.variables.keys())
        # 5 years
        nose.tools.ok_(len(result.variables['time']) == 5, len(result.variables['time']))
        
        
    

{'fraction_non_alphanumeric': 0.10370111731843576, 'fraction_numerical': 0.026885474860335195, 'mean_word_length': 2.7647831800262814, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3186881', 'n_tokens_mistral': 1058, 'n_tokens_neox': 1009, 'n_words': 193}