Skip to content

Commit

Permalink
fix(tests): fix other tests for the changed align output structure
Browse files Browse the repository at this point in the history
  • Loading branch information
joanise committed Jul 12, 2024
1 parent 1413271 commit 96c6a67
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
3 changes: 2 additions & 1 deletion readalongs/text/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from collections import OrderedDict
from datetime import datetime
from io import TextIOWrapper
from pathlib import Path
from typing import IO, Union
from unicodedata import normalize

Expand Down Expand Up @@ -104,7 +105,7 @@ def is_do_not_align(element):
return dna in ("true", "True", "TRUE", "1")


def load_xml(input_path: Union[str, IO]) -> etree.ElementTree:
def load_xml(input_path: Union[str, Path, IO]) -> etree.ElementTree:
"""Safely load an XML file with etree.parse to respect encoding
Return: the root of the XML etree
Expand Down
8 changes: 4 additions & 4 deletions test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ def test_call_align(self):
self.assertTrue(exception is None)
self.assertIn("Words (<w>) not present; tokenizing", log)
expected_output_files = (
"output.readalong",
"output.m4a",
"www/output.readalong",
"www/output.m4a",
"output.TextGrid",
"output_sentences.srt",
"output_words.srt",
"index.html",
"output.html",
"www/index.html",
"Offline-HTML/output.html",
)
for f in expected_output_files:
self.assertTrue(
Expand Down
6 changes: 3 additions & 3 deletions test/test_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_align_sample(self):
if process.returncode != 0:
LOGGER.error("Subprocess readalongs align failed: %s", process.stderr)
# Check Result
raspath = Path(output_path)
raspath = Path(output_path) / "www"
ras_files = raspath.glob("*.readalong")
self.assertTrue(
next(ras_files, False),
Expand All @@ -108,7 +108,7 @@ def test_align_removed(self):
if process.returncode != 0:
LOGGER.error("Subprocess readalongs align failed: %s", process.stderr)
# Check Result
raspath = Path(output_path)
raspath = Path(output_path) / "www"
ras_files = raspath.glob("*.readalong")
self.assertTrue(
next(ras_files, False),
Expand All @@ -135,7 +135,7 @@ def test_align_muted(self):
if process.returncode != 0:
LOGGER.error("Subprocess readalongs align failed: %s", process.stderr)
# Check Result
raspath = Path(output_path)
raspath = Path(output_path) / "www"
ras_files = raspath.glob("*.readalong")
self.assertTrue(
next(ras_files, False),
Expand Down
16 changes: 7 additions & 9 deletions test/test_silence.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class TestSilence(BasicTestCase):

def test_basic_silence_insertion(self):
"""Basic usage of the silence feature in a readalong"""
output = os.path.join(self.tempdir, "silence")
output = self.tempdir / "silence"
# Run align from xml
results = self.runner.invoke(
align,
Expand All @@ -35,22 +35,20 @@ def test_basic_silence_insertion(self):
"fra",
os.path.join(self.data_dir, "ej-fra-silence.readalong"),
os.path.join(self.data_dir, "ej-fra.m4a"),
output,
str(output),
],
)
self.assertEqual(results.exit_code, 0)
self.assertTrue(os.path.exists(os.path.join(output, "silence.m4a")))
self.assertTrue((output / "www/silence.m4a").exists())
# test silence spans in output xml
root = load_xml(os.path.join(output, "silence.readalong"))
root = load_xml(output / "www/silence.readalong")
silence_spans = root.xpath("//silence")
self.assertEqual(len(silence_spans), 3)
# test audio has correct amount of silence added
original_audio = AudioSegment.from_file(
os.path.join(self.data_dir, "ej-fra.m4a")
)
new_audio = AudioSegment.from_file(
os.path.join(output, "silence.m4a"), format="m4a"
)
new_audio = AudioSegment.from_file(output / "www/silence.m4a", format="m4a")
self.assertAlmostEqual(
len(new_audio) - len(original_audio),
2882,
Expand All @@ -59,7 +57,7 @@ def test_basic_silence_insertion(self):
)

def test_bad_silence(self):
output = os.path.join(self.tempdir, "bad_silence")
output = self.tempdir / "bad_silence"
# Run align from bad xml
results = self.runner.invoke(
align,
Expand All @@ -77,7 +75,7 @@ def test_bad_silence(self):
"fra",
os.path.join(self.data_dir, "ej-fra-silence-bad.readalong"),
os.path.join(self.data_dir, "ej-fra.m4a"),
output,
str(output),
],
)
self.assertNotEqual(results.exit_code, 0)
Expand Down

0 comments on commit 96c6a67

Please sign in to comment.