async def test_tell(self): async with s3aioFileObject(self.cfg["STFC"]["url"] + "/buckettest/thefox2a.nc", credentials=self.cfg["STFC"]["credentials"], mode="rw") as s3c: if s3c.tell() == 0: return else: self.fail("s3aioFileObject.tell did not return 0")
async def test_seekable(self): async with s3aioFileObject(self.cfg["STFC"]["url"] + "/buckettest/thefox2a.nc", credentials=self.cfg["STFC"]["credentials"], mode="rw") as s3c: if s3c.seekable(): return else: self.fail("s3aioFileObject.seekable returned False")
async def test_fileno(self): async with s3aioFileObject(self.cfg["STFC"]["url"] + "/buckettest/thefox2a.nc", credentials=self.cfg["STFC"]["credentials"], mode="w") as s3c: try: s3c.fileno() except io.UnsupportedOperation: return self.fail( "s3aioFileObject.fileno did not raise io.UnsupportedOperation")
async def test_1write(self): async with s3aioFileObject(self.cfg["STFC"]["url"] + "/buckettest/thefox2a.nc", credentials=self.cfg["STFC"]["credentials"], mode="w") as s3c: # create random bytes - if we keep it below s3c._getsize() then it will # only do one upload size = await s3c._getsize() bytes = bytearray(size) for b in range(0, size): bytes[b] = 128 # convert bytes to io.BytesIO if await s3c.write(bytes) == 0: self.fail("s3aioFileObject.write returned zero")
async def test_seek(self): async with s3aioFileObject(self.cfg["STFC"]["url"] + "/buckettest/thefox2a.nc", credentials=self.cfg["STFC"]["credentials"], mode="rw") as s3c: # Three different methods for seek: # whence = io.SEEK_SET # whence = io.SEEK_CUR # whence = io.SEEK_END # the current pointer is on zero if not await s3c.seek(0, whence=io.SEEK_SET) == 0: self.fail("s3aioFileObject.seek did not return 0") if not await s3c.seek(10, whence=io.SEEK_SET) == 10: self.fail("s3aioFileObject.seek did not return 10") # now on 10 try: await s3c.seek(-1, whence=io.SEEK_SET) except IOException: pass else: self.fail("s3aioFileObject.seek did not raise IOException") # should have failed so still on 10 # the current pointer is on ten (10) if not await s3c.seek(-10, whence=io.SEEK_CUR) == 0: self.fail("s3aioFileObject.seek did not return 0") # now on 0 - should raise an exception if we seek below 0 try: await s3c.seek(-1, whence=io.SEEK_CUR) except IOException: pass else: self.fail("s3aioFileObject.seek did not raise IOException") # still on zero: get the size to seek past it size = await s3c._getsize() try: await s3c.seek(size + 1, whence=io.SEEK_CUR) except IOException: pass else: self.fail("s3aioFileObject.seek did not raise IOException") # still on zero - seek from the end try: await s3c.seek(size + 1, whence=io.SEEK_END) except IOException: pass else: self.fail("s3aioFileObject.seek did not raise IOException") # still on 0 - seek backwards from the end try: await s3c.seek(-1, whence=io.SEEK_END) except IOException: pass else: self.fail("s3aioFileObject.seek did not raise IOException") if await s3c.seek(10, whence=io.SEEK_END) != size - 10: self.fail( "s3aioFileObject.seek did not return {}".format(size - 10))