Skip to content

Commit

Permalink
test: use shell_run() to simplify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kelly-sovacool committed Aug 13, 2024
1 parent 44ff43b commit af637a7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
21 changes: 7 additions & 14 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import tempfile
from xavier.src.xavier.__main__ import main
from ccbr_tools.pipeline.util import get_hpcname
from ccbr_tools.shell import exec_in_context, shell_run

xavier_run = (
"xavier run "
Expand All @@ -17,11 +18,8 @@ def run_in_temp(command_str):
with tempfile.TemporaryDirectory() as tmp_dir:
outdir = os.path.join(tmp_dir, "testout")
run_command = f"{command_str} --output {outdir}"
output = subprocess.run(
output = shell_run(
f"{run_command} --runmode init && {run_command} --runmode dryrun",
capture_output=True,
shell=True,
text=True,
)
if os.path.exists(os.path.join(outdir, "config.json")):
with open(os.path.join(outdir, "config.json"), "r") as infile:
Expand All @@ -32,12 +30,7 @@ def run_in_temp(command_str):


def test_help():
assert (
"XAVIER"
in subprocess.run(
"./bin/xavier --help", capture_output=True, shell=True, text=True
).stdout
)
assert "XAVIER" in shell_run("./bin/xavier --help")


def test_dryrun_targets():
Expand All @@ -53,13 +46,13 @@ def test_dryrun_targets():
assert all(
[
"This was a dry-run (flag -n). The order of jobs does not reflect the order of execution."
in output_human.stdout,
in output_human,
"This was a dry-run (flag -n). The order of jobs does not reflect the order of execution."
in output_mouse.stdout,
in output_mouse,
"This was a dry-run (flag -n). The order of jobs does not reflect the order of execution."
in output_custom.stdout,
in output_custom,
"error: Path 'not/a/file.txt' does not exists! Failed to provide valid input."
in output_invalid.stderr,
in output_invalid,
config_human["input_params"]["EXOME_TARGETS"].endswith(
"resources/Agilent_SSv7_allExons_hg38.bed"
),
Expand Down
2 changes: 1 addition & 1 deletion tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_dryrun():
with tempfile.TemporaryDirectory() as tmp_dir:
run_args = argparse.Namespace(
runmode="init",
input=list(glob.glob(xavier_base(".tests/*.fastq.gz"))),
input=list(glob.glob(f"{xavier_base('.tests')}/*.fastq.gz")),
output=tmp_dir,
genome="hg38",
targets=xavier_base("resources/Agilent_SSv7_allExons_hg38.bed"),
Expand Down

0 comments on commit af637a7

Please sign in to comment.