Skip to content

Commit 83742ff

Browse files
MENGZHEGENGroedoejet
authored andcommitted
fix: add unit test for handling empty filelist
1 parent 189e338 commit 83742ff

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

everyvoice/tests/data/empty.psv

Whitespace-only changes.

everyvoice/tests/test_wizard.py

+22
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,28 @@ def test_dataset_subtour(self):
553553
self.assertEqual(len(symbol_set_step.state[SN.symbol_set_step.value]), 2)
554554
self.assertIn("t͡s", symbol_set_step.state[SN.symbol_set_step.value]["phones"])
555555

556+
def test_empty_filelist(self):
557+
tour = Tour(
558+
name="empty filelist",
559+
steps=[
560+
dataset.FilelistStep(),
561+
dataset.FilelistFormatStep(),
562+
],
563+
)
564+
filelist = str(self.data_dir / "empty.psv")
565+
566+
filelist_step = tour.steps[0]
567+
with monkeypatch(filelist_step, "prompt", Say(filelist)):
568+
filelist_step.run()
569+
570+
format_step = tour.steps[1]
571+
with self.assertRaises(SystemExit) as cm:
572+
with patch_menu_prompt(1) as stdout:
573+
format_step.run()
574+
output = stdout.getvalue()
575+
self.assertIn("is empty", output)
576+
self.assertEqual(cm.exception.code, 1)
577+
556578
def test_wrong_fileformat_psv(self):
557579
tour = Tour(
558580
name="mismatched fileformat",

everyvoice/wizard/dataset.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,7 @@ def looks_like_sv(self, file_type, separator) -> bool:
178178
if len(initial_records) > 0:
179179
column_count = len(initial_records[0])
180180
else:
181-
print(
182-
f"ERROR: The filelist you specify ({filelist_path}) is empty. Please double check."
183-
)
181+
print(f"ERROR: File ({filelist_path} is empty. Please double check.")
184182
sys.exit(1)
185183

186184
if column_count < 2:

0 commit comments

Comments
 (0)