Skip to content
Snippets Groups Projects

remove system exits from datafetcher tests

Merged Janet Goldstein requested to merge WS-179-4-remove-sys-exits into main
All threads resolved!
2 files
+ 154
1
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -4,45 +4,25 @@
""" Various conveniences for use and re-use in test cases """
import json
import logging
import os
import sys
import tempfile
from pathlib import Path
sys.path.insert(0, str(Path(".").absolute()))
sys.path.insert(0, str(Path("..").absolute()))
# TODO: Some Fine Day: this duplicates same function in package tester.
# CAVEAT PROGRAMMOR: attempts to centralize it have resulted in tears.
def get_project_root() -> Path:
"""
Get the root of this project.
:return:
"""
my_path = Path(__file__)
path = my_path
while not path.name.endswith("workspaces") and not path.name.endswith("packages"):
path = path.parent
return path
from typing import List, Dict
import pytest
from pycapo import CapoConfig
# pylint: disable=C0115, C0116, C0200, R0902, R0903, R0914, R1721, W0212, W0613, W0621, W0703, W1203
sys.path.insert(0, str(get_project_root()))
from shared.workspaces.test.test_data.utilities import (
# pylint: disable=C0115, C0116, C0200, R0902, R0903, R0914, R1721, W0212, W0613,
# pylint: disable=W0621, W0703, W1203
from .df_testdata_utils import (
get_locations_report,
get_test_data_dir,
)
from datafetcher.datafetcher import DataFetcher
from datafetcher.return_codes import ReturnCode
from datafetcher.errors import MissingSettingsException, NoProfileException
from datafetcher.locations_report import LocationsReport
from datafetcher.utilities import (
@@ -54,8 +34,9 @@ from datafetcher.utilities import (
)
TEST_PROFILE = "docker"
MISSING_SETTING = ReturnCode.MISSING_SETTING.value["code"]
MISSING_PROFILE = ReturnCode.MISSING_PROFILE.value["code"]
# set this to False when debugging one or more tests
# so as not to have to sit thru every test;
# comment out the target test(s)' "@pytest.skip"
RUN_ALL = True
LOCATION_REPORTS = {
@@ -259,7 +240,7 @@ def make_tempdir() -> Path:
umask = os.umask(0o000)
top_level = tempfile.mkdtemp(prefix="datafetcher_test_", dir="/var/tmp")
os.umask(umask)
yield top_level
return top_level
@pytest.fixture(scope="session")
@@ -322,41 +303,27 @@ def launch_datafetcher(args: list, df_capo_settings: dict) -> int:
"""
if args is None or len(args) == 0:
return MISSING_SETTING
try:
namespace = evaluate_args_and_capo(args, df_capo_settings)
fetcher = DataFetcher(namespace, df_capo_settings)
return fetcher.run()
except SystemExit as exc:
if hasattr(exc, "value"):
return exc.value.code if hasattr(exc.value, "code") else exc.value
if hasattr(exc, "code"):
return exc.code
raise MissingSettingsException
raise
except (KeyError, NoProfileException) as exc:
logging.error(f"{exc}")
return MISSING_PROFILE
except Exception as exc:
pytest.fail(f"{exc}")
namespace = evaluate_args_and_capo(args, df_capo_settings)
datafetcher = DataFetcher(namespace, df_capo_settings)
datafetcher.run()
def evaluate_args_and_capo(args: list, capo_settings: dict):
def evaluate_args_and_capo(args: List[str], capo_settings: Dict[str, str]):
if args is None or len(args) == 0:
sys.exit(MISSING_SETTING)
raise MissingSettingsException
profile = get_profile_from_args(args)
if profile is None:
profile = capo_settings["profile"]
if profile is None:
sys.exit(MISSING_PROFILE)
raise NoProfileException
else:
args["profile"] = profile
namespace = get_arg_parser().parse_args(args)
return namespace
return get_arg_parser().parse_args(args)
def get_profile_from_args(args: list) -> str:
Loading