Skip to content

Commit

Permalink
tests all functioning, now to fix imports and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
metazool committed Oct 4, 2024
1 parent bc1829a commit da4b4e2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/cyto_ml/pipeline/pipeline_decollage.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def requires(self):

def output(self):
date = datetime.today().date()
return luigi.LocalTarget(f'./decollage_complete_{date}.txt')
return luigi.LocalTarget(f'{self.directory}/decollage_complete_{date}.txt')

def run(self):
metadata = pd.read_csv(self.input()[0].path)
Expand Down Expand Up @@ -166,7 +166,7 @@ def requires(self):

def output(self):
date = datetime.today().date()
return luigi.LocalTarget(f'./s3_upload_complete_{date}.txt')
return luigi.LocalTarget(f'{self.directory}/s3_upload_complete_{date}.txt')

def run(self):
# Collect the list of decollaged image files from the output of DecollageImages
Expand Down
23 changes: 16 additions & 7 deletions tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,30 @@ def test_decollage_images(temp_dir):
output_image = os.path.join(temp_dir, "test_experiment_0.tif")
assert os.path.exists(output_image), "Decollaged image should be created."


class MockTask(luigi.Task):
directory = luigi.Parameter()
check_unfulfilled_deps = False
def output(self) -> luigi.Target:
# "The output() method returns one or more Target objects.""
return luigi.LocalTarget(f'{self.directory}/out.txt')

def test_upload_to_api(temp_dir, mocker):
# Mock the DecollageImages output using pytest-mock
mock_output = mocker.patch('pipeline.pipeline_decollage.DecollageImages.output')
mock_output.return_value = [os.path.join(temp_dir, "test_experiment_0.tif")]

# Write a tmp file to serve as our upstream task's output
with open(os.path.join(temp_dir, 'out.txt'), 'w') as out:
out.write("blah")
# The task `requires` DecollageImages, but that requires other tasks, which run first
# Rather than mock its output, or the whole chain, require a mock task that replaces it
mock_output = mocker.patch(f'cyto_ml.pipeline.pipeline_decollage.UploadDecollagedImagesToS3.requires')
mock_output.return_value = MockTask(directory=temp_dir)

# Mock the requests.post to simulate the API response
mock_post = mocker.patch('pipeline.pipeline_decollage.requests.post')
mock_post = mocker.patch('cyto_ml.pipeline.pipeline_decollage.requests.post')
mock_post.return_value.status_code = 200

task = UploadDecollagedImagesToS3(
directory=str(temp_dir),
output_directory=str(temp_dir),
s3_bucket="mock_bucket",
s3_folder="mock_folder"
)

luigi.build([task], local_scheduler=True)
Expand Down

0 comments on commit da4b4e2

Please sign in to comment.