Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove manual path construction #438

Merged
merged 3 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions tests/test_configuration.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from astropy.io import fits
from astropy.table import Table
import os
import tempfile
import unittest
from pathlib import Path
Expand Down Expand Up @@ -122,7 +123,7 @@ def test_save_and_load_yaml(self):
config.set("mask_grow", 5)

with tempfile.TemporaryDirectory() as dir_name:
file_path = f"{dir_name}/tmp_config_data.yaml"
file_path = os.path.join(dir_name, "tmp_config_data.yaml")
self.assertFalse(Path(file_path).is_file())

# Unable to load non-existent file.
Expand Down Expand Up @@ -155,7 +156,7 @@ def test_save_and_load_fits(self):
config.set("mask_bits_dict", {"bit1": 1, "bit2": 2})

with tempfile.TemporaryDirectory() as dir_name:
file_path = f"{dir_name}/test.fits"
file_path = os.path.join(dir_name, "test.fits")
self.assertFalse(Path(file_path).is_file())

# Unable to load non-existent file.
Expand Down
3 changes: 2 additions & 1 deletion tests/test_end_to_end.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import math
import numpy as np
import os
import tempfile
import unittest

Expand Down Expand Up @@ -116,7 +117,7 @@ def test_e2e_work_unit(self):
work = WorkUnit(im_stack=ds.stack, config=config)

with tempfile.TemporaryDirectory() as dir_name:
file_path = f"{dir_name}/test_workunit.fits"
file_path = os.path.join(dir_name, "test_workunit.fits")
work.to_fits(file_path)

rs = SearchRunner()
Expand Down
3 changes: 2 additions & 1 deletion tests/test_fake_data_creator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import tempfile
import unittest

Expand Down Expand Up @@ -90,7 +91,7 @@ def test_save_work_unit(self):
ds = FakeDataSet(15, 10, num_images)

with tempfile.TemporaryDirectory() as dir_name:
file_name = f"{dir_name}/fake_work_unit.fits"
file_name = os.path.join(dir_name, "fake_work_unit.fits")
ds.save_fake_data_to_work_unit(file_name)
self.assertTrue(Path(file_name).exists())

Expand Down
6 changes: 3 additions & 3 deletions tests/test_file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_visit_from_file_name(self):
def test_save_load_csv(self):
data = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]
with tempfile.TemporaryDirectory() as dir_name:
file_name = f"{dir_name}/data1.dat"
file_name = os.path.join(dir_name, "data1.dat")

# Check that there is nothing to load before saving the file.
# By default FileUtils should raise a FileNotFoundError.
Expand Down Expand Up @@ -80,7 +80,7 @@ def test_load_times(self):
def test_save_times(self):
mapping = {"0001": 100.0, "0002": 110.0, "0003": 111.0}
with tempfile.TemporaryDirectory() as dir_name:
file_name = f"{dir_name}/times.dat"
file_name = os.path.join(dir_name, "times.dat")
FileUtils.save_time_dictionary(file_name, mapping)
self.assertTrue(Path(file_name).is_file())

Expand Down Expand Up @@ -145,7 +145,7 @@ def test_save_and_load_single_result(self):
trj.vy = 4.0

with tempfile.TemporaryDirectory() as dir_name:
filename = f"{dir_name}/results_tmp.txt"
filename = os.path.join(dir_name, "results_tmp.txt")
FileUtils.save_results_file(filename, [trj])

loaded_trjs = FileUtils.load_results_file_as_trajectories(filename)
Expand Down
13 changes: 4 additions & 9 deletions tests/test_raw_image.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import numpy as np
import os
import tempfile
import unittest

import numpy as np
import timeit
from kbmod.search import (
HAS_GPU,
KB_NO_DATA,
Expand Down Expand Up @@ -378,9 +378,7 @@ def test_read_write_file(self):
"""Test file writes and reads correctly."""
img = RawImage(self.array, 10.0)
with tempfile.TemporaryDirectory() as dir_name:
file_name = "tmp_RawImage"
full_path = "%s/%s.fits" % (dir_name, file_name)

full_path = os.path.join(dir_name, "tmp_RawImage.fits")
img.save_fits(full_path)

# Reload the file.
Expand All @@ -396,10 +394,7 @@ def test_stack_file(self):
"""Test multi-extension FITS files write and read correctly."""
img = RawImage(self.array, 10.0)
with tempfile.TemporaryDirectory() as dir_name:
file_name = "tmp_RawImage"
full_path = "%s/%s.fits" % (dir_name, file_name)

# Save the image and create a file.
full_path = os.path.join(dir_name, "tmp_RawImage.fits")
img.save_fits(full_path)

# Add 4 more layers at different times.
Expand Down