diff --git a/AegeanTools/source_finder.py b/AegeanTools/source_finder.py index 5bac437e..09956759 100644 --- a/AegeanTools/source_finder.py +++ b/AegeanTools/source_finder.py @@ -301,7 +301,7 @@ def estimate_lmfit_parinfo(self, data, rmsimg, curve, beam, innerclip, outerclip pixbeam = global_data.psfhelper.get_pixbeam_pixel(yo + offsets[0], xo + offsets[1]) if pixbeam is None: - self.log.debug(" Summit has invalid WCS/Beam - Skipping.".format(i)) + self.log.debug(" Summit has invalid WCS/Beam - Skipping.") continue # set a square limit based on the size of the pixbeam @@ -1223,7 +1223,7 @@ def _refit_islands(self, group, stage, outerclip=None, istart=0): if 'amp' not in p: params[p].vary = False else: - self.log.debug(" no not-masked pixels, skipping".format(src.island, src.source)) + self.log.debug(" no not-masked pixels, skipping") continue # do the fit diff --git a/tests/test_BANE.py b/tests/test_BANE.py index 723a670b..5be1eeb7 100644 --- a/tests/test_BANE.py +++ b/tests/test_BANE.py @@ -19,20 +19,26 @@ def test_sigmaclip(): # normal usage case data = np.random.random(100) data[13] = np.nan - assert len(BANE.sigmaclip(data, 3, 4, reps=4)) > 0 + if not len(BANE.sigmaclip(data, 3, 4, reps=4)) > 0: + raise AssertionError() # test list where all elements get clipped - assert len(BANE.sigmaclip([-10, 10], 1, 2, reps=2)) == 0 + if not len(BANE.sigmaclip([-10, 10], 1, 2, reps=2)) == 0: + raise AssertionError() # test empty list - assert len(BANE.sigmaclip([], 0, 3)) == 0 + if not len(BANE.sigmaclip([], 0, 3)) == 0: + raise AssertionError() def test_optimum_sections(): # typical case - assert BANE.optimum_sections(8, (64, 64)) == (2, 4) + if not BANE.optimum_sections(8, (64, 64)) == (2, 4): + raise AssertionError() + # redundant case - assert BANE.optimum_sections(1, (134, 1200)) == (1, 1) + if not BANE.optimum_sections(1, (134, 1200)) == (1, 1): + raise AssertionError() def test_mask_data(): @@ -41,7 +47,8 @@ def test_mask_data(): mask[3:5, 0:2] = np.nan BANE.mask_img(data, mask) # check that the nan regions overlap - assert np.all(np.isnan(data) == np.isnan(mask)) + if not np.all(np.isnan(data) == np.isnan(mask)): + raise AssertionError() def test_filter_image(): @@ -53,14 +60,22 @@ def test_filter_image(): # hdu = fits.getheader(fname) # shape = hdu[0]['NAXIS1'], hdu[0]['NAXIS2'] BANE.filter_image(fname, step_size=[10, 10], box_size=[100, 100], cores=1, out_base=outbase) - assert os.path.exists(rms) + if not os.path.exists(rms): + raise AssertionError() + os.remove(rms) - assert os.path.exists(bkg) + if not os.path.exists(bkg): + raise AssertionError() + os.remove(bkg) BANE.filter_image(fname, cores=2, out_base=outbase, twopass=True, compressed=True) - assert os.path.exists(rms) + if not os.path.exists(rms): + raise AssertionError() + os.remove(rms) - assert os.path.exists(bkg) + if not os.path.exists(bkg): + raise AssertionError() + os.remove(bkg) @@ -69,4 +84,4 @@ def test_filter_image(): for f in dir(): if f.startswith('test'): print(f) - exec(f+"()") \ No newline at end of file + globals()[f]() \ No newline at end of file diff --git a/tests/test_angle_tools.py b/tests/test_angle_tools.py index c98020b1..e27de2e5 100644 --- a/tests/test_angle_tools.py +++ b/tests/test_angle_tools.py @@ -32,7 +32,8 @@ def test_dec2dms(): (np.nan, "XX:XX:XX.XX"), (np.inf, "XX:XX:XX.XX")]: ans = at.dec2dms(dec) - assert ans == dstr, "{0} != {1}".format(ans, dstr) + if not ans == dstr: + raise AssertionError("{0} != {1}".format(ans, dstr)) def test_dec2hms(): @@ -42,7 +43,8 @@ def test_dec2hms(): (np.nan, "XX:XX:XX.XX"), (np.inf, "XX:XX:XX.XX")]: ans = at.dec2hms(dec) - assert ans == dstr, "{0} != {1}".format(ans, dstr) + if not ans == dstr: + raise AssertionError("{0} != {1}".format(ans, dstr)) def test_gcd(): @@ -104,4 +106,4 @@ def test_translate_rhumb(): for f in dir(): if f.startswith('test'): print(f) - exec(f+"()") \ No newline at end of file + globals()[f]() \ No newline at end of file diff --git a/tests/test_catalogs.py b/tests/test_catalogs.py index 7fc26325..82a20796 100644 --- a/tests/test_catalogs.py +++ b/tests/test_catalogs.py @@ -19,8 +19,11 @@ def test_check_table_formats(): files = ','.join(['a.csv', 'a.fits', 'a.vot', 'a.hdf5', 'a.ann', 'a.docx', 'a']) - assert not cat.check_table_formats(files) - assert cat.check_table_formats('files.fits') + + if cat.check_table_formats(files): + raise AssertionError() + if not cat.check_table_formats('files.fits'): + raise AssertionError() def test_show_formats(): @@ -31,16 +34,20 @@ def test_get_table_formats(): formats = cat.get_table_formats() for f in formats: name = 'a.'+f - assert cat.check_table_formats(name) + if not cat.check_table_formats(name): + raise AssertionError() def test_update_meta_data(): meta = None meta = cat.update_meta_data(meta) - assert 'PROGRAM' in meta + if 'PROGRAM' not in meta: + raise AssertionError() + meta = {'DATE': 1} meta = cat.update_meta_data(meta) - assert meta['DATE'] == 1 + if not meta['DATE'] == 1: + raise AssertionError() def test_load_save_catalog(): @@ -49,21 +56,29 @@ def test_load_save_catalog(): fout = 'a.'+ext cat.save_catalog(fout, catalog, meta=None) fout = 'a_comp.'+ext - assert os.path.exists(fout) + if not os.path.exists(fout): + raise AssertionError() + catin = cat.load_catalog(fout) - assert len(catin) == len(catalog) + if not len(catin) == len(catalog): + raise AssertionError() + os.remove(fout) for ext in ['reg', 'ann', 'bla']: fout = 'a.'+ext cat.save_catalog(fout, catalog, meta=None) fout = 'a_comp.'+ext - assert os.path.exists(fout) + if not os.path.exists(fout): + raise AssertionError() + os.remove(fout) fout = 'a.db' cat.save_catalog(fout, catalog, meta=None) - assert os.path.exists(fout) + if not os.path.exists(fout): + raise AssertionError() + os.remove(fout) badfile = open("file.fox", 'w') @@ -75,7 +90,9 @@ def test_load_save_catalog(): badfile.close() catin = cat.load_catalog('file.fox') print(catin) - assert len(catin) == 1 + if not len(catin) == 1: + raise AssertionError() + os.remove('file.fox') @@ -86,13 +103,17 @@ def test_load_table_write_table(): cat.save_catalog(fout, catalog, meta=None) fout = 'a_comp.'+fmt tab = cat.load_table(fout) - assert len(tab) == len(catalog) + if not len(tab) == len(catalog): + raise AssertionError() + os.remove(fout) cat.save_catalog('a.csv', catalog, meta=None) tab = cat.load_table('a_comp.csv') cat.write_table(tab, 'a.csv') - assert os.path.exists('a.csv') + if not os.path.exists('a.csv'): + raise AssertionError() + os.remove('a.csv') assert_raises(Exception, cat.write_table, tab, 'bla.fox') @@ -104,11 +125,17 @@ def test_write_comp_isl_simp(): catalog[0].galactic = True out = 'a.csv' cat.write_catalog(out, catalog) - assert os.path.exists('a_isle.csv') + if not os.path.exists('a_isle.csv'): + raise AssertionError() + os.remove('a_isle.csv') - assert os.path.exists('a_comp.csv') + if not os.path.exists('a_comp.csv'): + raise AssertionError() + os.remove('a_comp.csv') - assert os.path.exists('a_simp.csv') + if not os.path.exists('a_simp.csv'): + raise AssertionError() + os.remove('a_simp.csv') @@ -117,7 +144,9 @@ def dont_test_load_save_fits_tables(): # probably a bug that will be fixed by astropy later. catalog = [OutputSource()] cat.save_catalog('a.fits', catalog, meta=None) - assert os.path.exists('a_comp.fits') + if not os.path.exists('a_comp.fits'): + raise AssertionError() + os.remove('a_comp.fits') # Somehow this doesn't work for my simple test cases # catin = cat.load_table('a_comp.fits') @@ -134,37 +163,53 @@ def test_write_contours_boxes(): src.extent = [1, 4, 1, 4] catalog = [src] cat.writeIslandContours('out.reg', catalog, fmt='reg') - assert os.path.exists('out.reg') + if not os.path.exists('out.reg'): + raise AssertionError() + os.remove('out.reg') # shouldn't write anything cat.writeIslandContours('out.ann', catalog, fmt='ann') - assert not os.path.exists('out.ann') + if os.path.exists('out.ann'): + raise AssertionError() cat.writeIslandBoxes('out.reg', catalog, fmt='reg') - assert os.path.exists('out.reg') + if not os.path.exists('out.reg'): + raise AssertionError() + os.remove('out.reg') cat.writeIslandBoxes('out.ann', catalog, fmt='ann') - assert os.path.exists('out.ann') + if not os.path.exists('out.ann'): + raise AssertionError() + os.remove('out.ann') # shouldn't write anything cat.writeIslandBoxes('out.ot', catalog, fmt='ot') - assert not os.path.exists('out.ot') + if os.path.exists('out.ot'): + raise AssertionError() def test_write_ann(): # write regular and simple sources for .ann files cat.writeAnn('out.ann', [OutputSource()], fmt='ann') - assert os.path.exists('out_comp.ann') + if not os.path.exists('out_comp.ann'): + raise AssertionError() + os.remove('out_comp.ann') cat.writeAnn('out.ann', [SimpleSource()], fmt='ann') - assert os.path.exists('out_simp.ann') + if not os.path.exists('out_simp.ann'): + raise AssertionError() + os.remove('out_simp.ann') # same but for .reg files cat.writeAnn('out.reg', [OutputSource()], fmt='reg') - assert os.path.exists('out_comp.reg') + if not os.path.exists('out_comp.reg'): + raise AssertionError() + os.remove('out_comp.reg') cat.writeAnn('out.reg', [SimpleSource()], fmt='reg') - assert os.path.exists('out_simp.reg') + if not os.path.exists('out_simp.reg'): + raise AssertionError() + os.remove('out_simp.reg') @@ -173,4 +218,4 @@ def test_write_ann(): for f in dir(): if f.startswith('test'): print(f) - exec(f+"()") \ No newline at end of file + globals()[f]() \ No newline at end of file diff --git a/tests/test_cluster.py b/tests/test_cluster.py index a8c9cf47..8413a164 100644 --- a/tests/test_cluster.py +++ b/tests/test_cluster.py @@ -75,4 +75,4 @@ def test_regroup(): for f in dir(): if f.startswith('test'): print(f) - exec(f+"()") \ No newline at end of file + globals()[f]() \ No newline at end of file diff --git a/tests/test_fits_image.py b/tests/test_fits_image.py index 13955c6f..a02d555b 100644 --- a/tests/test_fits_image.py +++ b/tests/test_fits_image.py @@ -136,4 +136,4 @@ def test_pix2sky_sky2pix(): for f in dir(): if f.startswith('test'): print(f) - exec(f+"()") \ No newline at end of file + globals()[f]() \ No newline at end of file diff --git a/tests/test_fits_interp.py b/tests/test_fits_interp.py index 1cd478ac..527b885c 100644 --- a/tests/test_fits_interp.py +++ b/tests/test_fits_interp.py @@ -76,4 +76,4 @@ def test_fits_interp_compress_then_expand(): for f in dir(): if f.startswith('test'): print(f) - exec(f+"()") \ No newline at end of file + globals()[f]() \ No newline at end of file diff --git a/tests/test_fitting.py b/tests/test_fitting.py index e38629ea..8f1edde2 100644 --- a/tests/test_fitting.py +++ b/tests/test_fitting.py @@ -209,4 +209,4 @@ def test_condon_errs(): for f in dir(): if f.startswith('test'): print(f) - exec(f+"()") + globals()[f]() diff --git a/tests/test_misc.py b/tests/test_misc.py index 9e850090..8971e106 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -13,4 +13,4 @@ def test_flags(): for f in dir(): if f.startswith('test'): print(f) - exec(f+"()") \ No newline at end of file + globals()[f]() \ No newline at end of file diff --git a/tests/test_models.py b/tests/test_models.py index 239a626a..00e4b684 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -78,4 +78,4 @@ def test_classify_catalogue(): for f in dir(): if f.startswith('test'): print(f) - exec(f+"()") \ No newline at end of file + globals()[f]() \ No newline at end of file diff --git a/tests/test_msq2.py b/tests/test_msq2.py index 660abc02..608eb409 100644 --- a/tests/test_msq2.py +++ b/tests/test_msq2.py @@ -39,4 +39,4 @@ def test_multi_islands(): for f in dir(): if f.startswith('test'): print(f) - exec(f+"()") \ No newline at end of file + globals()[f]() \ No newline at end of file diff --git a/tests/test_regions.py b/tests/test_regions.py index 33893d07..dce028a6 100644 --- a/tests/test_regions.py +++ b/tests/test_regions.py @@ -226,4 +226,4 @@ def test_symmetric_difference(): for f in dir(): if f.startswith('test'): print(f) - exec(f+"()") \ No newline at end of file + globals()[f]() \ No newline at end of file diff --git a/tests/test_source_finder.py b/tests/test_source_finder.py index 9c91cf75..800990e8 100644 --- a/tests/test_source_finder.py +++ b/tests/test_source_finder.py @@ -169,4 +169,4 @@ def test_save_image(): for f in dir(): if f.startswith('test'): print(f) - exec(f+"()") \ No newline at end of file + globals()[f]() \ No newline at end of file diff --git a/tests/test_wcs_helpers.py b/tests/test_wcs_helpers.py index f965458a..d6df9cf8 100644 --- a/tests/test_wcs_helpers.py +++ b/tests/test_wcs_helpers.py @@ -114,4 +114,4 @@ def test_ellipse_round_trip(): for f in dir(): if f.startswith('test'): print(f) - exec(f+"()") + globals()[f]()