<s> import sys <EOL> import unittest <EOL> import os <EOL> import tempfile <EOL> from netCDF4 import Dataset , CompoundType , chartostring , stringtoarr , default_encoding <EOL> import numpy as np <EOL> from numpy . testing import assert_array_equal , assert_array_almost_equal <EOL> FILE_NAME = tempfile . NamedTemporaryFile ( suffix = '<STR_LIT>' , delete = False ) . name <EOL> DIM_NAME = '<STR_LIT:time>' <EOL> VAR_NAME = '<STR_LIT>' <EOL> VAR_NAME2 = '<STR_LIT>' <EOL> GROUP_NAME = '<STR_LIT>' <EOL> dtype = np . dtype ( [ ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) ] ) <EOL> TYPE_NAME = '<STR_LIT>' <EOL> TYPE_NAMEC = '<STR_LIT>' <EOL> dtypec = np . dtype ( [ ( '<STR_LIT>' , '<STR_LIT:c>' , ( <NUM_LIT:8> , ) ) , ( '<STR_LIT>' , '<STR_LIT:c>' , ( <NUM_LIT:8> , ) ) ] ) <EOL> missvals = np . empty ( <NUM_LIT:1> , dtype ) <EOL> missvals [ '<STR_LIT>' ] = <NUM_LIT> <EOL> missvals [ '<STR_LIT>' ] = - <NUM_LIT> <EOL> windunits = np . zeros ( <NUM_LIT:1> , dtypec ) <EOL> windunits [ '<STR_LIT>' ] = stringtoarr ( '<STR_LIT>' , dtypec . fields [ '<STR_LIT>' ] [ <NUM_LIT:0> ] . itemsize ) <EOL> windunits [ '<STR_LIT>' ] = stringtoarr ( '<STR_LIT>' , dtypec . fields [ '<STR_LIT>' ] [ <NUM_LIT:0> ] . itemsize ) <EOL> class VariablesTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . file = FILE_NAME <EOL> f = Dataset ( self . file , '<STR_LIT:w>' ) <EOL> d = f . createDimension ( DIM_NAME , None ) <EOL> g = f . createGroup ( GROUP_NAME ) <EOL> wind_vector_type = f . createCompoundType ( dtype , TYPE_NAME ) <EOL> wind_vectorunits_type = f . createCompoundType ( dtypec , TYPE_NAMEC ) <EOL> v = f . createVariable ( VAR_NAME , wind_vector_type , DIM_NAME ) <EOL> vv = g . createVariable ( VAR_NAME2 , wind_vector_type , DIM_NAME ) <EOL> v . missing_values = missvals <EOL> v . units = windunits <EOL> vv . missing_values = missvals <EOL> vv . units = windunits <EOL> f . close ( ) <EOL> def tearDown ( self ) : <EOL> os . remove ( self . file ) <EOL> def runTest ( self ) : <EOL> """<STR_LIT>""" <EOL> f = Dataset ( self . file , '<STR_LIT:r>' ) <EOL> v = f . variables [ VAR_NAME ] <EOL> g = f . groups [ GROUP_NAME ] <EOL> vv = g . variables [ VAR_NAME2 ] <EOL> assert_array_almost_equal ( v . missing_values [ '<STR_LIT>' ] , missvals [ '<STR_LIT>' ] ) <EOL> assert_array_almost_equal ( v . missing_values [ '<STR_LIT>' ] , missvals [ '<STR_LIT>' ] ) <EOL> assert_array_almost_equal ( vv . missing_values [ '<STR_LIT>' ] , missvals [ '<STR_LIT>' ] ) <EOL> assert_array_almost_equal ( vv . missing_values [ '<STR_LIT>' ] , missvals [ '<STR_LIT>' ] ) <EOL> assert_array_equal ( v . units [ '<STR_LIT>' ] , windunits [ '<STR_LIT>' ] . squeeze ( ) ) <EOL> assert_array_equal ( v . units [ '<STR_LIT>' ] , windunits [ '<STR_LIT>' ] . squeeze ( ) ) <EOL> assert_array_equal ( vv . units [ '<STR_LIT>' ] , windunits [ '<STR_LIT>' ] . squeeze ( ) ) <EOL> assert_array_equal ( vv . units [ '<STR_LIT>' ] , windunits [ '<STR_LIT>' ] . squeeze ( ) ) <EOL> assert ( chartostring ( v . units [ '<STR_LIT>' ] ) . item ( ) . rstrip ( ) . decode ( default_encoding ) == '<STR_LIT>' ) <EOL> assert ( chartostring ( v . units [ '<STR_LIT>' ] ) . item ( ) . rstrip ( ) . decode ( default_encoding ) == '<STR_LIT>' ) <EOL> assert ( chartostring ( vv . units [ '<STR_LIT>' ] ) . item ( ) . rstrip ( ) . decode ( default_encoding ) == '<STR_LIT>' ) <EOL> assert ( chartostring ( vv . units [ '<STR_LIT>' ] ) . item ( ) . rstrip ( ) . decode ( default_encoding ) == '<STR_LIT>' ) <EOL> f . close ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
