diff --git a/readalongs/text/util.py b/readalongs/text/util.py index 6243f4f6..68cf2980 100644 --- a/readalongs/text/util.py +++ b/readalongs/text/util.py @@ -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 @@ -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 diff --git a/test/test_api.py b/test/test_api.py index 52374b3f..0619f2e9 100755 --- a/test/test_api.py +++ b/test/test_api.py @@ -34,13 +34,13 @@ def test_call_align(self): self.assertTrue(exception is None) self.assertIn("Words () 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( diff --git a/test/test_audio.py b/test/test_audio.py index 675af5eb..5814c413 100755 --- a/test/test_audio.py +++ b/test/test_audio.py @@ -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), @@ -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), @@ -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), diff --git a/test/test_silence.py b/test/test_silence.py index 69d52b75..fb23d81a 100755 --- a/test/test_silence.py +++ b/test/test_silence.py @@ -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, @@ -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, @@ -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, @@ -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)