|
11 | 11 | # ------------------------------------------------------------------------------------------------- |
12 | 12 | # ----------------------------------------------------------------------------- |
13 | 13 |
|
14 | | -import microhapulator |
| 14 | +from microhapulator import open as mhopen |
| 15 | +from microhapulator.cli import main |
15 | 16 | from microhapulator.tests import data_file |
16 | 17 | import pytest |
17 | 18 |
|
18 | 19 |
|
19 | 20 | def test_microhapulator_open(): |
20 | 21 | thefile = data_file("refr/three-loci-refr.fasta") |
21 | | - with microhapulator.open(thefile, "r") as filehandle: |
| 22 | + with mhopen(thefile, "r") as filehandle: |
22 | 23 | filecontents = filehandle.read() |
23 | 24 | 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: |
26 | 27 | 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