# Path: tkp/testutil/stream_emu.py
# def create_fits_hdu():
#     """
#     Create a fake AARTFAAC file used as a base for the emulated servers. Could
#     be anything but for now we just take the fits file from the test data.
# 
#     returns:
#         astropy.io.fits.HDUList: a fits object
#     """
#     hdulist = fits.open(path.join(DATAPATH, 'accessors/aartfaac.fits'))
#     hdu = hdulist[0]
#     return hdu
# 
# def serialize_hdu(hdu):
#     """
#     Serialize a fits object.
# 
#     args:
#         hdu (astropy.io.fits.HDUList): a fits object
#     returns:
#         str: a serialized fits object.
#     """
#     data = struct.pack('=%sf' % hdu.data.size, *hdu.data.flatten('F'))
#     header = hdu.header.tostring()
#     return data, header
# 
# def make_window(hdu):
#     """
#     Construct a complete serialised image including aartfaac header
# 
#     args:
#         hdu (astropy.io.fits.HDUList): the first header
#     returns:
#         str: serialised fits file
#     """
#     result = StringIO.StringIO()
#     data, fits_header = serialize_hdu(hdu)
#     header = create_header(len(fits_header), len(data))
#     result.write(header)
#     result.write(fits_header)
#     result.write(data)
#     return result.getvalue()


import unittest
import dateutil
import tkp.stream
from datetime import datetime
from tkp.testutil.stream_emu import create_fits_hdu, serialize_hdu, make_window


class TestStream(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.hdu = create_fits_hdu()
        now = datetime.now()
        cls.hdu.header['date-obs'] = now.isoformat()

    def test_reconstruct(self):

# Path: tkp/testutil/stream_emu.py
# def create_fits_hdu():
#     """
#     Create a fake AARTFAAC file used as a base for the emulated servers. Could
#     be anything but for now we just take the fits file from the test data.
# 
#     returns:
#         astropy.io.fits.HDUList: a fits object
#     """
#     hdulist = fits.open(path.join(DATAPATH, 'accessors/aartfaac.fits'))
#     hdu = hdulist[0]
#     return hdu
# 
# def serialize_hdu(hdu):
#     """
#     Serialize a fits object.
# 
#     args:
#         hdu (astropy.io.fits.HDUList): a fits object
#     returns:
#         str: a serialized fits object.
#     """
#     data = struct.pack('=%sf' % hdu.data.size, *hdu.data.flatten('F'))
#     header = hdu.header.tostring()
#     return data, header
# 
# def make_window(hdu):
#     """
#     Construct a complete serialised image including aartfaac header
# 
#     args:
#         hdu (astropy.io.fits.HDUList): the first header
#     returns:
#         str: serialised fits file
#     """
#     result = StringIO.StringIO()
#     data, fits_header = serialize_hdu(hdu)
#     header = create_header(len(fits_header), len(data))
#     result.write(header)
#     result.write(fits_header)
#     result.write(data)
#     return result.getvalue()


# Path: tests/test_stream.py
import unittest
import dateutil
import tkp.stream
from datetime import datetime
from tkp.testutil.stream_emu import create_fits_hdu, serialize_hdu, make_window



class TestStream(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.hdu = create_fits_hdu()
        now = datetime.now()
        cls.hdu.header['date-obs'] = now.isoformat()

    def test_reconstruct(self):

        data, header = serialize_hdu(self.hdu)