Skip to content

Commit

Permalink
implemented tox to run tests
Browse files Browse the repository at this point in the history
  • Loading branch information
simontorres committed Jul 24, 2024
1 parent bc3ab81 commit cd21d15
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 33 deletions.
14 changes: 7 additions & 7 deletions goodman_pipeline/core/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ class ClassifySpectroscopicData(TestCase):

def setUp(self):
self.path = os.path.join(
os.getcwd(),
'goodman_pipeline/data/test_data/test_classify_spectroscopic');
os.path.dirname(__file__),
'../../data/test_data/test_classify_spectroscopic');
if not os.path.isdir(self.path):
os.mkdir(self.path)

Expand Down Expand Up @@ -1366,7 +1366,7 @@ def setUp(self):
# expected master flat to be retrieved by get_best_flat
self.reference_flat_name = 'master_flat_1200m2_0.84_dome.fits'
# location of sample flats
self.flat_path = 'goodman_pipeline/data/test_data/master_flat'
self.flat_path = os.path.join(os.path.dirname(__file__), '../../data/test_data/master_flat')
slit = re.sub('[A-Za-z" ]',
'',
self.master_flat.header['SLIT'])
Expand Down Expand Up @@ -1761,8 +1761,8 @@ class ReferenceDataTest(TestCase):

def setUp(self):
self.rd = ReferenceData(
reference_dir=os.path.join(os.getcwd(),
'goodman_pipeline/data/ref_comp'))
reference_dir=os.path.join(os.path.dirname(__file__),
'../../data/ref_comp'))
self.ccd = CCDData(data=np.ones((800, 2000)),
meta=fits.Header(),
unit='adu')
Expand Down Expand Up @@ -2037,8 +2037,8 @@ def setUp(self):
'FALSE']], columns=columns)]

self.reference_data = ReferenceData(
reference_dir=os.path.join(os.getcwd(),
'goodman_pipeline/data/ref_comp'))
reference_dir=os.path.join(os.path.dirname(__file__),
'../../data/ref_comp'))

def test_search_comp_group(self):
result = search_comp_group(
Expand Down
4 changes: 2 additions & 2 deletions goodman_pipeline/images/tests/test_data_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class DataClassifierTests(TestCase):

def setUp(self):
self.raw_path = os.path.join(
os.getcwd(),
'goodman_pipeline/data/test_data/classify-data')
os.path.dirname(__file__),
'../../data/test_data/classify-data')

if not os.path.isdir(self.raw_path):
os.mkdir(self.raw_path)
Expand Down
4 changes: 2 additions & 2 deletions goodman_pipeline/images/tests/test_night_organizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ class NightOrganizerTest(TestCase):

def setUp(self):
self.full_path = os.path.join(
os.getcwd(),
'goodman_pipeline/data/test_data/night-organizer-test')
os.path.dirname(__file__),
'../../data/test_data/night-organizer-test')

if not os.path.isdir(self.full_path):
os.mkdir(self.full_path)
Expand Down
13 changes: 6 additions & 7 deletions goodman_pipeline/spectroscopy/tests/test_redspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ def test_reference_dir_does_not_exists(self):

args = get_args(arguments=arguments)
self.assertTrue(os.path.exists(
os.path.join(os.getcwd(),
'goodman_pipeline/testing/reference_files')))
os.path.join(os.path.dirname(__file__),
'../../testing/reference_files')))
self.assertTrue(os.path.isabs(args.reference_dir))

def test_reference_dir_os_error(self):
Expand Down Expand Up @@ -114,8 +114,11 @@ def test_get_args():
args = get_args(arguments)

assert isinstance(args, argparse.Namespace)
assert os.path.normpath(args.source) == os.getcwd()
assert os.path.normpath(args.destination) == os.getcwd()
assert args.pattern == 'test-pattern'
return args
assert args.output_prefix == 'w'
assert args.extraction_type == 'fractional'


class TestMainApp(TestCase):
Expand All @@ -141,7 +144,3 @@ def test___call___with_valid_arguments(self):
'--extraction', 'fractional']
args = get_args(arguments=arguments)
self.assertRaises(SystemExit, self.main_app, args)


if __name__ == '__main__':
test_get_args()
26 changes: 13 additions & 13 deletions goodman_pipeline/spectroscopy/tests/test_wavelength.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ class WavelengthCalibrationTests(TestCase):

def setUp(self):
self.file_list = []
argument_list = ['--data-path', os.getcwd(),
'--proc-path', os.getcwd(),
argument_list = ['--data-path', os.path.dirname(__file__),
'--proc-path', os.path.dirname(__file__),
'--search-pattern', 'cfzsto',
'--output-prefix', 'w',
'--extraction', 'fractional',
'--reference-files', 'data/ref_comp',
'--reference-files', os.path.join(os.path.dirname(__file__), '../../data/ref_comp'),
'--max-targets', '3',
]
arguments = get_args(argument_list)
Expand Down Expand Up @@ -155,7 +155,7 @@ def test___call___method_one_comparison_lamps(self):
json_output = self.wc(ccd=self.ccd,
comp_list=[self.lamp],
save_data_to='',
reference_data='goodman_pipeline/data/ref_comp',
reference_data=os.path.join(os.path.dirname(__file__), '../../data/ref_comp'),
json_output=True)

self.assertEqual(json_output['error'], 'Unable to obtain wavelength solution')
Expand All @@ -170,19 +170,19 @@ def test___call___method_no_match_found(self):
self.ccd,
[self.lamp],
'',
'goodman_pipeline/data/ref_comp')
os.path.join(os.path.dirname(__file__), '../../data/ref_comp'))

def test___call___method_one_solution(self):
file_path = os.path.join(os.getcwd(),
'goodman_pipeline/data/ref_comp',
file_path = os.path.join(os.path.dirname(__file__),
'../../data/ref_comp',
'goodman_comp_1200M2_FeHeAr.fits')
ref_lamp = CCDData.read(file_path, unit='adu')
lamp_ccd = write_fits(ref_lamp, os.path.join(os.getcwd(), 'test_comparison_lamp.fits'), )
self.file_list.append('test_comparison_lamp.fits')
json_output = self.wc(ccd=self.ccd,
comp_list=[lamp_ccd],
save_data_to='',
reference_data='goodman_pipeline/data/ref_comp',
reference_data=os.path.join(os.path.dirname(__file__), '../../data/ref_comp'),
json_output=True)
# print(json.dumps(json_output, indent=4))
self.assertEqual(len(json_output['wavelength_solution']), 1)
Expand All @@ -191,11 +191,11 @@ def test___call___method_one_solution(self):
self.file_list.append(_solution['reference_lamp'])

def test___call___method_two_solution(self):
file_path_1 = os.path.join(os.getcwd(),
'goodman_pipeline/data/ref_comp',
file_path_1 = os.path.join(os.path.dirname(__file__),
'../../data/ref_comp',
'goodman_comp_1200M2_FeHeAr.fits')
file_path_2 = os.path.join(os.getcwd(),
'goodman_pipeline/data/ref_comp',
file_path_2 = os.path.join(os.path.dirname(__file__),
'../../data/ref_comp',
'goodman_comp_1200M2_CuHeAr.fits')
ref_lamp_1 = CCDData.read(file_path_1, unit='adu')
ref_lamp_2 = CCDData.read(file_path_2, unit='adu')
Expand All @@ -207,7 +207,7 @@ def test___call___method_two_solution(self):
json_output = self.wc(ccd=self.ccd,
comp_list=[lamp_ccd_1, lamp_ccd_2],
save_data_to='',
reference_data='goodman_pipeline/data/ref_comp',
reference_data=os.path.join(os.path.dirname(__file__), '../../data/ref_comp'),
json_output=True)
# print(json.dumps(json_output, indent=4))
self.assertEqual(len(json_output['wavelength_solution']), 2)
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ dependencies = [
"Source" = "https://github.com/soar-telescope/goodman_pipeline"

[project.scripts]
redccd = "goodman_pipeline.scripts.redccd"
redspec = "goodman_pipeline.scripts.redspec"
redccd = "goodman_pipeline.scripts.redccd:__main__"
redspec = "goodman_pipeline.scripts.redspec:__main__"


[tool.setuptools]
Expand Down
25 changes: 25 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[tox]
envlist =
py{38, 39, 310, 311, 312}-test{,-cov}

isolated_build = true

[testenv]
setenv =
MPLBACKEND=agg
allowlist_externals = *

passenv = HOME,WINDIR,LC_ALL,LC_CTYPE,CC,CI

changedir = .tmp/{envname}

description =
run tests
cov: also test coverage

deps =
cov: pytest-cov

commands =
pytest '{toxinidir}/goodman_pipeline' {posargs}
cov: pytest --cov goodman_pipeline --cov-config='{toxinidir}/setup.cfg' {posargs}

0 comments on commit cd21d15

Please sign in to comment.