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
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)
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)
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)
def test_guess_imgtype_no_name(self): with io.BytesIO() as f: with self.assertRaises(ValueError): povplot.render_tripcolor(f, **self.test_args)
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)