Skip to content

Commit

Permalink
Fix breaking tests from context manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon committed Feb 3, 2025
1 parent 5d4af86 commit 1f2af63
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
12 changes: 6 additions & 6 deletions datalab/datalab_session/tests/test_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ def test_operate(self, mock_create_jpgs, mock_save_fits_and_thumbnails, mock_get
# return the test fits paths in order of the input_files instead of aws fetch
mock_get_fits.side_effect = [self.test_fits_1_path, self.test_fits_2_path]
# save temp output to a known path so we can test it
mock_named_tempfile.return_value.name = self.temp_median_path
mock_named_tempfile.return_value.__enter__.return_value.name = self.temp_median_path
# avoids overwriting our output
mock_create_jpgs.return_value = ('test_path', 'test_path')
mock_create_jpgs.return_value.__enter__.return_value = ('test_path', 'test_path')
# don't save to s3
mock_save_fits_and_thumbnails.return_value = self.temp_median_path

Expand Down Expand Up @@ -230,9 +230,9 @@ def test_operate(self, mock_get_fits, mock_named_tempfile, mock_create_jpgs, moc
# return the test fits paths in order of the input_files instead of aws fetch
mock_get_fits.side_effect = [self.test_red_path, self.test_green_path, self.test_blue_path]
# save temp output to a known path so we can test
mock_named_tempfile.return_value.name = self.temp_rgb_path
mock_named_tempfile.return_value.__enter__.return_value.name = self.temp_rgb_path
# avoids overwriting our output
mock_create_jpgs.return_value = ('test_path', 'test_path')
mock_create_jpgs.return_value.__enter__.return_value = ('test_path', 'test_path')
# don't save to s3
mock_save_fits_and_thumbnails.return_value = self.temp_rgb_path

Expand Down Expand Up @@ -300,9 +300,9 @@ def test_operate(self, mock_create_jpgs, mock_save_fits_and_thumbnails, mock_get
mock_get_fits.side_effect = [self.test_fits_1_path, self.test_fits_2_path,
self.temp_fits_1_negative_path, self.temp_fits_2_negative_path]
# save temp output to a known path so we can test it
mock_named_tempfile.return_value.name = self.temp_stacked_path
mock_named_tempfile.return_value.__enter__.return_value.name = self.temp_stacked_path
# avoids overwriting our output
mock_create_jpgs.return_value = ('test_path', 'test_path')
mock_create_jpgs.return_value.__enter__.return_value = ('test_path', 'test_path')
# don't save to s3
mock_save_fits_and_thumbnails.return_value = self.temp_stacked_path

Expand Down
7 changes: 5 additions & 2 deletions datalab/datalab_session/utils/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,11 @@ def create_jpgs(cache_key, fits_paths: str, color=False, zmin=None, zmax=None) -
try:
yield large_jpg_path, thumbnail_jpg_path
finally:
os.remove(large_jpg_path)
os.remove(thumbnail_jpg_path)
try:
os.remove(large_jpg_path)
os.remove(thumbnail_jpg_path)
except FileNotFoundError:
pass

def crop_arrays(array_list: list):
"""
Expand Down

0 comments on commit 1f2af63

Please sign in to comment.