# Path: photometry/todolist.py
# def calc_cbv_area(catalog_row, settings):
# def edge_distance(row, column, aperture=None, image_shape=None):
# def _ffi_todo(hdf5_file, exclude=[], faint_limit=15.0):
# def _tpf_todo(fname, input_folder=None, cameras=None, ccds=None,
# 	find_secondary_targets=True, exclude=[], faint_limit=15.0):
# def make_todo(input_folder=None, sectors=None, cameras=None, ccds=None, overwrite=False,
# 	find_secondary_targets=True, output_file=None):


import pytest
import os
import numpy as np
import tempfile
import sqlite3
import contextlib
import conftest # noqa: F401
from photometry import todolist
			if row['datasource'] == 'ffi':
				assert row['cadence'] == expected_cadence_ffi, "Wrong cadence"
			else:
				assert row['cadence'] in expected_cadence_tpf, "Wrong cadence"

		# NOTE: There is actually 2 TPF matching the test-cases in both sectors:
		cursor.execute("SELECT COUNT(*) FROM todolist WHERE datasource='tpf';")
		assert cursor.fetchone()[0] == 2, "Expected 2 TPFs in todolist"

		if sector == 27:
			#cursor.execute("SELECT COUNT(*) FROM todolist WHERE datasource='ffi';")
			#assert cursor.fetchone()[0] == 0, "Expected no FFI targets in sector 27"
			cursor.execute("SELECT COUNT(*) FROM todolist WHERE datasource='tpf' AND cadence=120;")
			assert cursor.fetchone()[0] == 1, "Expected one TPFs in todolist with 120s cadence"
			cursor.execute("SELECT COUNT(*) FROM todolist WHERE datasource='tpf' AND cadence=20;")
			assert cursor.fetchone()[0] == 1, "Expected one TPFs in todolist with 20s cadence"

		cursor.close()

#--------------------------------------------------------------------------------------------------
def test_make_todolist_invalid_folder():
	INPUT_DIR = os.path.join(os.path.dirname(__file__), 'input')
	with pytest.raises(NotADirectoryError) as e:
		todolist.make_todo(os.path.join(INPUT_DIR, 'does', 'not', 'exist'))
	assert str(e.value) == "The given path does not exist or is not a directory"

#--------------------------------------------------------------------------------------------------
def test_make_todolist_sector1(SHARED_INPUT_DIR):
	with tempfile.NamedTemporaryFile() as tmpfile:
		# Run make_todo and save output to temp-file:

# Path: photometry/todolist.py
# def calc_cbv_area(catalog_row, settings):
# def edge_distance(row, column, aperture=None, image_shape=None):
# def _ffi_todo(hdf5_file, exclude=[], faint_limit=15.0):
# def _tpf_todo(fname, input_folder=None, cameras=None, ccds=None,
# 	find_secondary_targets=True, exclude=[], faint_limit=15.0):
# def make_todo(input_folder=None, sectors=None, cameras=None, ccds=None, overwrite=False,
# 	find_secondary_targets=True, output_file=None):


# Path: tests/test_todolist.py
import pytest
import os
import numpy as np
import tempfile
import sqlite3
import contextlib
import conftest # noqa: F401
from photometry import todolist

			if row['datasource'] == 'ffi':
				assert row['cadence'] == expected_cadence_ffi, "Wrong cadence"
			else:
				assert row['cadence'] in expected_cadence_tpf, "Wrong cadence"

		# NOTE: There is actually 2 TPF matching the test-cases in both sectors:
		cursor.execute("SELECT COUNT(*) FROM todolist WHERE datasource='tpf';")
		assert cursor.fetchone()[0] == 2, "Expected 2 TPFs in todolist"

		if sector == 27:
			#cursor.execute("SELECT COUNT(*) FROM todolist WHERE datasource='ffi';")
			#assert cursor.fetchone()[0] == 0, "Expected no FFI targets in sector 27"
			cursor.execute("SELECT COUNT(*) FROM todolist WHERE datasource='tpf' AND cadence=120;")
			assert cursor.fetchone()[0] == 1, "Expected one TPFs in todolist with 120s cadence"
			cursor.execute("SELECT COUNT(*) FROM todolist WHERE datasource='tpf' AND cadence=20;")
			assert cursor.fetchone()[0] == 1, "Expected one TPFs in todolist with 20s cadence"

		cursor.close()

#--------------------------------------------------------------------------------------------------
def test_make_todolist_invalid_folder():
	INPUT_DIR = os.path.join(os.path.dirname(__file__), 'input')
	with pytest.raises(NotADirectoryError) as e:
		todolist.make_todo(os.path.join(INPUT_DIR, 'does', 'not', 'exist'))
	assert str(e.value) == "The given path does not exist or is not a directory"

#--------------------------------------------------------------------------------------------------
def test_make_todolist_sector1(SHARED_INPUT_DIR):
	with tempfile.NamedTemporaryFile() as tmpfile:
		# Run make_todo and save output to temp-file:

		todolist.make_todo(SHARED_INPUT_DIR, sectors=1, cameras=3, ccds=2, output_file=tmpfile.name)