def test_search_headers_no_datafile(self): """ Tests the search_headers function against the original file that caused the issue. """ try: download_folder("search_headers") except: raise DataDownloadException( "Could not download test data for skies." ) raw_dir = "src/simmer/tests/test_search_header/" data, header = pyfits.getdata( raw_dir + "wrong_header.fits", header=True ) del header["DATAFILE"] pyfits.writeto( raw_dir + "wrong_header.fits", data, header, overwrite=True ) with captured_output() as (out, err): search.search_headers(raw_dir) anticipated_string = "Header Incomplete in src/simmer/tests/test_search_header/wrong_header.fits!!!" # This can go inside or outside the `with` block output = out.getvalue().strip() delete_folder(raw_dir) self.assertEqual(output, anticipated_string)
def test_create_config_xlsx(self): try: download_folder("config_test") except: raise DataDownloadException( "Could not download test data for config_test." ) tab = "Sheet1" excel_path = "src/simmer/Examples/Shane/logsheet.xlsx" c.create_config(excel_path, "created_frame.csv", tab) created_frame = pd.read_csv("created_frame.csv") compare_frame = pd.read_csv( "src/simmer/tests/config_test/created_frame_xlsx.csv" ) delete_folder("src/simmer/tests/config_test") self.assertTrue(created_frame.equals(compare_frame))
def test_add_dark_exposure(self): try: download_folder("dark_test") except: raise DataDownloadException( "Could not download test data for darks." ) excel_path = "src/simmer/Examples/Shane/logsheet.xlsx" copy_path = "src/simmer/Examples/Shane/logsheet_copy.xlsx" copyfile(excel_path, copy_path) raw_dir = "src/simmer/tests/dark_test/" tab = "Sheet1" inst = i.ShARCS() ad.add_dark_exp(inst, copy_path, raw_dir, tab) os.remove(copy_path) delete_folder(raw_dir) self.assertTrue(True)
def test_readpharo_quadrants(self): try: download_folder("readpharo_test") except: raise DataDownloadException( "Could not download test data for readpharo function." ) raw_dir, new_dir, test_red_dir = ( "src/simmer/tests/readpharo_test/raw/", "src/simmer/tests/readpharo_test/test_newdir/", "src/simmer/tests/readpharo_test/test_red/", ) self.inst.read_data(raw_dir, new_dir) compare_flattened = pyfits.getdata(test_red_dir + "sph0436.fits") zero = np.zeros(np.shape(compare_flattened)) flattened = pyfits.getdata(new_dir + "sph0436.fits") val = np.all(np.allclose(compare_flattened, flattened, equal_nan=True)) delete_folder("src/simmer/tests/readpharo_test") self.assertTrue(val)
def test_search_headers(self): try: download_folder("sky_test") except: raise DataDownloadException( "Could not download test data for skies." ) raw_dir, write_dir = ( "src/simmer/tests/sky_test/", "src/simmer/tests/sky_test/", ) search.search_headers(raw_dir, write_dir) val = True f = open(write_dir + "headers_wrong.txt", "r") for line in f: if "INCOMPLETE" in line: val = False f.close() self.assertTrue(val)
def test_LogsheetError(self): try: download_folder("config_test") except: raise DataDownloadException( "Could not download test data for config_test." ) tab = "Sheet1" logsheet_path = "src/simmer/Examples/PHARO/logsheet.csv" frame = pd.read_csv(logsheet_path) nan_start_config_path = "src/simmer/tests/nan_start_config_test.csv" frame.loc[20, "Start"] = np.nan frame.to_csv(nan_start_config_path) self.assertRaises( c.LogsheetError, c.create_config, nan_start_config_path, "created_frame.csv", tab, )