<s> import sys <EOL> import unittest <EOL> import os <EOL> import tempfile <EOL> import numpy as NP <EOL> from numpy . testing import assert_almost_equal <EOL> import netCDF4 <EOL> import math <EOL> VAR_NAME = '<STR_LIT>' <EOL> VAR_TYPE = '<STR_LIT>' <EOL> VAR_VAL = math . pi <EOL> FILE_NAME = tempfile . NamedTemporaryFile ( suffix = '<STR_LIT>' , delete = False ) . name <EOL> GROUP_NAME = '<STR_LIT>' <EOL> class ScalarVariableTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . file = FILE_NAME <EOL> rootgrp = netCDF4 . Dataset ( self . file , '<STR_LIT:w>' ) <EOL> temp = rootgrp . createVariable ( VAR_NAME , VAR_TYPE ) <EOL> temp . assignValue ( VAR_VAL ) <EOL> subgroup = rootgrp . createGroup ( GROUP_NAME ) <EOL> tempg = subgroup . createVariable ( VAR_NAME , VAR_TYPE ) <EOL> tempg [ : ] = VAR_VAL <EOL> rootgrp . close ( ) <EOL> def tearDown ( self ) : <EOL> os . remove ( self . file ) <EOL> def runTest ( self ) : <EOL> """<STR_LIT>""" <EOL> f = netCDF4 . Dataset ( self . file , '<STR_LIT>' ) <EOL> v = f . variables [ VAR_NAME ] <EOL> self . assertTrue ( v . dimensions == ( ) ) <EOL> self . assertTrue ( v . shape == ( ) ) <EOL> assert_almost_equal ( v . getValue ( ) , VAR_VAL , decimal = <NUM_LIT:6> ) <EOL> assert_almost_equal ( v [ : ] , VAR_VAL , decimal = <NUM_LIT:6> ) <EOL> g = f . groups [ GROUP_NAME ] <EOL> vg = g . variables [ VAR_NAME ] <EOL> self . assertTrue ( vg . dimensions == ( ) ) <EOL> self . assertTrue ( vg . shape == ( ) ) <EOL> assert_almost_equal ( vg . getValue ( ) , VAR_VAL , decimal = <NUM_LIT:6> ) <EOL> assert_almost_equal ( vg [ : ] , VAR_VAL , decimal = <NUM_LIT:6> ) <EOL> f . close ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
