Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion everyvoice/model/aligner/wav2vec2aligner
8 changes: 2 additions & 6 deletions everyvoice/tests/preprocessed_audio_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

class PreprocessedAudioFixture:
"""
A unittest fixture to preprocess the audio files.
A unittest fixture (implemented as a base class) to preprocess the audio files.
"""

_tempdir = tempfile.TemporaryDirectory(prefix="tmpdir_PreprocessedInputFixture_")
Expand Down Expand Up @@ -67,12 +67,8 @@ class PreprocessedAudioFixture:

preprocessor = Preprocessor(fp_config)

# def setUp(self):
# """Each test function should get a fresh preprocessor"""
# self.preprocessor = Preprocessor(self.fp_config)

@classmethod
def setUpClass(cls):
def setup_class(cls):
"""Generate a preprocessed test set that can be used in various test cases."""
# We only need to actually run this once
if not PreprocessedAudioFixture._preprocess_ran:
Expand Down
10 changes: 5 additions & 5 deletions everyvoice/tests/regression/test-demo-app-mix.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,36 +30,36 @@ def test_rundemo(self) -> None:
with page.expect_download() as download_info:
page.get_by_label("Download").click()
download = download_info.value
self.assertTrue(download.suggested_filename.endswith(".wav"))
assert download.suggested_filename.endswith(".wav")
page.get_by_label("Output Format").click()
page.get_by_label("spec").click()
synthesize_button.click()
page.get_by_label("Play", exact=True).click()
with page.expect_download() as download1_info:
page.locator("#file_output").get_by_role("link").click()
download = download1_info.value
self.assertTrue(download.suggested_filename.endswith(".pt"))
assert download.suggested_filename.endswith(".pt")
page.get_by_label("Output Format").click()
page.get_by_label("textgrid").click()
synthesize_button.click()
with page.expect_download() as download2_info:
page.locator("#file_output").get_by_role("link").click()
download = download2_info.value
self.assertTrue(download.suggested_filename.endswith(".TextGrid"))
assert download.suggested_filename.endswith(".TextGrid")
page.get_by_label("Output Format").click()
page.get_by_label("readalong-xml").click()
synthesize_button.click()
with page.expect_download() as download3_info:
page.locator("#file_output").get_by_role("link").click()
download = download3_info.value
self.assertTrue(download.suggested_filename.endswith(".readalong"))
assert download.suggested_filename.endswith(".readalong")
page.get_by_label("Output Format").click()
page.get_by_label("readalong-html").click()
synthesize_button.click()
with page.expect_download() as download4_info:
page.locator("#file_output").get_by_role("link").click()
download = download4_info.value
self.assertTrue(download.suggested_filename.endswith(".html"))
assert download.suggested_filename.endswith(".html")
page.get_by_label("Language").click()
page.get_by_label("und").click()
page.get_by_label("Speaker", exact=True).click()
Expand Down
2 changes: 1 addition & 1 deletion everyvoice/tests/stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ def __exit__(self, *_exc_info):
def flatten_log(log_output: str) -> str:
"""Replace newlines and other sequences of whitespace by a single space.

Usage: self.assertIn("some text", flatten_log(captured_output))
Usage: assert "some text" in flatten_log(captured_output)

Avoids having to use self.assertRegex everywhere just because of rich or pretty
printing of messages over multiple lines.
Expand Down
108 changes: 54 additions & 54 deletions everyvoice/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@

def test_version(self):
result = self.runner.invoke(app, ["--version"])
self.assertEqual(result.exit_code, 0)
self.assertIn(VERSION, result.stdout)
assert result.exit_code == 0
assert VERSION in result.stdout

def test_submodule_versions(self):
# Team decision 2025-02-10: we won't keep submodule versions in complete lockstep,
Expand All @@ -181,12 +181,12 @@
def test_diagnostic(self):
with capture_stdout():
result = self.runner.invoke(app, ["--diagnostic"])
self.assertEqual(result.exit_code, 0)
self.assertIn("EveryVoice version", result.stdout)
self.assertIn("Python version", result.stdout)
assert result.exit_code == 0
assert "EveryVoice version" in result.stdout
assert "Python version" in result.stdout
# We can't really validate the whole dependency list, but we should at least find torch
# [5:] ignores the header generated by everyvoice --diagnostic and only looks at deps
self.assertIn("torch", "".join(result.stdout.lower().splitlines()[5:]))
assert "torch" in "".join(result.stdout.lower().splitlines()[5:])

def wip_test_synthesize(self):
# TODO: Here's a stub for getting synthesis unit tests working
Expand Down Expand Up @@ -229,7 +229,7 @@
"wav",
],
)
self.assertEqual(single_text_result.exit_code, 0)
assert single_text_result.exit_code == 0
self.assertEqual(
len(list(Path("single_text/wav").glob("*.wav"))), 1
) # assert synthesizes a single file
Expand All @@ -249,7 +249,7 @@
"wav",
],
)
self.assertEqual(filelist_result.exit_code, 0)
assert filelist_result.exit_code == 0
self.assertEqual(
len(list((tmpdir / "filelist" / "wav").glob("*.wav"))), 3
) # assert synthesizes three files
Expand All @@ -258,16 +258,16 @@
result = self.runner.invoke(app, ["--help"])
# each command has some help
for command in self.commands:
self.assertIn(command, result.stdout)
assert command in result.stdout
# link to docs is present
self.assertIn("https://docs.everyvoice.ca", result.stdout)
assert "https://docs.everyvoice.ca" in result.stdout

Check failure

Code scanning / CodeQL

Incomplete URL substring sanitization High test

The string
https://docs.everyvoice.ca
may be at an arbitrary position in the sanitized URL.
Comment thread
joanise marked this conversation as resolved.
Dismissed

def test_command_help_messages(self):
for command in self.commands:
result = self.runner.invoke(app, [command, "--help"])
self.assertEqual(result.exit_code, 0)
assert result.exit_code == 0
result = self.runner.invoke(app, [command, "-h"])
self.assertEqual(result.exit_code, 0)
assert result.exit_code == 0

def test_update_schema(self):
dummy_contact = ContactInformation(
Expand Down Expand Up @@ -317,8 +317,8 @@
# Next, but only if everything above passed, we make sure we can't overwrite
# existing schemas by accident.
result = self.runner.invoke(app, ["update-schemas"])
self.assertNotEqual(result.exit_code, 0)
self.assertIn("FileExistsError", str(result))
assert result.exit_code != 0
assert "FileExistsError" in str(result)

def test_evaluate(self):
result = self.runner.invoke(
Expand All @@ -331,12 +331,12 @@
self.data_dir / "lj" / "wavs" / "LJ050-0269.wav",
],
)
self.assertEqual(result.exit_code, 0)
self.assertIn("LJ010-0008", result.stdout)
self.assertIn("STOI", result.stdout)
self.assertIn("MOS", result.stdout)
self.assertIn("SI-SDR", result.stdout)
self.assertIn("PESQ", result.stdout)
assert result.exit_code == 0
assert "LJ010-0008" in result.stdout
assert "STOI" in result.stdout
assert "MOS" in result.stdout
assert "SI-SDR" in result.stdout
assert "PESQ" in result.stdout
dir_result = self.runner.invoke(
app,
[
Expand All @@ -347,42 +347,42 @@
self.data_dir / "LJ010-0008.wav",
],
)
self.assertEqual(dir_result.exit_code, 0)
self.assertIn("LJ050-0269", dir_result.stdout, "should print out the basenames")
assert dir_result.exit_code == 0
assert "LJ050-0269", dir_result.stdout in "should print out the basenames"
self.assertIn(
"Average STOI",
dir_result.stdout,
"should report metrics in terms of averages",
)
evaluation_output = self.data_dir / "lj" / "wavs" / "evaluation.json"
self.assertTrue(evaluation_output.exists(), "should print results to a file")
assert evaluation_output.exists(), "should print results to a file"
evaluation_output.unlink()

def test_old_inspect_checkpoint(self):
result = self.runner.invoke(
app, ["inspect-checkpoint", str(self.data_dir / "test.ckpt")]
)
self.assertEqual(result.exit_code, 0)
assert result.exit_code == 0
self.assertIn(
"This command has been renamed to `everyvoice checkpoint inspect`",
flatten_log(result.stdout),
)

def test_inspect_checkpoint_help(self):
result = self.runner.invoke(app, ["checkpoint", "inspect", "--help"])
self.assertIn("checkpoint inspect [OPTIONS] MODEL_PATH", result.stdout)
assert "checkpoint inspect [OPTIONS] MODEL_PATH" in result.stdout

def test_inspect_checkpoint(self):
result = self.runner.invoke(
app, ["checkpoint", "inspect", str(self.data_dir / "test.ckpt")]
)
self.assertIn('global_step": 52256', result.stdout)
assert 'global_step": 52256' in result.stdout
self.assertIn(
"We couldn't read your file, possibly because the version of EveryVoice that created it is incompatible with your installed version.",
result.stdout,
)
self.assertIn("It appears to have 0.0 M parameters.", result.stdout)
self.assertIn("Number of Parameters", result.stdout)
assert "It appears to have 0.0 M parameters." in result.stdout
assert "Number of Parameters" in result.stdout

def test_inspect_not_a_checkpoint(self) -> None:
result = self.runner.invoke(app, ["checkpoint", "inspect", os.devnull])
Expand Down Expand Up @@ -433,7 +433,7 @@
str(self.config_dir / "everyvoice-spec-to-wav.yaml"),
],
)
self.assertEqual(result.exit_code, 1)
assert result.exit_code == 1
self.assertIn(
"We are expecting a FastSpeech2Config but it looks like you provided a HiFiGANConfig",
"\n".join(output),
Expand All @@ -455,14 +455,14 @@

def test_demo_with_bad_args(self):
result = self.runner.invoke(app, ["demo"])
self.assertNotEqual(result.exit_code, 0)
self.assertIn("Missing argument", result.output)
assert result.exit_code != 0
assert "Missing argument" in result.output

result = self.runner.invoke(
app, ["demo", os.devnull, os.devnull, "--output-format", "not-a-format"]
)
self.assertNotEqual(result.exit_code, 0)
self.assertIn("Invalid value", result.output)
assert result.exit_code != 0
assert "Invalid value" in result.output

EMPTY_DEMO_ARGS: dict[str, Any] = {
"languages": [],
Expand All @@ -481,7 +481,7 @@
**self.EMPTY_DEMO_ARGS, # type: ignore[arg-type]
outputs=[],
)
self.assertIn("Empty outputs list", str(cm.exception))
assert "Empty outputs list" in str(cm.exception)

class WrongEnum(str, enum.Enum):
foo = "foo"
Expand All @@ -494,13 +494,13 @@
**self.EMPTY_DEMO_ARGS, # type: ignore[arg-type]
outputs=outputs,
)
self.assertIn("Unknown output format 'foo'", str(cm.exception))
assert "Unknown output format 'foo'" in str(cm.exception)

def test_demo_with_bad_models(self) -> None:
devnull = Path(os.devnull)
with self.assertRaises(ValueError) as cm:
create_demo_app(devnull, devnull, **self.EMPTY_DEMO_ARGS, outputs=["wav"]) # type: ignore[arg-type]
self.assertIn("It does not appear to be a valid checkpoint", str(cm.exception))
assert "It does not appear to be a valid checkpoint" in str(cm.exception)

with self.assertRaises(ValueError) as cm:
create_demo_app(
Expand All @@ -509,13 +509,13 @@
**self.EMPTY_DEMO_ARGS, # type: ignore[arg-type]
outputs=["wav"],
)
self.assertIn("maybe it's not actually a HiFiGAN model", str(cm.exception))
assert "maybe it's not actually a HiFiGAN model" in str(cm.exception)

def test_demo_with_wrong_models(self) -> None:
fp_path, vocoder_path = self.get_dummy_models()
with self.assertRaises(ValueError) as cm:
create_demo_app(fp_path, fp_path, **self.EMPTY_DEMO_ARGS, outputs=["wav"]) # type: ignore[arg-type]
self.assertIn("maybe it's not actually a HiFiGAN model", str(cm.exception))
assert "maybe it's not actually a HiFiGAN model" in str(cm.exception)

with self.assertRaises(ValueError) as cm:
create_demo_app(
Expand All @@ -524,7 +524,7 @@
**self.EMPTY_DEMO_ARGS, # type: ignore[arg-type]
outputs=["wav"],
)
self.assertIn("maybe it's not actually an fs2 model", str(cm.exception))
assert "maybe it's not actually an fs2 model" in str(cm.exception)

def test_g2p(self):
result = self.runner.invoke(
Expand All @@ -538,8 +538,8 @@
],
)

self.assertEqual(result.exit_code, 0)
self.assertIn("['hello', 'world']", result.stdout)
assert result.exit_code == 0
assert "['hello', 'world']" in result.stdout
self.assertNotIn("['HELLO', 'WORLD']", result.stdout)

def mock_create_demo_app(self, *_args, **_kwargs):
Expand Down Expand Up @@ -605,10 +605,10 @@
ip, # Mock IP address
],
)
self.assertEqual(result.exit_code, 0)
self.assertIn(f" - Port: {port}", result.output)
self.assertIn(" - Share: True", result.output)
self.assertIn(f" - Server Name: {ip}", result.output)
assert result.exit_code == 0
assert f" - Port: {port}" in result.output
assert " - Share: True" in result.output
assert f" - Server Name: {ip}" in result.output

def mock_demo_load_model_from_checkpoint(
*_arg, **kwargs
Expand Down Expand Up @@ -729,7 +729,7 @@
)
# print(result.output, result.exit_code) # Debug output

self.assertEqual(result.exit_code, 0)
assert result.exit_code == 0
self.assertIn(
f"Using speakers from app config JSON: [('{config['speakers']['default']}', 'default')]",
result.output,
Expand Down Expand Up @@ -813,7 +813,7 @@
],
)
# print(result.output, result.exit_code) # Debug output
self.assertNotEqual(result.exit_code, 0)
assert result.exit_code != 0
self.assertRegex(
result.output, r"(?s)Your config file.*malformed.*has.*errors"
)
Expand Down Expand Up @@ -918,7 +918,7 @@
],
)

self.assertEqual(result.exit_code, 0)
assert result.exit_code == 0
self.assertIn(
"Renamed speaker 'old_speaker' to 'new_speaker'.", result.output
)
Expand Down Expand Up @@ -953,8 +953,8 @@
],
)
# print(result.output)
self.assertNotEqual(result.exit_code, 0)
self.assertIn("Speaker 'non_existing_speaker' not found", result.output)
assert result.exit_code != 0
assert "Speaker 'non_existing_speaker' not found" in result.output

def test_rename_speaker_with_no_speakers(self):
with tempfile.TemporaryDirectory() as tmpdir_str:
Expand All @@ -979,8 +979,8 @@
],
)
# print(result.output)
self.assertNotEqual(result.exit_code, 0)
self.assertIn("No speakers found", result.output)
assert result.exit_code != 0
assert "No speakers found" in result.output


class TestBaseCLIHelper(TestCase):
Expand All @@ -1002,10 +1002,10 @@

log_dir = config.training.logger.save_dir / config.training.logger.name
log = log_dir / "log"
self.assertTrue(log.exists())
assert log.exists()

hparams = log_dir / "hparams.yaml"
self.assertTrue(hparams.exists())
assert hparams.exists()
with hparams.open(mode="r", encoding="UTF8") as f:
config_reloaded = yaml.load(f, Loader=Loader)
self.assertEqual(
Expand Down
Loading
Loading