# Path: sourcefinder/testutil/data.py
# DATAPATH = os.environ.get('TKP_TESTPATH', DEFAULT)
# 
# Path: sourcefinder/testutil/decorators.py
# def requires_data(*args):
#     for filename in args:
#         if not os.path.exists(filename):
#             return unittest.skip("Test data (%s) not available" % filename)
#     return lambda func: func


import gc
import os
import unittest
import sourcefinder.accessors.fitsimage
import sourcefinder.image as image
import sourcefinder.utility.coordinates as coords
from sourcefinder.testutil.data import DATAPATH
from sourcefinder.testutil.decorators import requires_data
    @requires_data(all_fits)
    def testFluxes(self):

        #self.results.sort(lambda x, y: (y.peak > x.peak) - (y.peak < x.peak))
        self.results.sort(key=lambda x: x.peak)
        self.assertAlmostEqual(self.results[0].peak.value, 1.0 * FUDGEFACTOR, 1)


class FitToPointTestCase(unittest.TestCase):
    def setUp(self):
        # Beam here is a random beam, in this case the WENSS beam
        # without the declination dependence.
        fitsfile = sourcefinder.accessors.fitsimage.FitsImage(corrected_fits,
                                                              beam=(54. / 3600,
                                                                    54. / 3600,
                                                                    0.))
        self.my_im = image.ImageData(fitsfile.data, fitsfile.beam,
                                     fitsfile.wcs)

    def tearDown(self):
        del self.my_im
        gc.collect()

    @requires_data(corrected_fits)
    def testFixed(self):
        d = self.my_im.fit_to_point(1379.00938273, 1438.38801493, 20,
                                    threshold=2, fixed='position')
        self.assertAlmostEqual(d.x.value, 1379.00938273)
        self.assertAlmostEqual(d.y.value, 1438.38801493)


# Path: sourcefinder/testutil/data.py
# DATAPATH = os.environ.get('TKP_TESTPATH', DEFAULT)
# 
# Path: sourcefinder/testutil/decorators.py
# def requires_data(*args):
#     for filename in args:
#         if not os.path.exists(filename):
#             return unittest.skip("Test data (%s) not available" % filename)
#     return lambda func: func


# Path: test/test_L15_12h_const.py
import gc
import os
import unittest
import sourcefinder.accessors.fitsimage
import sourcefinder.image as image
import sourcefinder.utility.coordinates as coords
from sourcefinder.testutil.data import DATAPATH
from sourcefinder.testutil.decorators import requires_data

    @requires_data(all_fits)
    def testFluxes(self):

        #self.results.sort(lambda x, y: (y.peak > x.peak) - (y.peak < x.peak))
        self.results.sort(key=lambda x: x.peak)
        self.assertAlmostEqual(self.results[0].peak.value, 1.0 * FUDGEFACTOR, 1)


class FitToPointTestCase(unittest.TestCase):
    def setUp(self):
        # Beam here is a random beam, in this case the WENSS beam
        # without the declination dependence.
        fitsfile = sourcefinder.accessors.fitsimage.FitsImage(corrected_fits,
                                                              beam=(54. / 3600,
                                                                    54. / 3600,
                                                                    0.))
        self.my_im = image.ImageData(fitsfile.data, fitsfile.beam,
                                     fitsfile.wcs)

    def tearDown(self):
        del self.my_im
        gc.collect()

    @requires_data(corrected_fits)
    def testFixed(self):
        d = self.my_im.fit_to_point(1379.00938273, 1438.38801493, 20,
                                    threshold=2, fixed='position')
        self.assertAlmostEqual(d.x.value, 1379.00938273)
        self.assertAlmostEqual(d.y.value, 1438.38801493)


    @requires_data(corrected_fits)