diff --git a/tests/test_rdrgen.py b/tests/test_rdrgen.py index 231449aa5dab2fb7fea1c4008d99641857cfbcda..74455f86c39db9a4cdc349755b26eb7a0297b110 100644 --- a/tests/test_rdrgen.py +++ b/tests/test_rdrgen.py @@ -40,9 +40,10 @@ def test_can_reproduce_cris_rdr(tmpdir): str(tmpdir)) -def verify_rdr_reproduction(orig_file_name, tmp_dir): +def verify_rdr_reproduction(orig_file_name, tmp_dir, **build_rdr_opts): orig_file = os.path.join(os.path.dirname(__file__), orig_file_name) - new_file, = m.build_rdr('snpp', generate_rdr_packets(orig_file), output_dir=tmp_dir) + new_file, = m.build_rdr('snpp', generate_rdr_packets(orig_file), output_dir=tmp_dir, + **build_rdr_opts) new_file = os.path.join(tmp_dir, new_file) with h5py.File(orig_file, 'r') as orig_h5, h5py.File(new_file, 'a') as new_h5: root_attrs = ['Distributor', 'N_Dataset_Source', 'N_HDF_Creation_Date', @@ -51,7 +52,7 @@ def verify_rdr_reproduction(orig_file_name, tmp_dir): aggr_attrs = ['AggregateBeginningOrbitNumber', 'AggregateEndingOrbitNumber'] gran_attrs = ['N_Beginning_Orbit_Number', 'N_Creation_Date', 'N_Creation_Time', 'N_IDPS_Mode', 'N_Software_Version', 'N_Granule_Version', - 'N_Reference_ID'] + 'N_Reference_ID', 'N_JPSS_Document_Ref'] def copy_attrs(get_obj, attrs): orig_obj = get_obj(orig_h5) new_obj = get_obj(new_h5) @@ -73,50 +74,9 @@ def verify_rdr_reproduction(orig_file_name, tmp_dir): assert p.returncode == 0 - -def test_can_reproduce_rdr_from_class(): +def test_can_reproduce_rdr_from_class(tmpdir): class_rdr_file = 'RNSCA_npp_d20170912_t0001170_e0001370_b30441_c20170913220340173580_nobu_ops.h5' - class_rdr_path = os.path.join(os.path.dirname(__file__), class_rdr_file) - - # read buffer of raw packets from the RDR - with h5py.File(class_rdr_path, 'r') as class_h5_file: - class_blob = ( - class_h5_file['All_Data/SPACECRAFT-DIARY-RDR_All/RawApplicationPackets_0'][:]) - rdr_info = decode_rdr_blob(class_blob) - ini = rdr_info.header.ap_storage_offset - fin = ini + rdr_info.header.next_pkt_pos - pkt_buf = class_blob[ini:fin] - - # generate new RDR from packets, injecting matching metadata from CLASS file - rdr_type = m.SpacecraftDiaryRdrType - gran_iet = 1883865714000000 - aggr_level = 1 - pkt_stream = jpss_packet_stream(BytesIO(pkt_buf.tobytes())) - blob = m.build_rdr_blob('snpp', pkt_stream, rdr_type, gran_iet) - tmp_dir = '/tmp' - writer = m.RdrWriter( - 'snpp', [rdr_type], gran_iet, aggr_level, tmp_dir, - distributor='arch', origin='nob-', domain='ops', - creation_time=datetime(2017, 9, 13, 22, 3, 40, 173580), - orbit_num=30441, software_ver='I2.0.03.00') - writer.write_aggregate(rdr_type, gran_iet, aggr_level) - writer.write_granule(rdr_type, gran_iet, blob, - creation_time=datetime(2017, 9, 12, 1, 37, 43, 474383)) - writer.close() - - - # file names should be identical - assert writer.file_name == class_rdr_file - - # use h5diff to verify files match. -p option is needed to allow some slop - # in comparing N_Percent_Missing_Data - p = subprocess.Popen( - ['h5diff', '-c', '-p', '1e-6', - class_rdr_path, os.path.join(tmp_dir, writer.file_name)], - stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - stdout, _ = p.communicate() - assert stdout.decode() == '' - assert p.returncode == 0 + verify_rdr_reproduction(class_rdr_file, str(tmpdir), aggr_level=1) class TestGranulation(object):