def test_parse_ass_format(): """ Given a valid format: ass and a path to a valid file When trying to parse the file at the given file path Then the parser should return a fully populated Episode object """ parser = Parser(Format.ASS) lines = [ Line( 0, dt.time(0, 0, 54), dt.time(0, 0, 58), 'Jeremie', 'Diary of Jeremie Belpois, Kadic Academy 8th grade student,' ' October 9th.'), Line( 0, dt.time(0, 0, 59), dt.time(0, 1, 3), 'Jeremie', 'A few weeks ago, I was hunting for parts to finish building my' ' miniature robots.'), Line( 0, dt.time(0, 1, 3), dt.time(0, 1, 10), 'Jeremie', 'I couldnt find anything around here I could use, so I decided' ' to rummage for scrap in the abandoned factory, not far from the' ' Academy.'), ] valid_episode = Episode(0, "X.A.N.A. Awakens") for line in lines: valid_episode.add_line(line) assert parser.parse('tests/subtitles/test.ass') == valid_episode
def test_line_has_dialogue(): """ Given a line that has the dialogue "Some text." When searching the line for the substring "Text" Then the line should affirm that it has the substring in its dialogue """ text = 'Text' line = Line(121, dt.time(1), dt.time(2), 'Yumi', 'Some text.') assert line.has_dialogue(text)
def test_line_eq_false(): """ Given two equal lines When comparing them with the overloaded `==` operator Then they should resolve to a true boolean """ line_1 = Line(121, dt.time(1), dt.time(2), 'Yumi', 'Some text.') line_2 = Line(122, dt.time(3), dt.time(4), 'Odd', 'Other text.') assert line_1 != line_2
def test_episode_eq_true(): """ Given two equal episodes with equal lines When comparing them with the overloaded `==` operator Then they should resolve to a true boolean """ lines = [ Line(121, dt.time(0, 10, 12), dt.time(0, 10, 13), 'Yumi', 'Text 1'), Line(122, dt.time(0, 15, 12), dt.time(0, 16, 13), 'Ulrich', 'Text 2') ] episode_1 = Episode(121, "Zero Gravity Zone") episode_2 = Episode(121, "Zero Gravity Zone") for line in lines: episode_1.add_line(line) episode_2.add_line(line) assert episode_1 == episode_2
def test_episode_to_dict(): """ Given a set of valid episode and line info When constructing an episode with the data set: { production_code: 121, title: 'Zero Gravity Zone', lines: [ { production_code: 121, start: dt.time(1), end: dt.time(2), character: 'Yumi', dialogue: 'Some text.' } ], } Then it should produce a matching dict representation """ line = Line(121, dt.time(1), dt.time(2), 'Yumi', 'Some text.') episode = Episode(121, 'Zero Gravity Zone') episode.add_line(line) assert episode.__dict__() == { 'production_code': 121, 'title': 'Zero Gravity Zone', 'lines': [{ 'production_code': 121, 'timestamp': { 'start': dt.time(1).strftime('%H:%M:%S'), 'end': dt.time(2).strftime('%H:%M:%S') }, 'character': 'YUMI', 'dialogue': 'Some text.' }] }
def test_line_start_before_end(): """ Given a line with a start-time greater than its end-time When constructing the object Then a ValueError should be raised """ with pytest.raises(ValueError): assert Line(121, dt.time(2), dt.time(1), 'Yumi', 'Some text.')
def test_episode_not_has_search_terms(): """ Given the search terms: { character: Odd dialogue: more } When searching the episode with the given terms Then the results of the search should be: [] """ lines = [ Line(121, dt.time(0, 10, 12), dt.time(0, 10, 13), 'Yumi', 'A text 1.'), Line(121, dt.time(0, 11, 30), dt.time(0, 11, 32), 'Yumi', 'More text!'), Line(121, dt.time(0, 15, 12), dt.time(0, 16, 13), 'Ulrich', 'B, text 2.') ] episode = Episode(121, "Zero Gravity Zone") for line in lines: episode.add_line(line) assert episode.search(dialogue='more', character='odd') == []
def test_line_to_dict(): """ Given a set of valid line info When constructing a line with the data set: { production_code: 121, start: dt.time(1), end: dt.time(2), character: 'Yumi', dialogue: 'Some text.' } Then it should produce a matching dict representation """ line = Line(121, dt.time(1), dt.time(2), 'Yumi', 'Some text.') assert line.__dict__() == { 'production_code': 121, 'timestamp': { 'start': dt.time(1).strftime('%H:%M:%S'), 'end': dt.time(2).strftime('%H:%M:%S') }, 'character': 'YUMI', 'dialogue': 'Some text.' }
def test_line_construction(): """ Given a set of valid line info When constructing a line with the data set: { production_code: 121, start: dt.time(1), end: dt.time(2), character: 'Yumi', dialogue: 'Some text.' } and converting it to a string Then it should produce the string "" """ line = Line(121, dt.time(1), dt.time(2), 'Yumi', 'Some text.') assert str(line) == '<Line: [01:00:00-02:00:00][YUMI]: Some text.>'
def test_episode_add_get(): """ Given a valid line: { production_code: 121, start: dt.time(0, 5, 37), end: dt.time(0, 5, 42), character: 'Ulrich', dialogue: 'No, I said count me out. I’ll go when the game’s over.' } When adding it to an episode and subindexing the episode by the same start-time Then it should give back the line just submitted """ episode = Episode(121, "Zero Gravity Zone") line = Line(121, dt.time(0, 5, 37), dt.time(0, 5, 42), 'Ulrich', 'No, I said count me out. I’ll go when the game’s over.') episode.add_line(line) assert episode[dt.time(0, 5, 37)] == line