Skip to content

Commit bf3b0e5

Browse files
Close loopholes in index command
1 parent 7b56d9e commit bf3b0e5

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

tests/test_cli.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,40 @@ def test_output(self, vcz_path, tmp_path):
136136
assert output.exists()
137137

138138

139+
class TestIndex:
140+
def test_stats(self, vcz_path):
141+
result = run_vcztools(f"index -s {vcz_path}")
142+
assert list(result.splitlines()) == ["19\t.\t2", "20\t.\t6", "X\t.\t1"]
143+
144+
def test_nrecords(self, vcz_path):
145+
result = run_vcztools(f"index -n {vcz_path}")
146+
assert list(result.splitlines()) == ["9"]
147+
148+
def test_stats_and_nrecords(self, vcz_path):
149+
runner = ct.CliRunner(mix_stderr=False)
150+
result = runner.invoke(
151+
cli.vcztools_main,
152+
f"index -ns {vcz_path}",
153+
catch_exceptions=False,
154+
)
155+
assert result.exit_code == 2
156+
assert len(result.stdout) == 0
157+
assert len(result.stderr) > 0
158+
assert "Expected only one of --stats or --nrecords options" in result.stderr
159+
160+
def test_no_stats_or_nrecords(self, vcz_path):
161+
runner = ct.CliRunner(mix_stderr=False)
162+
result = runner.invoke(
163+
cli.vcztools_main,
164+
f"index {vcz_path}",
165+
catch_exceptions=False,
166+
)
167+
assert result.exit_code == 2
168+
assert len(result.stdout) == 0
169+
assert len(result.stderr) > 0
170+
assert "Error: Building region indexes is not supported" in result.stderr
171+
172+
139173
def test_top_level():
140174
runner = ct.CliRunner(mix_stderr=False)
141175
result = runner.invoke(

vcztools/cli.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,14 @@ def list_commands(self, ctx):
6767
help="Print per contig stats.",
6868
)
6969
def index(path, nrecords, stats):
70+
if nrecords and stats:
71+
raise click.UsageError("Expected only one of --stats or --nrecords options")
7072
if nrecords:
7173
stats_module.nrecords(path, sys.stdout)
7274
elif stats:
7375
stats_module.stats(path, sys.stdout)
76+
else:
77+
raise click.UsageError("Building region indexes is not supported")
7478

7579

7680
@click.command

0 commit comments

Comments
 (0)