Skip to content
Snippets Groups Projects
Commit ad8cbce8 authored by Janet Goldstein's avatar Janet Goldstein
Browse files

WS-601: fixing potential sites of UnboundLocalError

parent c28c09c5
No related branches found
No related tags found
1 merge request!397WS-601: fixing potential sites of UnboundLocalError
Pipeline #2408 passed
......@@ -69,7 +69,6 @@ class ManifestIF(ManifestComponentIF):
self.telescope = telescope
self.parameters = self.build_ingest_parameters(additional_metadata)
self.files_found = [file for file in self.staging_source_dir.iterdir()]
def build_ingest_parameters(self, additional_metadata: AbstractTextFile):
......@@ -270,10 +269,14 @@ class IngestionManifestBuilder:
# find science product (we expect just one for this SP type)
tars_found = find_output_tars(self.files_found, self.staging_source_dir)
sci_prod = None
for file in tars_found:
sci_prod = OutputScienceProduct(type=self.sp_type, filename=file.name)
break
return OutputGroup(science_products=[sci_prod])
if sci_prod:
return OutputGroup(science_products=[sci_prod])
def _build_imaging_output_group(self) -> OutputGroup:
"""
......
......@@ -10,6 +10,8 @@ from ingest_envoy.manifest_components import (
)
from ingest_envoy.utilities import AncillaryProductType
FITS = "fits"
RMS = "rms"
# pylint: disable=R1721
class ImageIngestionProductsFinder:
......@@ -35,12 +37,10 @@ class ImageIngestionProductsFinder:
:return:
"""
sp_image_file = [
file
for file in self.files_found
if file.name.endswith(".fits") and "rms" not in file.name
file for file in self.files_found if file.name.endswith(FITS) and RMS not in file.name
][0]
image_files = [
file for file in self.files_found if ("rms" in file.name or file.name.endswith(".png"))
file for file in self.files_found if (RMS in file.name or file.name.endswith(".png"))
]
sp_aps = []
......@@ -79,6 +79,7 @@ class ImageIngestionProductsFinder:
ancillary_files = [Path(ap.filename) for ap in ancillary_products]
# find the pipeline artifacts tar
pipeline_artifacts_tar = None
for file in self.files_found:
if file not in ancillary_files and self._is_ancillary_image_product(file):
pipeline_artifacts_tar = file
......@@ -102,7 +103,7 @@ class ImageIngestionProductsFinder:
if "image" in file.name:
if file.name.endswith(".png"):
return AncillaryProduct(type=AncillaryProductType.THUMBNAIL_IMG, filename=filename)
if file.name.endswith(".fits") and "rms" in file.name:
if file.name.endswith(FITS) and RMS in file.name:
return AncillaryProduct(
type=AncillaryProductType.QUICKLOOK_RMS_IMAGE, filename=filename
)
......
......@@ -9,7 +9,6 @@ from pathlib import Path
# pylint: disable=E0401, E0402, R1721, W0621
from unittest.mock import patch
import pytest
import tarfile
from ingest_envoy.ingestion_manifest import (
......@@ -75,7 +74,7 @@ def test_filters_cal_input_files(ingest_path: Path):
assert manifest.locator == locator
params = manifest.parameters
assert params.reingest == False and params.ngas_ingest == True
assert params.reingest is False and params.ngas_ingest is True
assert not hasattr(params, "calibrate")
input_group = manifest.input_group
......@@ -190,7 +189,7 @@ def test_ancillary_product_well_formed():
:return:
"""
ap1 = AncillaryProduct(type=AncillaryProductType.LOG_TYPE, filename="without_feathers.tar")
expected = {"type": AncillaryProductType.LOG_TYPE.value, "filename": "without_feathers.tar"}
expected = {"type": AncillaryProductType.LOG_TYPE.value, "filename": ap1.filename}
actual = ap1.to_json()
assert actual == expected
......
......@@ -34,6 +34,8 @@ from ingest_envoy.manifest_components import (
TARFILE_EXT,
)
IMG_MANIFEST_EXAMPLE = "image_metadata_2021_05_21_T10_17_19.180.json"
def test_parameters_json_well_formed(ingest_path: Path):
"""
......@@ -156,7 +158,7 @@ def test_ingestion_artifacts_tar_correct(ingest_path: Path):
populate_fake_image_ingest_path(ingest_path)
locator = "uid://evla/calibration/3dfa528b-9870-46c9-a200-131dbac701cc"
addl_md = AbstractTextFile(filename="image_metadata_2021_05_21_T10_17_19.180.json", content="")
addl_md = AbstractTextFile(filename=IMG_MANIFEST_EXAMPLE, content="")
# manifest maker, manifest maker, make me a manifest
IngestionManifestBuilder(
......@@ -201,7 +203,7 @@ def test_creates_expected_manifest(ingest_path: Path):
populate_fake_image_ingest_path(ingest_path)
locator = "uid://evla/calibration/3dfa528b-9870-46c9-a200-131dbac701cc"
addl_md_file = ingest_path / "image_metadata_2021_05_21_T10_17_19.180.json"
addl_md_file = ingest_path / IMG_MANIFEST_EXAMPLE
addl_md = AbstractTextFile(filename=str(addl_md_file), content="")
# build us a manifest in the ingest_path using this locator and additional metadata
......@@ -346,7 +348,7 @@ def manifest_parameters(ingest_path: Path) -> ManifestParameters:
:return: the manifest parameters we're expecting
"""
addl_md_path = ingest_path / "image_metadata_2021_05_21_T10_17_19.180.json"
addl_md_path = ingest_path / IMG_MANIFEST_EXAMPLE
addl_md = AbstractTextFile(filename=str(addl_md_path), content="")
params = ManifestParameters(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment