Skip to content

Commit a738463

Browse files
committed
Test update
1 parent 0ff25df commit a738463

File tree

3 files changed

+51
-6
lines changed

3 files changed

+51
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1010

1111
### Fixed
1212
- Bug with handling marker vs. locus identifiers when running `mhpl8r seq` (#190).
13+
- Bug with writing output to terminal for some commands (#191).
1314

1415

1516
## [0.8.4] 2024-09-16

microhapulator/cli/sim.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ def main(args):
5959
profile = mhapi.sim(frequencies, seed=args.seed)
6060
with mhopen(args.out, "w") as fh:
6161
profile.dump(fh)
62-
message = "profile JSON written to {:s}".format(fh.name)
63-
print("[MicroHapulator::sim]", message, file=sys.stderr)
62+
if hasattr(fh, "name"):
63+
message = "profile JSON written to {:s}".format(fh.name)
64+
print("[MicroHapulator::sim]", message, file=sys.stderr)
6465
if args.haplo_seq:
6566
index = MicrohapIndex.from_files(args.markers, fasta_path=args.sequences)
6667
index.validate()

microhapulator/tests/test_cli.py

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,59 @@
1111
# -------------------------------------------------------------------------------------------------
1212
# -----------------------------------------------------------------------------
1313

14-
import microhapulator
14+
from microhapulator import open as mhopen
15+
from microhapulator.cli import main
1516
from microhapulator.tests import data_file
1617
import pytest
1718

1819

1920
def test_microhapulator_open():
2021
thefile = data_file("refr/three-loci-refr.fasta")
21-
with microhapulator.open(thefile, "r") as filehandle:
22+
with mhopen(thefile, "r") as filehandle:
2223
filecontents = filehandle.read()
2324
assert len(filecontents.strip().split("\n")) == 6
24-
with pytest.raises(ValueError, match=r'invalid mode "p"') as ve:
25-
with microhapulator.open(thefile, "p") as filehandle:
25+
with pytest.raises(ValueError, match=r'invalid mode "p"'):
26+
with mhopen(thefile, "p") as filehandle:
2627
pass
28+
29+
30+
# These parameters and the following two test functions are mostly just smoke tests to make sure
31+
# the code doesn't go up in flames when data is written to stdout.
32+
# @pytest.fixture(params=[
33+
# ("diff", [data_file("prof/euramer-sim-gt.json"), data_file("prof/euramer-inf-gt.json")]),
34+
# ("dist", [data_file("prof/euramer-sim-gt.json"), data_file("prof/euramer-inf-gt.json")]),
35+
# ("sim", [data_file("pashtun-sim/tiny-panel-multidef-freq.tsv")]),
36+
# ("unite", [data_file("prof/swedish-mom.json"), data_file("prof/swedish-dad.json")]),
37+
# ])
38+
# def stdout_regress_param(request):
39+
# return request.param
40+
#
41+
#
42+
# def test_regression_stdout(stdout_regress_param, capsys, tmp_path):
43+
# command, infiles = stdout_regress_param
44+
# main([command, *infiles, "-o", outfile])
45+
# terminal = capsys.readouterr()
46+
# assert terminal.out == ""
47+
# main([command, *infiles])
48+
# assert terminal.out != ""
49+
50+
51+
@pytest.mark.parametrize(
52+
"command, infiles",
53+
[
54+
("diff", [data_file("prof/euramer-sim-gt.json"), data_file("prof/euramer-inf-gt.json")]),
55+
("dist", [data_file("prof/euramer-sim-gt.json"), data_file("prof/euramer-inf-gt.json")]),
56+
("sim", [data_file("freq/korea-5loc-freq.tsv")]),
57+
("unite", [data_file("prof/swedish-mom.json"), data_file("prof/swedish-dad.json")]),
58+
],
59+
)
60+
def test_regression_output_file(command, infiles, capsys, tmp_path):
61+
# This is mostly just a smoke test to make sure the code doesn't go up in flames when data is
62+
# written to stdout.
63+
outfile = str(tmp_path / "output.data")
64+
main([command, *infiles, "-o", outfile])
65+
terminal = capsys.readouterr()
66+
assert terminal.out == ""
67+
main([command, *infiles])
68+
terminal = capsys.readouterr()
69+
assert terminal.out != ""

0 commit comments

Comments
 (0)