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 pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ classifiers = [

dependencies = [
"chevron==0.14.0",
"click>=8.0.4,<8.2.0",
"click>=8.0.4",
"coloredlogs>=10.0",
"fastapi>=0.103.0",
"g2p>=2.2.0, <3",
Expand Down
1 change: 1 addition & 0 deletions readalongs/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def cli():
"--config",
type=click.Path(exists=True),
help="Use ReadAlong-Studio configuration file (in JSON format)",
default=None,
)
@click.option(
"-o",
Expand Down
6 changes: 4 additions & 2 deletions tests/basic_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ def silence_c_stderr():
address our narrow needs, namely to silence stderr in a context manager.
"""

if os.name == "nt" and sys.version_info < (3, 10):
yield # work around instability for this on Windows with Py 3.8/3.9
if "pytest" in sys.modules or os.name == "nt" and sys.version_info < (3, 10):
# Incompatible and pointless with pytest since it captures all output
# Also work around instability for this on Windows with Py 3.8/3.9
yield
else:
stderr_fileno = sys.stderr.fileno()
stderr_save = os.dup(stderr_fileno)
Expand Down
27 changes: 14 additions & 13 deletions tests/test_align_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ def test_invoke_align(self) -> None:
(output / "www/assets/image-for-page1.jpg").exists(),
"alignment with image files should have copied image-for-page1.jpg to assets",
)
self.assertIn("image-for-page2.jpg is accessible ", results.stdout)
self.assertIn("image-for-page2.jpg is accessible ", results.output)
os.unlink("image-for-page1.jpg")
self.assertFalse(exists("image-for-page1.jpg"))
self.assertRegex(results.stdout, "Align mode .* succeeded for sequence 0.")
# print(results.stdout)
self.assertRegex(results.output, "Align mode .* succeeded for sequence 0.")
# print(results.output)

# Move the alignment output to compare with further down
# We cannot just output to a different name because changing the output file name
Expand All @@ -126,7 +126,7 @@ def test_invoke_align(self) -> None:
],
)
self.assertEqual(results_dna.exit_code, 0)
# print(results_dna.stdout)
# print(results_dna.output)
self.assertTrue(
(output / "www/output.readalong").exists(),
"successful alignment with DNA should have created output.readalong",
Expand All @@ -135,13 +135,13 @@ def test_invoke_align(self) -> None:
(output / "output.xhtml").exists(),
"successful alignment with -o xhtml should have created output.xhtml",
)
self.assertIn("Please copy image-for-page1.jpg to ", results_dna.stdout)
self.assertIn("Please copy image-for-page1.jpg to ", results_dna.output)
self.assertFalse(
(output / "www/assets/image-for-page1.jpg").exists(),
"image-for-page1.jpg was not on disk, cannot have been copied",
)
self.assertIn(
"Align mode moderate succeeded for sequence 0.", results_dna.stdout
"Align mode moderate succeeded for sequence 0.", results_dna.output
)

# We test error situations in the same test case, since we reuse the same outputs
Expand All @@ -153,6 +153,7 @@ def test_invoke_align(self) -> None:
str(output),
],
)
print("dir(result)", dir(results_output_exists))
self.assertNotEqual(results_output_exists.exit_code, 0)
self.assertIn(
"already exists, use -f to overwrite", results_output_exists.output
Expand Down Expand Up @@ -237,10 +238,10 @@ def test_langs_cmd(self):
"""Validates that readalongs langs lists all in-langs that can map to eng-arpabet"""
results = self.runner.invoke(langs)
self.assertEqual(results.exit_code, 0)
self.assertIn("crg-tmd", results.stdout)
self.assertIn("crg-dv ", results.stdout)
self.assertNotIn("crg ", results.stdout)
self.assertNotIn("fn-unicode", results.stdout)
self.assertIn("crg-tmd", results.output)
self.assertIn("crg-dv ", results.output)
self.assertNotIn("crg ", results.output)
self.assertNotIn("fn-unicode", results.output)

def test_align_english(self):
"""Validates that the lexicon-based g2p works for English language alignment"""
Expand Down Expand Up @@ -310,7 +311,7 @@ def test_invalid_config(self):
join(self.tempdir, "out-invalid-config-1"),
],
)
self.assertIn("must be in JSON format", result.stdout)
self.assertIn("must be in JSON format", result.output)

# --config parameters needs to contain valid json, test with garbage
config_file = join(self.tempdir, "bad-config.json")
Expand All @@ -326,7 +327,7 @@ def test_invalid_config(self):
join(self.tempdir, "out-invalid-config-2"),
],
)
self.assertIn("is not in valid JSON format", result.stdout)
self.assertIn("is not in valid JSON format", result.output)

def test_bad_anchors(self):
"""Make sure invalid anchors yield appropriate errors"""
Expand Down Expand Up @@ -356,7 +357,7 @@ def test_bad_anchors(self):
"Could not parse all anchors",
"Aborting.",
]:
self.assertIn(msg, bad_anchors_result.stdout)
self.assertIn(msg, bad_anchors_result.output)

def test_misc_align_errors(self):
"""Test calling readalongs align with misc CLI errors"""
Expand Down
10 changes: 5 additions & 5 deletions tests/test_make_xml_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,21 @@ def test_invoke_make_xml(self):
["-l", "atj", "-d", self.empty_file, os.path.join(self.tempdir, "delme")],
)
self.assertEqual(results.exit_code, 0)
self.assertRegex(results.stdout, "Running readalongs make-xml")
self.assertRegex(results.output, "Running readalongs make-xml")

def test_no_lang(self):
"""Error case: readalongs make-xml without the mandatory -l switch"""
results = self.runner.invoke(
make_xml, [self.empty_file, self.empty_file + ".readalong"]
)
self.assertNotEqual(results.exit_code, 0)
self.assertRegex(results.stdout, "Missing.*language")
self.assertRegex(results.output, "Missing.*language")

def test_inputfile_not_exist(self):
"""Error case: input file does not exist"""
results = self.runner.invoke(make_xml, "-l atj /file/does/not/exist delme")
self.assertNotEqual(results.exit_code, 0)
self.assertRegex(results.stdout, "No such file or directory")
self.assertRegex(results.output, "No such file or directory")

def test_outputfile_exists(self):
"""Existing output file should not be overwritten by readalongs make-xml by default"""
Expand All @@ -74,7 +74,7 @@ def test_outputfile_exists(self):
["-l", "atj", self.empty_file, os.path.join(self.tempdir, "exists")],
)
self.assertNotEqual(results.exit_code, 0)
self.assertRegex(results.stdout, "exists.*overwrite")
self.assertRegex(results.output, "exists.*overwrite")

def test_output_exists(self):
"""Make sure readalongs make-xml create the expected output file"""
Expand Down Expand Up @@ -124,7 +124,7 @@ def test_generate_output_name(self):
# LOGGER.warning("Output: {}".format(results.output))
# LOGGER.warning("Exception: {}".format(results.exception))
self.assertEqual(results.exit_code, 0)
self.assertRegex(results.stdout, "Wrote.*someinput[.]readalong")
self.assertRegex(results.output, "Wrote.*someinput[.]readalong")
self.assertTrue(
os.path.exists(os.path.join(self.tempdir, "someinput.readalong"))
)
Expand Down
Loading