Skip to content

Commit

Permalink
fix: add unit test for handling empty filelist
Browse files Browse the repository at this point in the history
  • Loading branch information
MENGZHEGENG authored and roedoejet committed Jul 24, 2024
1 parent 189e338 commit 83742ff
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
Empty file added everyvoice/tests/data/empty.psv
Empty file.
22 changes: 22 additions & 0 deletions everyvoice/tests/test_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,28 @@ def test_dataset_subtour(self):
self.assertEqual(len(symbol_set_step.state[SN.symbol_set_step.value]), 2)
self.assertIn("t͡s", symbol_set_step.state[SN.symbol_set_step.value]["phones"])

def test_empty_filelist(self):
tour = Tour(
name="empty filelist",
steps=[
dataset.FilelistStep(),
dataset.FilelistFormatStep(),
],
)
filelist = str(self.data_dir / "empty.psv")

filelist_step = tour.steps[0]
with monkeypatch(filelist_step, "prompt", Say(filelist)):
filelist_step.run()

format_step = tour.steps[1]
with self.assertRaises(SystemExit) as cm:
with patch_menu_prompt(1) as stdout:
format_step.run()
output = stdout.getvalue()
self.assertIn("is empty", output)
self.assertEqual(cm.exception.code, 1)

def test_wrong_fileformat_psv(self):
tour = Tour(
name="mismatched fileformat",
Expand Down
4 changes: 1 addition & 3 deletions everyvoice/wizard/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,7 @@ def looks_like_sv(self, file_type, separator) -> bool:
if len(initial_records) > 0:
column_count = len(initial_records[0])
else:
print(
f"ERROR: The filelist you specify ({filelist_path}) is empty. Please double check."
)
print(f"ERROR: File ({filelist_path} is empty. Please double check.")
sys.exit(1)

if column_count < 2:
Expand Down

0 comments on commit 83742ff

Please sign in to comment.