From ad8cbce8f326a1bc4e56ccf6cae568a2f907df9a Mon Sep 17 00:00:00 2001 From: Janet Goldstein <jgoldste@nrao.edu> Date: Wed, 4 Aug 2021 19:29:57 +0000 Subject: [PATCH] WS-601: fixing potential sites of UnboundLocalError --- .../ingest_envoy/ingest_envoy/ingestion_manifest.py | 7 +++++-- .../ingest_envoy/std_img_manifest_utils.py | 11 ++++++----- .../ingest_envoy/test/test_evla_cal_manifest.py | 5 ++--- .../pexable/ingest_envoy/test/test_image_manifest.py | 8 +++++--- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/apps/cli/executables/pexable/ingest_envoy/ingest_envoy/ingestion_manifest.py b/apps/cli/executables/pexable/ingest_envoy/ingest_envoy/ingestion_manifest.py index 04e49a137..e9e49641a 100644 --- a/apps/cli/executables/pexable/ingest_envoy/ingest_envoy/ingestion_manifest.py +++ b/apps/cli/executables/pexable/ingest_envoy/ingest_envoy/ingestion_manifest.py @@ -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: """ diff --git a/apps/cli/executables/pexable/ingest_envoy/ingest_envoy/std_img_manifest_utils.py b/apps/cli/executables/pexable/ingest_envoy/ingest_envoy/std_img_manifest_utils.py index aff7a3e07..8851d1573 100644 --- a/apps/cli/executables/pexable/ingest_envoy/ingest_envoy/std_img_manifest_utils.py +++ b/apps/cli/executables/pexable/ingest_envoy/ingest_envoy/std_img_manifest_utils.py @@ -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 ) diff --git a/apps/cli/executables/pexable/ingest_envoy/test/test_evla_cal_manifest.py b/apps/cli/executables/pexable/ingest_envoy/test/test_evla_cal_manifest.py index b1e2ede31..b928425e1 100644 --- a/apps/cli/executables/pexable/ingest_envoy/test/test_evla_cal_manifest.py +++ b/apps/cli/executables/pexable/ingest_envoy/test/test_evla_cal_manifest.py @@ -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 diff --git a/apps/cli/executables/pexable/ingest_envoy/test/test_image_manifest.py b/apps/cli/executables/pexable/ingest_envoy/test/test_image_manifest.py index 4fa5d1e58..2b500b50f 100644 --- a/apps/cli/executables/pexable/ingest_envoy/test/test_image_manifest.py +++ b/apps/cli/executables/pexable/ingest_envoy/test/test_image_manifest.py @@ -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( -- GitLab