Exemple #1
0
 def render(self, **kwargs):
     with tempfile.TemporaryFile('w+b') as f:
         povplot.render_tripcolor(f, imgtype='png', **kwargs)
         f.flush()
         f.seek(0)
         im = (matplotlib.image.imread(f, format='png') *
               255).round().astype(numpy.uint8)
         if im.shape[2] == 3:
             im = numpy.concatenate(
                 [im, numpy.full_like(im[:, :, :1], 255)], axis=2)
         return im
Exemple #2
0
 def test_guess_imgtype_known(self):
     for header, *suffixes in (self.png_header, '.png',
                               b'.png'), :  # (self.jpg_header, '.jpg'):
         for suffix in suffixes:
             with self.subTest(suffix=suffix):
                 with tempfile.NamedTemporaryFile('w+b',
                                                  suffix=suffix) as f:
                     povplot.render_tripcolor(f, **self.test_args)
                     f.flush()
                     f.seek(0)
                     self.assertEqual(f.read(len(header)), header)
Exemple #3
0
 def test_write_str(self):
     with tempfile.NamedTemporaryFile('w+b', suffix='.png') as f:
         povplot.render_tripcolor(f.name, **self.test_args)
         f.flush()
         f.seek(0)
         self.assertEqual(f.read(len(self.png_header)), self.png_header)
Exemple #4
0
 def test_write_stringio(self):
     with io.BytesIO() as f:
         povplot.render_tripcolor(f, imgtype='png', **self.test_args)
         f.flush()
         f.seek(0)
         self.assertEqual(f.read(len(self.png_header)), self.png_header)
Exemple #5
0
 def test_guess_imgtype_no_name(self):
     with io.BytesIO() as f:
         with self.assertRaises(ValueError):
             povplot.render_tripcolor(f, **self.test_args)
Exemple #6
0
 def test_guess_imgtype_unknown(self):
     with tempfile.NamedTemporaryFile('wb', suffix='.unknown') as f:
         with self.assertRaises(ValueError):
             povplot.render_tripcolor(f, **self.test_args)