def test_show_videos_over_multiple_rows(self): htmls = [] with mock.patch('IPython.display.display', htmls.append): media.show_videos([media.moving_circle()] * 12, columns=3) self.assertLen(htmls, 1) self.assertIsInstance(htmls[0], IPython.display.HTML) self.assertLen(re.findall('(?s)<table', htmls[0].data), 4) self.assertLen(re.findall('(?s)<video', htmls[0].data), 12)
def test_show_videos_list(self): htmls = [] with mock.patch('IPython.display.display', htmls.append): media.show_videos([media.moving_circle()] * 2) self.assertLen(htmls, 1) self.assertIsInstance(htmls[0], IPython.display.HTML) self.assertLen(re.findall('(?s)<table', htmls[0].data), 1) self.assertLen(re.findall('(?s)<video', htmls[0].data), 2)
def test_show_save_video(self): video = media.moving_circle((32, 32), num_images=10) with tempfile.TemporaryDirectory() as directory_name: directory_path = pathlib.Path(directory_name) with media.show_save.to_dir(directory_path): with mock.patch('IPython.display.display'): media.show_videos({'video0': video, 'video1': video}) for i in range(2): path = directory_path / f'video{i}.mp4' self.assertTrue(path.is_file()) self.assertBetween(path.stat().st_size, 1500, 3000)
def test_show_videos_dict(self): htmls = [] with mock.patch('IPython.display.display', htmls.append): media.show_videos({ 'title1': media.moving_circle(), 'title2': media.moving_circle(), }) self.assertLen(htmls, 1) self.assertIsInstance(htmls[0], IPython.display.HTML) self.assertLen(re.findall('(?s)<table', htmls[0].data), 1) self.assertRegex(htmls[0].data, '(?s)title1.*<video.*title2.*<video') self.assertLen(re.findall('(?s)<video', htmls[0].data), 2)