Пример #1
0
 def test_show_images_over_multiple_rows(self):
     htmls = []
     with mock.patch('IPython.display.display', htmls.append):
         media.show_images([media.color_ramp()] * 5, columns=2)
     self.assertLen(htmls, 1)
     self.assertIsInstance(htmls[0], IPython.display.HTML)
     self.assertLen(re.findall('(?s)<table', htmls[0].data), 3)
     self.assertLen(re.findall('(?s)<img', htmls[0].data), 5)
Пример #2
0
 def test_show_images_list(self):
     htmls = []
     with mock.patch('IPython.display.display', htmls.append):
         media.show_images([media.color_ramp()] * 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)<img', htmls[0].data), 2)
Пример #3
0
 def test_show_save_image(self):
     with tempfile.TemporaryDirectory() as directory_name:
         with media.show_save.to_dir(directory_name):
             with mock.patch('IPython.display.display'):
                 media.show_images({'ramp': media.color_ramp((128, 128))})
         filename = os.path.join(directory_name, 'ramp.png')
         self.assertTrue(os.path.isfile(filename))
         self.assertBetween(os.path.getsize(filename), 200, 1000)
Пример #4
0
 def test_show_images_dict(self):
     htmls = []
     with mock.patch('IPython.display.display', htmls.append):
         media.show_images({
             'title1': media.color_ramp(),
             'title2': media.color_ramp()
         })
     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.*<img .*title2.*<img ')
     self.assertLen(re.findall('(?s)<img', htmls[0].data), 2)