Skip to content

Commit

Permalink
fix tests for create_output change, overwrite temp files
Browse files Browse the repository at this point in the history
  • Loading branch information
LTDakin committed Oct 2, 2024
1 parent 26ed7f5 commit e0411d1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions datalab/datalab_session/analysis/get_tif.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datalab.datalab_session.file_utils import create_tif, get_fits
from datalab.datalab_session.s3_utils import key_exists, add_file_to_bucket, get_s3_url
from datalab.datalab_session.file_utils import create_tif
from datalab.datalab_session.s3_utils import key_exists, add_file_to_bucket, get_s3_url, get_fits

def get_tif(input: dict):
"""
Expand Down
3 changes: 2 additions & 1 deletion datalab/datalab_session/data_operations/rgb_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

from datalab.datalab_session.data_operations.data_operation import BaseDataOperation
from datalab.datalab_session.exceptions import ClientAlertException
from datalab.datalab_session.file_utils import create_output, get_fits, crop_arrays, create_jpgs
from datalab.datalab_session.file_utils import create_output, crop_arrays, create_jpgs
from datalab.datalab_session.s3_utils import get_fits

log = logging.getLogger()
log.setLevel(logging.INFO)
Expand Down
2 changes: 1 addition & 1 deletion datalab/datalab_session/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def create_fits(key: str, image_arr: np.ndarray) -> str:

hdu_list = fits.HDUList([primary_hdu, image_hdu])
fits_path = tempfile.NamedTemporaryFile(suffix=f'{key}.fits').name
hdu_list.writeto(fits_path)
hdu_list.writeto(fits_path, overwrite=True)

return fits_path

Expand Down
16 changes: 8 additions & 8 deletions datalab/datalab_session/tests/test_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def wizard_description():
return wizard_description

def operate(self):
self.set_output({'output_files': []})
self.set_output([])


class TestDataOperation(FileExtendedTestCase):
Expand Down Expand Up @@ -147,7 +147,7 @@ def test_generate_cache_key(self):
self.assertEqual(self.data_operation.generate_cache_key(), pregenerated_cache_key)

def test_set_get_output(self):
self.data_operation.set_output({'output_files': []})
self.data_operation.set_output([])
self.assertEqual(self.data_operation.get_operation_progress(), 1.0)
self.assertEqual(self.data_operation.get_status(), 'COMPLETED')
self.assertEqual(self.data_operation.get_output(), {'output_files': []})
Expand All @@ -170,8 +170,8 @@ def tearDown(self):

@mock.patch('datalab.datalab_session.file_utils.tempfile.NamedTemporaryFile')
@mock.patch('datalab.datalab_session.data_operations.data_operation.get_fits')
@mock.patch('datalab.datalab_session.data_operations.median.save_fits_and_thumbnails')
@mock.patch('datalab.datalab_session.data_operations.median.create_jpgs')
@mock.patch('datalab.datalab_session.file_utils.save_fits_and_thumbnails')
@mock.patch('datalab.datalab_session.file_utils.create_jpgs')
def test_operate(self, mock_create_jpgs, mock_save_fits_and_thumbnails, mock_get_fits, mock_named_tempfile):

# return the test fits paths in order of the input_files instead of aws fetch
Expand Down Expand Up @@ -221,8 +221,8 @@ def tearDown(self):
self.clean_test_dir()
return super().tearDown()

@mock.patch('datalab.datalab_session.data_operations.rgb_stack.save_fits_and_thumbnails')
@mock.patch('datalab.datalab_session.data_operations.rgb_stack.create_jpgs')
@mock.patch('datalab.datalab_session.file_utils.save_fits_and_thumbnails')
@mock.patch('datalab.datalab_session.file_utils.create_jpgs')
@mock.patch('datalab.datalab_session.file_utils.tempfile.NamedTemporaryFile')
@mock.patch('datalab.datalab_session.data_operations.rgb_stack.get_fits')
def test_operate(self, mock_get_fits, mock_named_tempfile, mock_create_jpgs, mock_save_fits_and_thumbnails):
Expand Down Expand Up @@ -266,8 +266,8 @@ def tearDown(self):

@mock.patch('datalab.datalab_session.file_utils.tempfile.NamedTemporaryFile')
@mock.patch('datalab.datalab_session.data_operations.data_operation.get_fits')
@mock.patch('datalab.datalab_session.data_operations.stacking.save_fits_and_thumbnails')
@mock.patch('datalab.datalab_session.data_operations.stacking.create_jpgs')
@mock.patch('datalab.datalab_session.file_utils.save_fits_and_thumbnails')
@mock.patch('datalab.datalab_session.file_utils.create_jpgs')
def test_operate(self, mock_create_jpgs, mock_save_fits_and_thumbnails, mock_get_fits, mock_named_tempfile):

# Create a negative images using numpy
Expand Down

0 comments on commit e0411d1

Please sign in to comment.