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 48 49
|
import unittest
import rpy2.rpy_classic as rpy
import rpy2.rinterface
class RpyClassicTestCase(unittest.TestCase):
def testAttributeExpansion(self):
rpy.set_default_mode(rpy.BASIC_CONVERSION)
wtest = rpy.r.wilcox_test
self.assertTrue(isinstance(wtest, rpy.Robj))
def testFunctionCall(self):
rpy.set_default_mode(rpy.BASIC_CONVERSION)
# positional only
three = rpy.r.sum(1,2)
three = three[0] # is this what is happening w/ rpy, or the list is
# ...automatically dropped ?
self.assertEqual(3, three)
# positional + keywords
onetwothree = rpy.r.seq(1, 3, by=0.5)
self.assertEqual([1.0, 1.5, 2.0, 2.5, 3.0], onetwothree)
def testFunctionCallWithRObj(self):
rpy.set_default_mode(rpy.NO_CONVERSION)
onetwo = rpy.r.seq(1, 2)
three = rpy.r.sum(onetwo)
rpy.set_default_mode(rpy.BASIC_CONVERSION)
self.assertEqual(3, three.sexp[0])
def testCallable(self):
rpy.set_default_mode(rpy.NO_CONVERSION)
#in rpy-1.x, everything is callable
self.assertTrue(callable(rpy.r.seq))
self.assertTrue(callable(rpy.r.pi))
def testSexp(self):
rpy.set_default_mode(rpy.NO_CONVERSION)
pi = rpy.r.pi
self.assertTrue(isinstance(pi.sexp, rpy2.rinterface.Sexp))
self.assertRaises(AttributeError, setattr, pi, 'sexp', None)
def suite():
suite = unittest.TestLoader().loadTestsFromTestCase(RpyClassicTestCase)
return suite
if __name__ == '__main__':
unittest.main()
|