Skip to content

Commit

Permalink
Fix test by extracting arg parsing to separate cli module that doesn'…
Browse files Browse the repository at this point in the history
…t need to access seqrepo
  • Loading branch information
theferrit32 committed Apr 30, 2024
1 parent 42ce34c commit cead782
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
21 changes: 21 additions & 0 deletions clinvar_gk_pilot/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import argparse
from typing import List


def parse_args(args: List[str]) -> dict:
"""
Parse arguments and return as dict.
"""
parser = argparse.ArgumentParser()
parser.add_argument("--filename", required=True, help="Filename to read")
parser.add_argument(
"--parallelism",
type=int,
default=1,
help=(
"Number of worker threads. "
"Default 1, which still uses a separate process to run tasks. "
"Set to 0 to run in main thread."
),
)
return vars(parser.parse_args(args))
20 changes: 1 addition & 19 deletions clinvar_gk_pilot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from ga4gh.vrs.dataproxy import create_dataproxy
from ga4gh.vrs.extras.translator import AlleleTranslator, CnvTranslator

from clinvar_gk_pilot.cli import parse_args
from clinvar_gk_pilot.gcs import (
_local_file_path_for,
already_downloaded,
Expand Down Expand Up @@ -42,25 +43,6 @@
}


def parse_args(args: List[str]) -> dict:
"""
Parse arguments and return as dict.
"""
parser = argparse.ArgumentParser()
parser.add_argument("--filename", required=True, help="Filename to read")
parser.add_argument(
"--parallelism",
type=int,
default=1,
help=(
"Number of worker threads. "
"Default 1, which still uses a separate process to run tasks. "
"Set to 0 to run in main thread."
),
)
return vars(parser.parse_args(args))


def process_line(line: str) -> str:
"""
Takes a line of JSON, processes it, and returns the result as a JSON string.
Expand Down
5 changes: 3 additions & 2 deletions test/test_main.py → test/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from clinvar_gk_pilot.main import parse_args
from clinvar_gk_pilot.cli import parse_args


def test_parse_args():
argv = ["--filename", "test.txt"]
opts = parse_args(argv)
assert opts["filename"] == "test.txt"
assert len(opts) == 1
assert opts["parallelism"] == 1
assert len(opts) == 2

0 comments on commit cead782

Please sign in to comment.