; docformat = 'rst' ;+ ; :Description: ; Unit tests for the cube_generator fits writer ; ; :Author: ; Josh Elliott ; joshua.elliott@lasp.colorado.edu ; ; :Requires: ; Written with IDL 8.6.1, but should run with anything > 8.3 ; mgunit : https://github.com/mgalloy/mgunit ; mglib : https://github.com/mgalloy/mglib ; IDLAstro : https://github.com/wlandsman/IDLAstro ; ; :History: ; Created 20 November 2017 ;- ;+ ; :Description: ; Setup for each test ; ;- pro uvis_fits_writer_ut::setup compile_opt idl2 self.test_struct = ptr_new({X:42, Y:'test', Z:indgen(4,2,3)}) self.fits_file_name = file_dirname(routine_filepath()) + path_sep() + 'test_file.fits' if file_test(self.fits_file_name) then begin file_delete, self.fits_file_name endif end ;+ ; :Description: ; Teardown for each test ; ;- pro uvis_fits_writer_ut::teardown compile_opt idl2 if file_test(self.fits_file_name) then begin file_delete, self.fits_file_name endif end ;+ ; :Description: ; Simple test to verify file creation. ; ;- function uvis_fits_writer_ut::test_create_file compile_opt idl2 s = *(self.test_struct) uvis_fits_writer, self.fits_file_name, s, replicate(s, 4), replicate(s, 2) assert, file_test(self.fits_file_name), 'File was not created.' return, 1 end ;+ ; :Description: ; Test to verify that the header was written. ;- function uvis_fits_writer_ut::test_header compile_opt idl2 s = *(self.test_struct) uvis_fits_writer, self.fits_file_name, s, replicate(s, 4), replicate(s, 2), HEADER=sindgen(10) !null = mrdfits(self.fits_file_name, 0, header, /SILENT) found = !false foreach line, header do begin found = line.contains('The UVIS instrument is part of the remote sensing payload') if found then break endforeach assert, found, 'Header information is missing.' assert, header[-2].contains('9'), 'Header information is incorrect.' return, 1 end ;+ ; :Description: ; Verify that the file contains the correct data. ;- function uvis_fits_writer_ut::test_verify_data compile_opt idl2 s = *(self.test_struct) s1 = replicate(s, 4) s2 = replicate(s, 2) uvis_fits_writer, self.fits_file_name, s, s1, s2 data = mrdfits(self.fits_file_name, 1, header, /SILENT) assert, s.x eq data.x, 'File data does not match test data.' assert, s.y eq data.y, 'File data does not match test data.' assert, array_equal(s.z, data.z), 'File data does not match test data.' return, 1 end ;+ ; :Description: ; Verify that the number of hdus in the fits file is correct ;- function uvis_fits_writer_ut::test_verify_n_hdus compile_opt idl2 s = *(self.test_struct) s1 = replicate(s, 4) s2 = replicate(s, 2) uvis_fits_writer, self.fits_file_name, s, s1, s2 fits_info, self.fits_file_name, N_EXT=n_hdus, /SILENT assert, n_hdus eq 3, 'Number of HDUs is incorrect.' return, 1 end ;+ ; :Description: ; Verify the result when multiple readouts are present. ;- function uvis_fits_writer_ut::test_verify_multiple_readouts compile_opt idl2 s = *(self.test_struct) s1 = replicate(s, 4) s2 = replicate(s, 2) uvis_fits_writer, self.fits_file_name, s, s1, s2 fits_info, self.fits_file_name, N_EXT=n_hdus, /SILENT hdus = list() idx = list() for i=1, n_hdus do begin ; start from 1, 0 is the "primary" which is just the header in our case. hdu = mrdfits(self.fits_file_name, i, header, /SILENT) hdu = orderedhash(hdu) dataset_name = hdu.Remove('DATASET_NAME') case (strlowcase(dataset_name)) of 'datastruct_initial': begin hdus.add, hdu.tostruct() idx.add, i-1 end else: begin ; ignore the others end endcase endfor hdus = hdus.toarray() idx = idx.toarray() idx = idx.sort() hdus = hdus[idx] assert, array_equal(s1.x, hdus.x), 'File data does not match test data.' assert, array_equal(s1.y, hdus.y), 'File data does not match test data.' assert, array_equal(s1.z, hdus.z), 'File data does not match test data.' return, 1 end ;+ ; :Description: ; ;- function uvis_fits_writer_ut::test_only_one_hdu compile_opt idl2 s = *(self.test_struct) uvis_fits_writer, self.fits_file_name, s fits_info, self.fits_file_name, N_EXT=n_hdus, /SILENT assert, n_hdus eq 1, 'Number of HDUs is incorrect.' return, 1 end ;+ ; :Description: ; ;- function uvis_fits_writer_ut::test_calibration_matrix compile_opt idl2 s = *(self.test_struct) s1 = replicate(s, 4) s2 = replicate(s, 2) cal_matrix = findgen(10,42) cal_matrix_err = findgen(10,42)+42 uvis_fits_writer, self.fits_file_name, s, s1, s2, cal_matrix, cal_matrix_err fits_info, self.fits_file_name, N_EXT=n_hdus, /SILENT assert, n_hdus eq 5, 'Number of HDUs is incorrect.' return, 1 end ;+ ; :Description: ; Class data definition procedure ;- pro uvis_fits_writer_ut__define compile_opt idl2 !NULL = {uvis_fits_writer_ut, $ inherits MGutTestCase, $ test_struct: ptr_new(), $ fits_file_name: '' $ } end