def test_readall(self):
     """RangeableFileObject.read(): to end of file."""
     rfo = RangeableFileObject(StringIO(self.test),(11,))
     self.assertEquals(self.test[11:],rfo.read())
class RangeableFileObjectTestCase(TestCase):
    """Test range.RangeableFileObject class"""
    
    def setUp(self):
        #            0         1         2         3         4         5          6         7         8         9
        #            0123456789012345678901234567890123456789012345678901234567 890123456789012345678901234567890
        self.test = 'Why cannot we write the entire 24 volumes of Encyclopaedia\nBrittanica on the head of a pin?\n'
        self.fo = StringIO(self.test)
        self.rfo = RangeableFileObject(self.fo, (20,69))
        
    def tearDown(self):
        pass
    
    def test_seek(self):
        """RangeableFileObject.seek()"""
        self.rfo.seek(11)
        self.assertEquals('24', self.rfo.read(2))
        self.rfo.seek(14)
        self.assertEquals('volumes', self.rfo.read(7))
        self.rfo.seek(1,1)
        self.assertEquals('of', self.rfo.read(2))
    
    def test_read(self):
        """RangeableFileObject.read()"""
        self.assertEquals('the', self.rfo.read(3))
        self.assertEquals(' entire 24 volumes of ', self.rfo.read(22))
        self.assertEquals('Encyclopaedia\nBrittanica', self.rfo.read(50))
        self.assertEquals('', self.rfo.read())
    
    def test_readall(self):
        """RangeableFileObject.read(): to end of file."""
        rfo = RangeableFileObject(StringIO(self.test),(11,))
        self.assertEquals(self.test[11:],rfo.read())
        
    def test_readline(self):
        """RangeableFileObject.readline()"""
        self.assertEquals('the entire 24 volumes of Encyclopaedia\n', self.rfo.readline())
        self.assertEquals('Brittanica', self.rfo.readline())
        self.assertEquals('', self.rfo.readline())
    
    def test_tell(self):
        """RangeableFileObject.tell()"""
        self.assertEquals(0,self.rfo.tell())
        self.rfo.read(5)
        self.assertEquals(5,self.rfo.tell())
        self.rfo.readline()
        self.assertEquals(39,self.rfo.tell())
 def setUp(self):
     #            0         1         2         3         4         5          6         7         8         9
     #            0123456789012345678901234567890123456789012345678901234567 890123456789012345678901234567890
     self.test = 'Why cannot we write the entire 24 volumes of Encyclopaedia\nBrittanica on the head of a pin?\n'
     self.fo = StringIO(self.test)
     self.rfo = RangeableFileObject(self.fo, (20,69))
Example #4
0
 def setUp(self):
     #            0         1         2         3         4         5          6         7         8         9
     #            0123456789012345678901234567890123456789012345678901234567 890123456789012345678901234567890
     self.test = 'Why cannot we write the entire 24 volumes of Encyclopaedia\nBrittanica on the head of a pin?\n'
     self.fo = StringIO(unicode(self.test) if not six.PY3 else self.test)
     self.rfo = RangeableFileObject(self.fo, (20, 69))
Example #5
0
 def test_readall(self):
     """RangeableFileObject.read(): to end of file."""
     text_compat = unicode(self.test) if not six.PY3 else self.test
     rfo = RangeableFileObject(StringIO(text_compat), (11, ))
     self.assertEquals(self.test[11:], rfo.read())
Example #6
0
class RangeableFileObjectTestCase(TestCase):
    """Test range.RangeableFileObject class"""
    def setUp(self):
        #            0         1         2         3         4         5          6         7         8         9
        #            0123456789012345678901234567890123456789012345678901234567 890123456789012345678901234567890
        self.test = 'Why cannot we write the entire 24 volumes of Encyclopaedia\nBrittanica on the head of a pin?\n'
        self.fo = StringIO(unicode(self.test) if not six.PY3 else self.test)
        self.rfo = RangeableFileObject(self.fo, (20, 69))

    def tearDown(self):
        pass

    def test_seek(self):
        """RangeableFileObject.seek()"""
        self.rfo.seek(11)
        self.assertEquals('24', self.rfo.read(2))
        self.rfo.seek(14)
        self.assertEquals('volumes', self.rfo.read(7))
        self.rfo.seek(1, 1)
        self.assertEquals('of', self.rfo.read(2))

    def test_read(self):
        """RangeableFileObject.read()"""
        self.assertEquals('the', self.rfo.read(3))
        self.assertEquals(' entire 24 volumes of ', self.rfo.read(22))
        self.assertEquals('Encyclopaedia\nBrittanica', self.rfo.read(50))
        self.assertEquals('', self.rfo.read())

    def test_readall(self):
        """RangeableFileObject.read(): to end of file."""
        text_compat = unicode(self.test) if not six.PY3 else self.test
        rfo = RangeableFileObject(StringIO(text_compat), (11, ))
        self.assertEquals(self.test[11:], rfo.read())

    def test_readline(self):
        """RangeableFileObject.readline()"""
        self.assertEquals('the entire 24 volumes of Encyclopaedia\n',
                          self.rfo.readline())
        self.assertEquals('Brittanica', self.rfo.readline())
        self.assertEquals('', self.rfo.readline())

    def test_tell(self):
        """RangeableFileObject.tell()"""
        self.assertEquals(0, self.rfo.tell())
        self.rfo.read(5)
        self.assertEquals(5, self.rfo.tell())
        self.rfo.readline()
        self.assertEquals(39, self.rfo.tell())
class RangeableFileObjectTestCase(TestCase):
    """Test range.RangeableFileObject class"""
    
    def setUp(self):
        #            0         1         2         3         4         5          6         7         8         9
        #            0123456789012345678901234567890123456789012345678901234567 890123456789012345678901234567890
        self.test = 'Why cannot we write the entire 24 volumes of Encyclopaedia\nBrittanica on the head of a pin?\n'
        self.fo = StringIO(self.test)
        self.rfo = RangeableFileObject(self.fo, (20,69))
        
    def tearDown(self):
        pass
    
    def test_seek(self):
        """RangeableFileObject.seek()"""
        self.rfo.seek(11)
        self.assertEquals('24', self.rfo.read(2))
        self.rfo.seek(14)
        self.assertEquals('volumes', self.rfo.read(7))
        self.rfo.seek(1,1)
        self.assertEquals('of', self.rfo.read(2))
    
    def test_poor_mans_seek(self):
        """RangeableFileObject.seek() poor mans version..
        
        We just delete the seek method from StringIO so we can
        excercise RangeableFileObject when the file object supplied
        doesn't support seek.
        """
        seek = StringIO.seek
        del(StringIO.seek)
        self.test_seek()
        StringIO.seek = seek
    
    def test_read(self):
        """RangeableFileObject.read()"""
        self.assertEquals('the', self.rfo.read(3))
        self.assertEquals(' entire 24 volumes of ', self.rfo.read(22))
        self.assertEquals('Encyclopaedia\nBrittanica', self.rfo.read(50))
        self.assertEquals('', self.rfo.read())
    
    def test_readall(self):
        """RangeableFileObject.read(): to end of file."""
        rfo = RangeableFileObject(StringIO(self.test),(11,))
        self.assertEquals(self.test[11:],rfo.read())
        
    def test_readline(self):
        """RangeableFileObject.readline()"""
        self.assertEquals('the entire 24 volumes of Encyclopaedia\n', self.rfo.readline())
        self.assertEquals('Brittanica', self.rfo.readline())
        self.assertEquals('', self.rfo.readline())
    
    def test_tell(self):
        """RangeableFileObject.tell()"""
        self.assertEquals(0,self.rfo.tell())
        self.rfo.read(5)
        self.assertEquals(5,self.rfo.tell())
        self.rfo.readline()
        self.assertEquals(39,self.rfo.tell())
Example #8
0
 def test_readall(self):
     """RangeableFileObject.read(): to end of file."""
     rfo = RangeableFileObject(StringIO(self.test), (11, ))
     self.assertEquals(self.test[11:], rfo.read())
Example #9
0
class RangeableFileObjectTestCase(TestCase):
    """Test range.RangeableFileObject class"""
    def setUp(self):
        #            0         1         2         3         4         5          6         7         8         9
        #            0123456789012345678901234567890123456789012345678901234567 890123456789012345678901234567890
        self.test = 'Why cannot we write the entire 24 volumes of Encyclopaedia\nBrittanica on the head of a pin?\n'
        self.fo = StringIO(self.test)
        self.rfo = RangeableFileObject(self.fo, (20, 69))

    def tearDown(self):
        pass

    def test_seek(self):
        """RangeableFileObject.seek()"""
        self.rfo.seek(11)
        self.assertEquals('24', self.rfo.read(2))
        self.rfo.seek(14)
        self.assertEquals('volumes', self.rfo.read(7))
        self.rfo.seek(1, 1)
        self.assertEquals('of', self.rfo.read(2))

    def test_poor_mans_seek(self):
        """RangeableFileObject.seek() poor mans version..
        
        We just delete the seek method from StringIO so we can
        excercise RangeableFileObject when the file object supplied
        doesn't support seek.
        """
        seek = StringIO.seek
        del (StringIO.seek)
        self.test_seek()
        StringIO.seek = seek

    def test_read(self):
        """RangeableFileObject.read()"""
        self.assertEquals('the', self.rfo.read(3))
        self.assertEquals(' entire 24 volumes of ', self.rfo.read(22))
        self.assertEquals('Encyclopaedia\nBrittanica', self.rfo.read(50))
        self.assertEquals('', self.rfo.read())

    def test_readall(self):
        """RangeableFileObject.read(): to end of file."""
        rfo = RangeableFileObject(StringIO(self.test), (11, ))
        self.assertEquals(self.test[11:], rfo.read())

    def test_readline(self):
        """RangeableFileObject.readline()"""
        self.assertEquals('the entire 24 volumes of Encyclopaedia\n',
                          self.rfo.readline())
        self.assertEquals('Brittanica', self.rfo.readline())
        self.assertEquals('', self.rfo.readline())

    def test_tell(self):
        """RangeableFileObject.tell()"""
        self.assertEquals(0, self.rfo.tell())
        self.rfo.read(5)
        self.assertEquals(5, self.rfo.tell())
        self.rfo.readline()
        self.assertEquals(39, self.rfo.tell())
 def test_readall(self):
     """RangeableFileObject.read(): to end of file."""
     text_compat = unicode(self.test) if not six.PY3 else self.test
     rfo = RangeableFileObject(StringIO(text_compat),(11,))
     self.assertEquals(self.test[11:],rfo.read())