test_Device.py :  » Language-Interface » RPy » rpy2-2.1.3 » rpy » rinterface » tests » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Language Interface » RPy 
RPy » rpy2 2.1.3 » rpy » rinterface » tests » test_Device.py
import unittest
import rpy2.rinterface as rinterface
import rpy2.rinterface.rpy_device as rdevice
import sys, os, subprocess, time, tempfile, signal
import tempfile

rinterface.initr()

class AbstractDeviceTestCase(unittest.TestCase):
    def setUp(self):
        self.gd = rdevice.GraphicalDevice()

    def tearDown(self):
        self.gd = None

    def _testGetSetBooleanAttr(self, name):
        gd = self.gd
        setattr(gd, name, True)
        self.assertTrue(getattr(gd, name))
        setattr(gd, name, False)
        self.assertFalse(getattr(gd, name))
        self.assertRaises(TypeError, setattr, gd, name, None)

    def _testGetSetDoubleAttr(self, name):
        gd = self.gd
        gd = rdevice.GraphicalDevice()
        setattr(gd, name, 100.0)
        self.assertTrue(getattr(gd, name))
        setattr(gd, name, 0.0)
        self.assertFalse(getattr(gd, name))
        self.assertRaises(TypeError, setattr, gd, name, None)

    def testHasTextUTF8(self):
        self._testGetSetBooleanAttr("hasTextUTF8")

    def testWantSymbolUTF8(self):
        self._testGetSetBooleanAttr("wantSymbolUTF8")
    
    def testLeft(self):
        self._testGetSetDoubleAttr("left")

    def testRight(self):
        self._testGetSetDoubleAttr("right")

    def testTop(self):
        self._testGetSetDoubleAttr("top")

    def testBottom(self):
        self._testGetSetDoubleAttr("bottom")

    def testCanGenMouseDown(self):
        self._testGetSetBooleanAttr("canGenMouseDown")

    def testCanGenMouseMove(self):
        self._testGetSetBooleanAttr("canGenMouseMove")
   
    def testCanGenKeybd(self):
        self._testGetSetBooleanAttr("canGenKeybd")

    def testDisplayListOn(self):
        self._testGetSetBooleanAttr("displayListOn")
  
   
        
class ConcreteDeviceTestCase(unittest.TestCase):
    
    class CodeDevice(rdevice.GraphicalDevice):
        
        def __init__(self, filehandle):
            super(ConcreteDeviceTestCase.CodeDevice, self).__init__()
            self._activated = None
            self._open = True
            self._pagecount = 0
            self._file = filehandle
            
        def activate(self):
            self._activated = True

        def deactivate(self):
            self._activated = False

        def close(self):
            self._activated = None
            self._open = False
            self._file.close()
            
        def size(self, lrbt):
            return (1,2,3,4)

        def newpage(self):
            self._file.write('#--- new page\n')
            self._pagecount = self._pagecount + 1

        def line(self, x1, y1, x2, y2):
            self._file.write('line(%f, %f, %f, %f)' %(x1, y1, x2, y2))

        def polyline(self, x, y):
            self._file.write('polyline(%f, %f)' %(x, y))
            
        def clip(self):
            pass

    def setUp(self):
        #f = tempfile.NamedTemporaryFile()
        f = file('/tmp/foo', mode='w')
        self.gd = ConcreteDeviceTestCase.CodeDevice(f)

    def tearDown(self):
        self.gd.close()

    def testActivate(self):
        self.assertTrue(self.gd._activated)
        #other_gd = ConcreteDeviceTestCase.CodeDevice()
        #self.assertFalse(self.gd._activated)

    def testClose(self):
        self.gd.close()
        self.assertFalse(self.gd._open)

    def testSize(self):
        size = self.gd.size()
        self.assertEquals(size, [1,2,3,4])

    def testLine(self):
        res = rinterface.globalenv.get('plot.new')()
        res = rinterface.globalenv.get('lines')(rinterface.IntSexpVector((0, 0)),
                                                rinterface.IntSexpVector((1, 2)))
        
def suite():
    suite = unittest.TestLoader().loadTestsFromTestCase(AbstractDeviceTestCase)
    suite.addTest(unittest.TestLoader().loadTestsFromTestCase(ConcreteDeviceTestCase))
    return suite

if __name__ == '__main__':
    tr = unittest.TextTestRunner(verbosity = 2)
    tr.run(suite())
 
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.