/usr/lib/python3/dist-packages/rpy2/robjects/lib/tests/test_grdevices.py is in python3-rpy2 2.8.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | import unittest
import os
import tempfile
from rpy2.robjects.packages import importr, data
datasets = importr('datasets')
mtcars = data(datasets).fetch('mtcars')['mtcars']
from rpy2.robjects import r
from rpy2.robjects.lib import grdevices
class GrdevicesTestCase(unittest.TestCase):
_todelete = list()
def testSetup(self):
pass
def tearDown(self):
for fn in self._todelete:
if os.path.exists(fn):
os.unlink(fn)
def testRenderToBytesNoPlot(self):
with grdevices.render_to_bytesio(grdevices.png) as b:
pass
self.assertEqual(0, len(b.getvalue()))
def testRenderToFile(self):
fn = tempfile.mktemp(suffix=".png")
with grdevices.render_to_file(grdevices.png,
filename=fn) as d:
r(''' plot(0) ''')
self._todelete.append(fn)
self.assertTrue(os.path.exists(fn))
def testRenderToBytesPlot(self):
with grdevices.render_to_bytesio(grdevices.png) as b:
r(''' plot(0) ''')
self.assertTrue(len(b.getvalue()) > 0)
def suite():
suite = unittest.TestLoader().loadTestsFromTestCase(GrdevicesTestCase)
return suite
if __name__ == '__main__':
unittest.main()
|