From 53142269b4895be26952c09a2aa265b63ccd8476 Mon Sep 17 00:00:00 2001 From: Reid Hewitt Date: Wed, 24 Apr 2024 09:49:53 -0600 Subject: [PATCH] add arg parse function and test --- harvester/utils.py | 11 +++++++++++ tests/unit/utils/test_utils.py | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/harvester/utils.py b/harvester/utils.py index 4f230c1f..3e31bf7b 100644 --- a/harvester/utils.py +++ b/harvester/utils.py @@ -1,6 +1,7 @@ import hashlib import json import os +import argparse import boto3 import sansjson @@ -11,6 +12,16 @@ # ruff: noqa: F841 +def parse_args(args): + + parser = argparse.ArgumentParser( + prog="Harvest Runner", description="etl harvest sources" + ) + parser.add_argument("-j", "--jobid") + + return parser.parse_args(args) + + def convert_set_to_list(obj): if isinstance(obj, set): return list(obj) diff --git a/tests/unit/utils/test_utils.py b/tests/unit/utils/test_utils.py index 89fc438b..81ad049b 100644 --- a/tests/unit/utils/test_utils.py +++ b/tests/unit/utils/test_utils.py @@ -1,4 +1,5 @@ from harvester.ckan_utils import munge_tag, munge_title_to_name +from harvester.utils import parse_args import pytest # these tests are copied from @@ -44,3 +45,9 @@ def test_munge_title_to_name(self, original, expected): """Munge a list of names gives expected results.""" munge = munge_title_to_name(original) assert munge == expected + + +class TestGeneralUtils: + def test_args_parsing(self): + args = parse_args(["-j", "test-id"]) + assert args.jobid == "test-id"