Skip to content

Commit

Permalink
style: reformat make_smil.py docstring to Google format, as per issue #…
Browse files Browse the repository at this point in the history
  • Loading branch information
joanise committed Sep 3, 2021
1 parent 2e13e1f commit ad875a0
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions test/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

from unittest import TestCase, main

from readalongs.text.make_smil import format_smil_time, format_times
from test_audio import segments_from_pairs

from readalongs.align import split_silences
from readalongs.text.util import parse_time


Expand Down Expand Up @@ -34,24 +36,30 @@ def test_parse_time_errors(self):
):
_ = parse_time(err_time_str)

def test_format_smil_time(self):
for num, formatted in (
(0.1234, "0.123"),
(34, "34.00"),
(23.12000000005, "23.12"),
(23.2999999, "23.30"),
):
self.assertEqual(
format_smil_time(num),
formatted,
f'error formatting "{num}" to 2 or 3 decimal digits',
def test_split_silences(self):
dna = segments_from_pairs((1000, 2000), (5000, 5000))
words = [
{"id": i, "start": s, "end": e}
for i, s, e in (
("1", 0.100, 0.200),
("2", 0.300, 0.900),
("3", 2.002, 2.100),
("4", 2.200, 4.900),
("5", 5.004, 6.000),
)

def test_format_times(self):
results = {"words": [{"start": 43.123456, "end": 54.0}]}
format_times(results)
self.assertEqual(results["words"][0]["start"], "43.123")
self.assertEqual(results["words"][0]["end"], "54.00")
]
split_silences(words, 6.100, dna)
ref = [
{"id": i, "start": s, "end": e}
for i, s, e in (
("1", 0.050, 0.250),
("2", 0.250, 1.000),
("3", 2.000, 2.150),
("4", 2.150, 4.952),
("5", 5.000, 6.050),
)
]
self.assertEqual(words, ref)


if __name__ == "__main__":
Expand Down

0 comments on commit ad875a0

Please sign in to comment.