Improved test coverage and touching up docs.

This commit is contained in:
Jamie Hardt
2023-11-07 08:20:23 -08:00
parent 208edd8bdc
commit 5aa34dfbe4
2 changed files with 29 additions and 5 deletions

View File

@@ -8,6 +8,26 @@ class TestCue(TestCase):
self.test_files = glob("tests/test_files/cue_chunks/*.wav")
return super().setUp()
def test_enumerate(self):
file1 = "tests/test_files/cue_chunks/STE-000.wav"
w1 = wavinfo.WavInfoReader(file1)
self.assertIsNotNone(w1.cues)
vals = list(w1.cues.each_cue())
self.assertEqual(vals, [(1,29616),(2,74592),(3,121200)])
def test_labels_notes(self):
file = "tests/test_files/cue_chunks/izotoperx_cues_test.wav"
w1 = wavinfo.WavInfoReader(file)
self.assertIsNotNone(w1.cues)
assert w1.cues is not None
for name, _ in w1.cues.each_cue():
self.assertIn(name,[1,2,3])
label, note = w1.cues.label_and_note(name)
if name == 1:
self.assertEqual("Marker 1", label)
self.assertIsNone(note)
def test_encoding_fallback(self):
"""
Added this after I noticed that iZotope RX seems to just encode "notes"
@@ -19,6 +39,7 @@ class TestCue(TestCase):
expected = ("Лорем ипсум долор сит амет, тимеам вивендум хас ет, "
"цу адолесценс дефинитионес еам.")
assert w.cues is not None
note = [n for n in w.cues.notes if n.name == 3]
self.assertEqual(len(note), 1)
self.assertEqual(note[0].text, expected)
@@ -28,17 +49,18 @@ class TestCue(TestCase):
w = wavinfo.WavInfoReader(file)
self.assertIsNotNone(w.cues)
assert w.cues is not None
self.assertEqual(len(w.cues.labels), 3)
for label in w.cues.labels:
self.assertIn(label.name, [1,2,3])
if label.name == 1:
self.assertEqual(label.text, "Marker 1")
elif label.name == 2:
self.assertEqual(label.text, "Marker 2")
elif label.name == 3:
self.assertEqual(label.text, "Marker 3")
else:
self.fail(f"Encountered unexpected label id {label.name}")

View File

@@ -215,6 +215,7 @@ class WavCuesReader:
def each_cue(self) -> Generator[Tuple[int, int], None, None]:
"""
Iterate through each cue.
:yields: the cue's ``name`` and ``sample_offset``
"""
for cue in self.cues:
@@ -223,9 +224,10 @@ class WavCuesReader:
def label_and_note(self, cue_ident: int) -> Tuple[Optional[str], Optional[str]]:
"""
Get the label and note (extended comment) for a cue.
:param cue_ident: the cue's name, it's unique identifying number
:returns: a tuple of the the cue's label (if present) and note (if
present)
:returns: a tuple of the the cue's label (if present) and note (if
present)
"""
label = next((l.text for l in self.labels if l.name == cue_ident), None)
note = next((n.text for n in self.notes if n.name == cue_ident), None)