def test__basic(self): test_str = """ line1; //no more line2 ; group { //this var = expr(7 ** 5 /2) attributes: :z = 3 ; :a = 6 ; :q = 4 ; } end""" expected_str = '\n'.join([ "line1;", "line2 ;", "group {", "var = expr(7 ** 5 /2)", "attributes:", ":z = 3 ;", ":a = 6 ;", ":q = 4 ;", "}", "end"]) result_str = comparable_cdl(test_str) self.assertEqual(result_str, expected_str)
def check_file_cdl(file_path): # Load from the given file with netCDF4.Dataset(file_path) as ds: g = ncds.read(ds) # Re-save to a temporary file, to get an ncdump output in known order. ncds.write('temp.nc', g) # Rename so name matches temporary file name as seen by ncdump. g.rename('temp') # Generate cdl. g_cdl = cdl(g) try: # Run ncdump on the test file f_cdl = subprocess.check_output('ncdump -h temp.nc', shell=True) finally: os.remove('temp.nc') # Check that the two CDL strings are "essentially" the same. g_cdl_std = ncdl.comparable_cdl(g_cdl) f_cdl_std = ncdl.comparable_cdl(f_cdl) if g_cdl_std == f_cdl_std: print 'OK (ncdump and ncobj output EQUAL)' else: print 'FAIL: ncdump and ncobj output differ..' print