File: test_robj.py

package info (click to toggle)
rpy 0.4.1-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,988 kB
  • ctags: 14,206
  • sloc: ansic: 15,392; python: 977; makefile: 406; sh: 28
file content (70 lines) | stat: -rw-r--r-- 2,109 bytes parent folder | download
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from __future__ import nested_scopes

import unittest
import sys
sys.path.insert(1, "..")
from rpy import *

class RobjTestCase(unittest.TestCase):

    def setUp(self):
        self.robj = type(r.array)
        set_default_mode(NO_DEFAULT)
        class_table.clear()
        proc_table.clear()
        
    def testType(self):
        self.failUnless(type(r.array) == type(r.seq))

    def testCall(self):
        self.failUnless(callable(r.seq))

    def testKeywordParameters(self):
        r.list.autoconvert(BASIC_CONVERSION)
        d = r.list(foo='foo', bar_foo='bar.foo',
                   print_='print', as_data_frame='as.data.frame')
        for k in d.keys():
            self.failUnless(k == d[k])
            
    def testNameConversions(self):
        self.failUnless(r.array is r['array'] and
                        r.print_ is r['print'] and
                        r.as_data_frame is r['as.data.frame'] and
                        r.attr__ is r['attr<-'])

    def testNotFound(self):
        self.failUnlessRaises(RException, lambda: r.foo)
        
    def testNameLengthOne(self):
        self.failUnless(r.T)

    def testAutoconvert(self):
        r.seq.autoconvert(1)
        self.failUnless(r.seq(10) == range(1,11))
        r.seq.autoconvert(0)
        self.failUnless(type(r.seq(10)) == type(r.seq))
        r.seq.autoconvert(1)

    def testBadAutoconvert(self):
        self.failUnlessRaises(ValueError, lambda : r.seq.autoconvert(4))
        
    def testGetAutoconvert(self):
        a = r.seq.autoconvert()
        self.failUnless(type(a) is type(1) and -1<=a<=2)
        
    def testRgc(self):
        r.seq.autoconvert(NO_CONVERSION)
        a = r.seq(100000)
        r.gc()
        assert(a[10])
        r.seq.autoconvert(BASIC_CONVERSION)

    def testLCall(self):
        "Test if lcall preserves named argument ordering."
        set_default_mode(NO_CONVERSION)
        a = r.c.lcall( (('',0),('a',1),('b',2),('c',3)) )
        set_default_mode(BASIC_CONVERSION)
        self.failUnless(r.names(a) == ['','a','b','c'])

if __name__ == '__main__':
    unittest.main()