Changeset 593


Ignore:
Timestamp:
Nov 22, 2015, 6:25:47 AM (4 years ago)
Author:
cito
Message:

Adapt large object tests for Python 3

The content of large objects are bytes in this case.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/module/TEST_PyGreSQL_classic_largeobj.py

    r586 r593  
    9191        finally:
    9292            del large_object
    93         data = 'some data to be shared'
     93        data = b'some data to be shared'
    9494        large_object = self.c.getlo(oid)
    9595        try:
     
    111111        finally:
    112112            del large_object
     113        self.assertIsInstance(r, bytes)
    113114        self.assertEqual(r, data)
    114115
    115116    def testLoImport(self):
    116117        f = tempfile.NamedTemporaryFile()
    117         data = 'some data to be imported'
     118        data = b'some data to be imported'
    118119        f.write(data)
    119120        f.flush()
     
    129130            self.assertEqual(r, len(data))
    130131            r = large_object.read(80)
    131             self.assertIsInstance(r, str)
     132            self.assertIsInstance(r, bytes)
    132133            self.assertEqual(r, data)
    133134            large_object.close()
     
    204205        # reading when object is not yet open
    205206        self.assertRaises(IOError, read, 80)
    206         data = 'some data to be read'
     207        data = b'some data to be read'
    207208        self.obj.open(pg.INV_WRITE)
    208209        self.obj.write(data)
     
    210211        self.obj.open(pg.INV_READ)
    211212        r = read(80)
    212         self.assertIsInstance(r, str)
     213        self.assertIsInstance(r, bytes)
    213214        self.assertEqual(r, data)
    214215        self.obj.close()
    215216        self.obj.open(pg.INV_READ)
    216217        r = read(8)
    217         self.assertIsInstance(r, str)
     218        self.assertIsInstance(r, bytes)
    218219        self.assertEqual(r, data[:8])
    219220        self.obj.close()
     
    227228        # writing when object is not yet open
    228229        self.assertRaises(IOError, write, 'invalid')
    229         data = 'some data to be written'
     230        data = b'some data to be written'
    230231        self.obj.open(pg.INV_WRITE)
    231232        write(data)
     
    233234        self.obj.open(pg.INV_READ)
    234235        r = self.obj.read(80)
     236        self.assertIsInstance(r, bytes)
    235237        self.assertEqual(r, data)
    236238
     
    245247        # seeking when object is not yet open
    246248        self.assertRaises(IOError, seek, 0, pg.SEEK_SET)
    247         data = 'some data to be seeked'
     249        data = b'some data to be seeked'
    248250        self.obj.open(pg.INV_WRITE)
    249251        self.obj.write(data)
     
    252254        seek(0, pg.SEEK_SET)
    253255        r = self.obj.read(9)
    254         self.assertEqual(r, 'some data')
     256        self.assertIsInstance(r, bytes)
     257        self.assertEqual(r, b'some data')
    255258        seek(4, pg.SEEK_CUR)
    256259        r = self.obj.read(2)
    257         self.assertEqual(r, 'be')
     260        self.assertIsInstance(r, bytes)
     261        self.assertEqual(r, b'be')
    258262        seek(-10, pg.SEEK_CUR)
    259263        r = self.obj.read(4)
    260         self.assertEqual(r, 'data')
     264        self.assertIsInstance(r, bytes)
     265        self.assertEqual(r, b'data')
    261266        seek(0, pg.SEEK_SET)
    262267        r = self.obj.read(4)
    263         self.assertEqual(r, 'some')
     268        self.assertIsInstance(r, bytes)
     269        self.assertEqual(r, b'some')
    264270        seek(-6, pg.SEEK_END)
    265271        r = self.obj.read(4)
    266         self.assertEqual(r, 'seek')
     272        self.assertIsInstance(r, bytes)
     273        self.assertEqual(r, b'seek')
    267274
    268275    def testTell(self):
     
    272279        # telling when object is not yet open
    273280        self.assertRaises(IOError, tell)
    274         data = 'some story to be told'
     281        data = b'some story to be told'
    275282        self.obj.open(pg.INV_WRITE)
    276283        self.obj.write(data)
     
    295302        self.obj.open(pg.INV_WRITE)
    296303        self.assertRaises(IOError, unlink)
    297         data = 'some data to be sold'
     304        data = b'some data to be sold'
    298305        self.obj.write(data)
    299306        self.obj.close()
     
    308315            r = obj.read(80)
    309316            obj.close()
     317            self.assertIsInstance(r, bytes)
    310318            self.assertEqual(r, data)
    311319        finally:
     
    327335        self.assertEqual(r, 0)
    328336        # sizing after adding some data
    329         data = 'some data to be sized'
     337        data = b'some data to be sized'
    330338        self.obj.open(pg.INV_WRITE)
    331339        self.obj.write(data)
     
    345353        self.assertEqual(r, len(data))
    346354        # sizing after adding more data
    347         data += ' and more data'
     355        data += b' and more data'
    348356        self.obj.open(pg.INV_WRITE)
    349357        self.obj.write(data)
     
    362370        self.assertRaises(TypeError, export, 'invalid', 0)
    363371        f = tempfile.NamedTemporaryFile()
    364         data = 'some data to be exported'
     372        data = b'some data to be exported'
    365373        self.obj.open(pg.INV_WRITE)
    366374        self.obj.write(data)
     
    371379        r = f.read()
    372380        f.close()
     381        self.assertIsInstance(r, bytes)
    373382        self.assertEqual(r, data)
    374383
    375384    def testPrint(self):
    376385        self.obj.open(pg.INV_WRITE)
    377         data = 'some object to be printed'
     386        data = b'some object to be printed'
    378387        self.obj.write(data)
    379388        f = tempfile.TemporaryFile('r+')
Note: See TracChangeset for help on using the changeset viewer.