diff --git a/opppy/dump_utils.py b/opppy/dump_utils.py index 67747b2..b79ef84 100644 --- a/opppy/dump_utils.py +++ b/opppy/dump_utils.py @@ -34,8 +34,7 @@ from opppy.progress import progress -USE_THREADS = not os.getenv("OPPPY_USE_THREADS", 'True').lower() in ('false', '0', 'f') - +USE_THREADS = os.getenv("OPPPY_USE_THREADS", 'True').lower() in ('true', '1', 't') def point_value_1d(data, x_key, value_key, x_value, method='nearest'): ''' @@ -489,7 +488,10 @@ def extract_series_2d_slice(data_list,series_key,value_key,dim_keys, slice_value def append_dumps(data, dump_files, opppy_parser, key_words=None): ''' - Append output data from a list of output_files to a user provided dictionary using a user proved opppy_parser + Append output data from a list of output_files to a user provided dictionary using a user proved + opppy_parser. By default this function will use the multiprocessing option to parallelize the + parsing of multiple dumps. The parallel parsing can be disabled by setting + the environment variable 'OPPPY_USE_THREADS=False' Input options: data opppy input dictionary to be append to (must have a 'verion' opppy key) diff --git a/opppy/output.py b/opppy/output.py index 68d9664..cd9f871 100644 --- a/opppy/output.py +++ b/opppy/output.py @@ -33,9 +33,7 @@ from opppy.version import __version__ from opppy.progress import * -USE_THREADS = not os.getenv("OPPPY_USE_THREADS", 'True').lower() in ('false', '0', 'f') - - +USE_THREADS = os.getenv("OPPPY_USE_THREADS", 'True').lower() in ('true', '1', 't') def append_cycle_data(cycle_data, data, sort_key_string): ''' @@ -317,7 +315,11 @@ def extract_cycle_data(cycle_string, my_opppy_parser): def append_output_dictionary(data, output_files, opppy_parser, append_date=False): ''' - Append output data from a list of output_files to a user provided dictionary using a user proved opppy_parser + Append output data from a list of output_files to a user provided dictionary using a user proved + opppy_parser. By default this function will use the multiprocessing option to parallelize the + parsing of multiple dumps. The parallel parsing can be disabled by setting + the environment variable 'OPPPY_USE_THREADS=False' + arguments: data opppy input dictionary to be append to (must have a 'verion' opppy key) diff --git a/opppy/tally.py b/opppy/tally.py index 628e262..bc55c28 100644 --- a/opppy/tally.py +++ b/opppy/tally.py @@ -33,7 +33,7 @@ from opppy.progress import * from opppy.output import * -USE_THREADS = not os.getenv("OPPPY_USE_THREADS", 'True').lower() in ('false', '0', 'f') +USE_THREADS = os.getenv("OPPPY_USE_THREADS", 'True').lower() in ('true', '1', 't') def append_tally_data(cycle_data, data, sort_key_string): ''' @@ -216,7 +216,11 @@ def print_tally_data(data): def append_tally_dictionary(data, output_files, opppy_parser, append_date=False): ''' - Append tally data from a list of output_files to a user provided dictionary using a user proved opppy_parser + Append tally data from a list of output_files to a user provided dictionary using a user proved + opppy_parser. By default this function will use the multiprocessing option to parallelize the + parsing of multiple dumps. The parallel parsing can be disabled by setting the environment + variable 'OPPPY_USE_THREADS=False' + arguments: data opppy input dictionary to be append to (must have a 'verion' opppy key) diff --git a/tests/gold_2d_line_data.p b/tests/gold_2d_line_data.p new file mode 100644 index 0000000..2fca3cf Binary files /dev/null and b/tests/gold_2d_line_data.p differ diff --git a/tests/gold_2d_slice_tracer_data.p b/tests/gold_2d_slice_tracer_data.p new file mode 100644 index 0000000..0521c5c Binary files /dev/null and b/tests/gold_2d_slice_tracer_data.p differ diff --git a/tests/gold_2d_tracer_data.p b/tests/gold_2d_tracer_data.p new file mode 100644 index 0000000..3dc1bba Binary files /dev/null and b/tests/gold_2d_tracer_data.p differ diff --git a/tests/gold_dump0.p b/tests/gold_dump0.p new file mode 100644 index 0000000..490e9aa Binary files /dev/null and b/tests/gold_dump0.p differ diff --git a/tests/gold_dumps.p b/tests/gold_dumps.p new file mode 100644 index 0000000..b55e858 Binary files /dev/null and b/tests/gold_dumps.p differ diff --git a/tests/gold_extract_cycle.p b/tests/gold_extract_cycle.p new file mode 100644 index 0000000..002b7cf Binary files /dev/null and b/tests/gold_extract_cycle.p differ diff --git a/tests/gold_grid_data.p b/tests/gold_grid_data.p new file mode 100644 index 0000000..9eb65e7 Binary files /dev/null and b/tests/gold_grid_data.p differ diff --git a/tests/gold_line_data.p b/tests/gold_line_data.p new file mode 100644 index 0000000..1404ef9 Binary files /dev/null and b/tests/gold_line_data.p differ diff --git a/tests/gold_output.p b/tests/gold_output.p new file mode 100644 index 0000000..ae6dd50 Binary files /dev/null and b/tests/gold_output.p differ diff --git a/tests/gold_point_data.p b/tests/gold_point_data.p new file mode 100644 index 0000000..7a4bf2d Binary files /dev/null and b/tests/gold_point_data.p differ diff --git a/tests/gold_sub_dump0.p b/tests/gold_sub_dump0.p new file mode 100644 index 0000000..6c537f1 Binary files /dev/null and b/tests/gold_sub_dump0.p differ diff --git a/tests/gold_sub_dumps.p b/tests/gold_sub_dumps.p new file mode 100644 index 0000000..d380d46 Binary files /dev/null and b/tests/gold_sub_dumps.p differ diff --git a/tests/gold_tally.p b/tests/gold_tally.p new file mode 100644 index 0000000..135570a Binary files /dev/null and b/tests/gold_tally.p differ diff --git a/tests/gold_tally_extract_cycle.p b/tests/gold_tally_extract_cycle.p new file mode 100644 index 0000000..dace3df Binary files /dev/null and b/tests/gold_tally_extract_cycle.p differ diff --git a/tests/gold_tracer_data.p b/tests/gold_tracer_data.p new file mode 100644 index 0000000..cf4107e Binary files /dev/null and b/tests/gold_tracer_data.p differ diff --git a/tests/my_test_opppy_dump_parser.py b/tests/my_test_opppy_dump_parser.py index 6de2207..50b3dbb 100644 --- a/tests/my_test_opppy_dump_parser.py +++ b/tests/my_test_opppy_dump_parser.py @@ -34,6 +34,7 @@ def build_data_dictionary(self, filename, dump_keys=None): if key in line and len(key) is len(line.split(':')[0]): data[key] = array(str_vector_to_float_vector(line.strip('\n').split(' ')[1:])) + # build xy_verts for 2d mesh plotting example if 'x' in data and 'y' in data: xy_verts = [] diff --git a/tests/test_dump_utils.py b/tests/test_dump_utils.py index 3fd0c1e..aace7f7 100644 --- a/tests/test_dump_utils.py +++ b/tests/test_dump_utils.py @@ -7,15 +7,25 @@ # All rights reserved. # -----------------------------------------------------------------------------# import sys -import matplotlib.pyplot as PyPlot +import numpy as np sys.path.append('..') import os dir_path = os.path.dirname(os.path.realpath(__file__))+"/" +OPPPY_UPGOLDS = os.getenv("OPPPY_UPGOLDS", 'False').lower() in ('true', '1', 't') + +# suppress plotting for pytest +SHOW_PLOTS = os.getenv("SHOW_PLOTS", 'False').lower() in ('true', '1', 't') +import matplotlib +if(not SHOW_PLOTS): + matplotlib.use('Agg') +import matplotlib.pyplot as PyPlot + from opppy.dump_utils import * import unittest +import collections.abc class test_opppy_dump_utils(unittest.TestCase): def test_dump_parser(self): @@ -32,11 +42,146 @@ def test_dump_parser(self): data = dump_parser.build_data_dictionary(filename) print(data) + if(OPPPY_UPGOLDS): + goldfile = open(dir_path+'gold_dump0.p', 'wb') + pickle.dump(data,goldfile) + goldfile.close() + + goldfile = open(dir_path+'gold_dump0.p', 'rb') + gold_data = pickle.load(goldfile) + goldfile.close() + print(data) + print(gold_data) + assert(data.keys()==gold_data.keys()) + for k, v in gold_data.items(): + try: + assert((data[k]==v).all()) + except: + assert(data[k]==v) + # extract a subset of data from the example dump file sub_data = dump_parser.build_data_dictionary(filename, ['time','density']) print(sub_data) + assert(data!=sub_data) + if(OPPPY_UPGOLDS): + goldfile = open(dir_path+'gold_sub_dump0.p', 'wb') + pickle.dump(sub_data,goldfile) + goldfile.close() + + goldfile = open(dir_path+'gold_sub_dump0.p', 'rb') + gold_data = pickle.load(goldfile) + goldfile.close() + assert(sub_data.keys()==gold_data.keys()) + for k, v in gold_data.items(): + try: + assert((sub_data[k]==v).all()) + except: + assert(sub_data[k]==v) + + def test_append_dump_dictionary(self): + ''' + This test the append_pickle function + ''' + from my_test_opppy_dump_parser import my_test_opppy_dump_parser + from opppy.version import __version__ + + # initialize my test dump parser + dump_parser = my_test_opppy_dump_parser() + + # initialize the data dictionary + data = {} + data['version'] = __version__ + + # Append the first output file + filenames = [dir_path + "example_dump.txt"] + # Build initial pickle + append_dumps(data, filenames, dump_parser) + + print(data) + + # Append the second output file + filenames = [dir_path + "example_dump2.txt"] + # Build initial pickle + append_dumps(data, filenames, dump_parser) + + print(data) + + # Append the thrid output file + filenames = [dir_path + "example_dump3.txt"] + # Build initial pickle + append_dumps(data, filenames, dump_parser) + + if(OPPPY_UPGOLDS): + goldfile = open(dir_path+'gold_dumps.p', 'wb') + pickle.dump(data,goldfile) + goldfile.close() + + goldfile = open(dir_path+'gold_dumps.p', 'rb') + gold_data = pickle.load(goldfile) + goldfile.close() + print(data) + data.pop('version') + gold_data.pop('version') + assert(data.keys()==gold_data.keys()) + for dump_name, dump_dic in gold_data.items(): + assert(data[dump_name].keys()==dump_dic.keys()) + for k, v in dump_dic.items(): + try: + assert((data[dump_name][k]==v).all()) + except: + assert(data[dump_name][k]==v) + + # initialize a new data dictionary + data2 = {} + data2['version'] = __version__ + + + # Append the thrid output file + filenames = [dir_path+"example_dump.txt",dir_path+"example_dump2.txt",dir_path+"example_dump3.txt"] + # Build initial pickle + append_dumps(data2, filenames, dump_parser) + + print(data2) + # Don't check the version for a match + data2.pop('version') + assert(data2.keys()==gold_data.keys()) + for dump_name, dump_dic in gold_data.items(): + assert(data2[dump_name].keys()==dump_dic.keys()) + for k, v in dump_dic.items(): + try: + assert((data2[dump_name][k]==v).all()) + except: + assert(data2[dump_name][k]==v) + + # extract subset of dump data + sub_data = {} + sub_data['version'] = __version__ + filenames = [dir_path+"example_dump.txt",dir_path+"example_dump2.txt",dir_path+"example_dump3.txt"] + # Build initial pickle + append_dumps(sub_data, filenames, dump_parser, ['time','density']) + + print(sub_data) + if(OPPPY_UPGOLDS): + goldfile = open(dir_path+'gold_sub_dumps.p', 'wb') + pickle.dump(sub_data,goldfile) + goldfile.close() + + goldfile = open(dir_path+'gold_sub_dumps.p', 'rb') + gold_data = pickle.load(goldfile) + goldfile.close() + sub_data.pop('version') + gold_data.pop('version') + assert(sub_data.keys()==gold_data.keys()) + for dump_name, dump_dic in gold_data.items(): + assert(sub_data[dump_name].keys()==dump_dic.keys()) + for k, v in dump_dic.items(): + try: + assert((sub_data[dump_name][k]==v).all()) + except: + assert(sub_data[dump_name][k]==v) + def test_point_value(self): ''' @@ -50,20 +195,32 @@ def test_point_value(self): filename = dir_path + "example_dump.txt" # extract all data from the example dump file data = dump_parser.build_data_dictionary(filename) - + point_data = {} # extract a 1D data value point1d = point_value_1d(data, 'cell_id', 'pressure', 6.0); - + point_data['poin1d'] = point1d print(point1d) point2d = point_value_2d(data, 'x','y', 'temperature', 1.0, 2.0); + point_data['poin2d'] = point2d print(point2d) print(data.keys()) point3d = point_value_3d(data, 'x','y', 'z', 'density', 1.0, 2.0, 0.5); + point_data['poin3d'] = point3d print(point3d) + if(OPPPY_UPGOLDS): + goldfile = open(dir_path+'gold_point_data.p', 'wb') + pickle.dump(point_data,goldfile) + goldfile.close() + + goldfile = open(dir_path+'gold_point_data.p', 'rb') + gold_data = pickle.load(goldfile) + goldfile.close() + assert(point_data == gold_data) + def test_point_series(self): ''' @@ -82,14 +239,32 @@ def test_point_series(self): data.append(dump_parser.build_data_dictionary(filename)) filename = dir_path + "example_dump3.txt" data.append(dump_parser.build_data_dictionary(filename)) - + tracer_data = {} # extract a 1D data value tracer_x, tracer_y = extract_series_point(data,'time',"density",['x'], [1.0]) + tracer_data["tracerx1"] = np.array([ x[0] for x in tracer_x['time']]) + tracer_data["tracery1"] = tracer_y['density'] print(tracer_x, tracer_y) tracer_x, tracer_y = extract_series_point(data,'time',"density",['x','y'], [1.0,2.0]) + tracer_data["tracerx2"] = np.array([ x[0] for x in tracer_x['time']]) + + tracer_data["tracery2"] = tracer_y['density'] print(tracer_x, tracer_y) tracer_x, tracer_y = extract_series_point(data,'time',"density",['x','y','z'], [1.0,2.0,5.0]) + tracer_data["tracerx3"] = np.array([ x[0] for x in tracer_x['time']]) + tracer_data["tracery3"] = tracer_y['density'] print(tracer_x, tracer_y) + if(OPPPY_UPGOLDS): + goldfile = open(dir_path+'gold_tracer_data.p', 'wb') + pickle.dump(tracer_data,goldfile) + goldfile.close() + + goldfile = open(dir_path+'gold_tracer_data.p', 'rb') + gold_data = pickle.load(goldfile) + goldfile.close() + for k, v in gold_data.items(): + assert((tracer_data[k]==v).all()) + @@ -107,9 +282,10 @@ def test_grid_data(self): filename = dir_path + "example_dump.txt" # extract all data from the example dump file data = dump_parser.build_data_dictionary(filename) - + check_data = {} # extract data to a grid grid = data2grid(data, 'x', 'y', 'density') + check_data['grid'] = grid # plot the data as a check PyPlot.imshow(grid['density'] , extent=(grid['x'].min(),grid['x'].max(),grid['y'].min(),grid['y'].max()), origin='lower') @@ -117,16 +293,31 @@ def test_grid_data(self): # plot the data in a bounding box gridbox = data2gridbox(data, 'x', 'y', 'density', 2.5, 1.0, 3.5, 1.8, method="linear") + check_data['gridbox'] = gridbox PyPlot.imshow(gridbox['density'] , extent=(gridbox['x'].min(),gridbox['x'].max(),gridbox['y'].min(),gridbox['y'].max()), origin='lower') PyPlot.show() # extract an x slice of data gridxslice = data2grid3Dslice(data, 'z', 'y', 'x', 'temperature', 5.0, npts=10,method='nearest') + check_data['gridxslice'] = gridxslice PyPlot.imshow(gridxslice['temperature'] , extent=(gridxslice['z'].min(),gridxslice['z'].max(),gridxslice['y'].min(),gridxslice['y'].max()), origin='lower') PyPlot.show() print(gridxslice['temperature'].T) + if(OPPPY_UPGOLDS): + goldfile = open(dir_path+'gold_grid_data.p', 'wb') + pickle.dump(check_data,goldfile) + goldfile.close() + + goldfile = open(dir_path+'gold_grid_data.p', 'rb') + gold_data = pickle.load(goldfile) + goldfile.close() + for key, gold_dic in gold_data.items(): + for k, v in gold_dic.items(): + assert((check_data[key][k]==v).all()) + + def test_2D_series(self): ''' @@ -145,12 +336,36 @@ def test_2D_series(self): data.append(dump_parser.build_data_dictionary(filename)) filename = dir_path + "example_dump3.txt" data.append(dump_parser.build_data_dictionary(filename)) - + check_data = {} # extract a 1D data value tracer_t, tracer_grid = extract_series_2d(data,'time',"temperature",['x','y'], npts=5 ) + check_data['time1'] = np.array([t[0] for t in tracer_t['time']]) + for i in range(len(check_data['time1'])): + check_data['temperature1'+str(i)] = tracer_grid[i]['temperature'] + check_data['x1'+str(i)] = tracer_grid[i]['x'] + check_data['y1'+str(i)] = tracer_grid[i]['y'] + print(tracer_t, tracer_grid) tracer_t, tracer_grid = extract_series_2d(data,'time',"temperature",['x','y'], npts=5, box=[2.5, 1.0, 3.5, 1.8] ) + check_data['time2'] = np.array([t[0] for t in tracer_t['time']]) + for i in range(len(check_data['time2'])): + check_data['temperature2'+str(i)] = tracer_grid[i]['temperature'] + check_data['x2'+str(i)] = tracer_grid[i]['x'] + check_data['y2'+str(i)] = tracer_grid[i]['y'] + print(tracer_t, tracer_grid) + print(check_data) + if(OPPPY_UPGOLDS): + goldfile = open(dir_path+'gold_2d_tracer_data.p', 'wb') + pickle.dump(check_data,goldfile) + goldfile.close() + + goldfile = open(dir_path+'gold_2d_tracer_data.p', 'rb') + gold_data = pickle.load(goldfile) + goldfile.close() + for k, v in gold_data.items(): + assert((check_data[k]==v).all()) + def test_2D_slice_series(self): ''' @@ -169,11 +384,23 @@ def test_2D_slice_series(self): data.append(dump_parser.build_data_dictionary(filename)) filename = dir_path + "example_dump3.txt" data.append(dump_parser.build_data_dictionary(filename)) - + check_data = {} # extract 2d plane data value tracer_t, tracer_grid = extract_series_2d_slice(data,'time',"temperature",['x','y','z'], 5.0, npts=5 ) + check_data['time'] = tracer_t['time'] + check_data['temperature'] = tracer_grid[0]['temperature'] print(tracer_t, tracer_grid) + if(OPPPY_UPGOLDS): + goldfile = open(dir_path+'gold_2d_slice_tracer_data.p', 'wb') + pickle.dump(check_data,goldfile) + goldfile.close() + + goldfile = open(dir_path+'gold_2d_slice_tracer_data.p', 'rb') + gold_data = pickle.load(goldfile) + goldfile.close() + for k, v in gold_data.items(): + assert((check_data[k]==v).all()) def test_data_2_line(self): @@ -192,18 +419,36 @@ def test_data_2_line(self): # extract all data from the example dump file data = dump_parser.build_data_dictionary(filename) + check_data = {} # plot the data in a bounding box x, y = data2line2d(data, 'x', 'y', 'temperature', 2.5, 1.0, 3.5, 1.8, npts=500, method="linear") + check_data['x1'] = x + check_data['y1'] = y PyPlot.plot(x, y) PyPlot.show() # plot the data in a bounding box x, y = data2line3d(data, 'x', 'y', 'z', 'temperature', 5.0, 1.0, 1.2, 5.0, 2.0, 1.75, npts=50, method="nearest") + check_data['x2'] = x + check_data['y2'] = y + print(x,y) PyPlot.plot(x, y) PyPlot.show() + if(OPPPY_UPGOLDS): + goldfile = open(dir_path+'gold_2d_line_data.p', 'wb') + pickle.dump(check_data,goldfile) + goldfile.close() + + goldfile = open(dir_path+'gold_2d_line_data.p', 'rb') + gold_data = pickle.load(goldfile) + goldfile.close() + for k, v in gold_data.items(): + assert((check_data[k]==v).all()) + + def test_line_series(self): ''' @@ -223,10 +468,38 @@ def test_line_series(self): filename = dir_path + "example_dump3.txt" data.append(dump_parser.build_data_dictionary(filename)) + check_data = {} # extract a 1D data value tracer_t, tracer_grid = extract_series_line(data,'time',"temperature",['x'], [1.0], [5.0], npts=5 ) + check_data['time1'] = np.array([t[0] for t in tracer_t['time']]) + for i in range(len(check_data['time1'])): + check_data['temperature1'+str(i)] = tracer_grid[i]['temperature'] + check_data['x1'+str(i)] = tracer_grid[i]['distance'] + print(tracer_t, tracer_grid) tracer_t, tracer_grid = extract_series_line(data,'time',"temperature",['x','y'], [5.0, 1.0], [5.0, 2.0], npts=5 ) + check_data['time2'] = np.array([t[0] for t in tracer_t['time']]) + for i in range(len(check_data['time2'])): + check_data['temperature2'+str(i)] = tracer_grid[i]['temperature'] + check_data['x2'+str(i)] = tracer_grid[i]['distance'] + print(tracer_t, tracer_grid) tracer_t, tracer_grid = extract_series_line(data,'time',"temperature",['x','y','z'], [5.0, 1.0, 1.2], [5.0, 2.0, 1.75], npts=5 ) + check_data['time3'] = np.array([t[0] for t in tracer_t['time']]) + for i in range(len(check_data['time3'])): + check_data['temperature3'+str(i)] = tracer_grid[i]['temperature'] + check_data['x3'+str(i)] = tracer_grid[i]['distance'] print(tracer_t, tracer_grid) + + if(OPPPY_UPGOLDS): + goldfile = open(dir_path+'gold_line_data.p', 'wb') + pickle.dump(check_data,goldfile) + goldfile.close() + + goldfile = open(dir_path+'gold_line_data.p', 'rb') + gold_data = pickle.load(goldfile) + goldfile.close() + for k, v in gold_data.items(): + assert((check_data[k]==v).all()) + + diff --git a/tests/test_output.py b/tests/test_output.py index cd69b49..27cc2ca 100644 --- a/tests/test_output.py +++ b/tests/test_output.py @@ -12,8 +12,10 @@ import os dir_path = os.path.dirname(os.path.realpath(__file__))+"/" +OPPPY_UPGOLDS = os.getenv("OPPPY_UPGOLDS", 'False').lower() in ('true', '1', 't') import unittest +import pickle from opppy.output import * @@ -29,21 +31,27 @@ def test_get_output_lines(self): # read all of the data cycle_strings = get_output_lines(dir_path+"example_output.txt","#cycle","#cycle","#end of file") print("All Data: ", cycle_strings) + assert(len(cycle_strings)==2) # only read cycle 1 data cycle_strings2 = get_output_lines(dir_path+"example_output.txt","#cycle","#cycle") print("Cycle 1 Data:",cycle_strings2) + assert(len(cycle_strings2)==1) # only read cycle 2 data cycle_strings3 = get_output_lines(dir_path+"example_output.txt","#cycle 2","#") print("Cycle 2 Data:", cycle_strings3) + assert(len(cycle_strings3)==1 and cycle_strings2!=cycle_strings3) # only read cycle 2 data cycle_strings4 = get_output_lines(dir_path+"example_output.txt","#","#") print("No end file data:", cycle_strings4) + assert(len(cycle_strings4)==2) # read nothing cycle_strings5 = get_output_lines(dir_path+"example_output.txt","#","junk") print("Bad end cycle string so no data:", cycle_strings5) + assert(len(cycle_strings5)==0) # read nothing cycle_strings6 = get_output_lines(dir_path+"example_output.txt","junk","#") print("Bad start cycle string so no data:", cycle_strings6) + assert(len(cycle_strings6)==0) def test_extract_cycle_data(self): ''' @@ -59,7 +67,16 @@ def test_extract_cycle_data(self): opppy_parser = my_test_opppy_parser() my_dictionary = extract_cycle_data(my_cycle_string, opppy_parser) - + if(OPPPY_UPGOLDS): + goldfile = open(dir_path+'gold_extract_cycle.p', 'wb') + pickle.dump(my_dictionary,goldfile) + goldfile.close() + + goldfile = open(dir_path+'gold_extract_cycle.p', 'rb') + gold_data = pickle.load(goldfile) + goldfile.close() + assert(my_dictionary==gold_data) + print(my_dictionary) @@ -67,7 +84,6 @@ def test_append_output_dictionary(self): ''' This test the append_pickle function ''' - # import the test parser from my_test_opppy_parser import my_test_opppy_parser from opppy.version import __version__ @@ -98,7 +114,18 @@ def test_append_output_dictionary(self): # Build initial pickle append_output_dictionary(data, output_files, opppy_parser) - print(data) + if(OPPPY_UPGOLDS): + goldfile = open(dir_path+'gold_output.p', 'wb') + pickle.dump(data,goldfile) + goldfile.close() + + goldfile = open(dir_path+'gold_output.p', 'rb') + gold_data = pickle.load(goldfile) + goldfile.close() + # Don't check the version for a match + gold_data.pop('version') + data.pop('version') + assert(data==gold_data) # initialize a new data dictionary data2 = {} @@ -111,3 +138,7 @@ def test_append_output_dictionary(self): append_output_dictionary(data2, output_files, opppy_parser) print(data2) + # Don't check the version for a match + data2.pop('version') + assert(data2==gold_data) + diff --git a/tests/test_tally.py b/tests/test_tally.py index 0e1eb84..ce2542c 100644 --- a/tests/test_tally.py +++ b/tests/test_tally.py @@ -12,6 +12,7 @@ import os dir_path = os.path.dirname(os.path.realpath(__file__))+"/" +OPPPY_UPGOLDS = os.getenv("OPPPY_UPGOLDS", 'False').lower() in ('true', '1', 't') import unittest @@ -34,7 +35,18 @@ def test_extract_cycle_data(self): opppy_parser = my_test_opppy_tally_parser() my_dictionary = extract_cycle_data(my_cycle_string, opppy_parser) - + if(OPPPY_UPGOLDS): + goldfile = open(dir_path+'gold_tally_extract_cycle.p', 'wb') + pickle.dump(my_dictionary,goldfile) + goldfile.close() + + goldfile = open(dir_path+'gold_tally_extract_cycle.p', 'rb') + gold_data = pickle.load(goldfile) + goldfile.close() + for dic, gold_dic in zip(my_dictionary,gold_data): + assert(dic==gold_dic) + + print(my_dictionary) @@ -74,6 +86,19 @@ def test_append_tally_dictionary(self): append_tally_dictionary(data, tally_files, opppy_parser) print(data) + if(OPPPY_UPGOLDS): + goldfile = open(dir_path+'gold_tally.p', 'wb') + pickle.dump(data,goldfile) + goldfile.close() + + goldfile = open(dir_path+'gold_tally.p', 'rb') + gold_data = pickle.load(goldfile) + goldfile.close() + # Don't check the version for a match + gold_data.pop('version') + data.pop('version') + for dic, gold_dic in zip(data,gold_data): + assert(dic==gold_dic) # initialize a new data dictionary data2 = {} @@ -86,3 +111,7 @@ def test_append_tally_dictionary(self): append_tally_dictionary(data2, tally_files, opppy_parser) print(data2) + # Don't check the version for a match + data2.pop('version') + for dic, gold_dic in zip(data2,gold_data): + assert(dic==gold_dic)