import os
import tempfile
from Chandra.Time import DateTime
from Ska.Shell import bash
import mica.common

# Override MICA_ARCHIVE with a temporary directory
TESTDIR = tempfile.mkdtemp()
mica.common.MICA_ARCHIVE = TESTDIR
# import mica.starcheck.starcheck after setting MICA_ARCHIVE
import mica.starcheck.starcheck

# Just ingest files from the last couple of weeks or so
# This still uses the silly find files newer than this other file method, so
# set the time stamp on that reference file
if not os.path.exists(os.path.join(TESTDIR, 'starcheck')):
    os.makedirs(os.path.join(TESTDIR, 'starcheck'))
bash("touch -d {} {}".format(DateTime(-15).iso, mica.starcheck.starcheck.FILES['touch_file']))
# And just check that the update script didn't raise any exceptions
mica.starcheck.starcheck.update()
# Cleanup manually
bash("rm -r {}".format(TESTDIR))

Add a script to make a test starcheck database from recent data
Add a script to make a test starcheck database from recent data

Even on just a few weeks, this seems to take too long to be a
standard test, so I'm just putting the logic here for safekeeping.
It could also be a "long" test for ska_testr, but that wouldn't
conveniently let you check test code compatibility without a dev ska.
