Skip to content

Commit

Permalink
Incorporate feedback and make the tests run under Python3. Notably, t…
Browse files Browse the repository at this point in the history
…he Grand Exception Unification in Python 3.3 means that IOError is a synonym for OSError in those versions, but not before; deal with this by catching both types and throwing OSError in the doctests (because that's how it prints). Fix #21. Fix #22.
  • Loading branch information
jamadden committed May 21, 2015
1 parent 69d72b2 commit 4dcb6d1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/ZODB/FileStorage/fspack.py
Expand Up @@ -435,7 +435,7 @@ def close_files_remove():
self._copier = PackCopier(self._tfile, self.index, self.tindex)

ipos, opos = self.copyToPacktime()
except IOError:
except (OSError, IOError):
# most probably ran out of disk space or some other IO error
close_files_remove()
raise # don't succeed silently
Expand Down Expand Up @@ -482,7 +482,7 @@ def close_files_remove():
self.blob_removed.close()

return pos
except IOError:
except (OSError, IOError):
# most probably ran out of disk space or some other IO error
close_files_remove()
if self.locked:
Expand Down
28 changes: 14 additions & 14 deletions src/ZODB/FileStorage/tests.py
Expand Up @@ -195,7 +195,7 @@ def pack_disk_full_copyToPacktime():
>>> fs = ZODB.FileStorage.FileStorage('data.fs')
>>> db = ZODB.DB(fs)
>>> conn = db.open()
>>> conn.root()[1] = u'foobar'
>>> conn.root()[1] = 'foobar'
>>> transaction.commit()
patch `copyToPacktime` to fail
Expand All @@ -204,17 +204,17 @@ def pack_disk_full_copyToPacktime():
>>> save_copyToPacktime = fspack.FileStoragePacker.copyToPacktime
>>> def failing_copyToPacktime(self):
... self._tfile.write('somejunkdata')
... raise IOError("No space left on device")
... self._tfile.write(b'somejunkdata')
... raise OSError("No space left on device")
>>> fspack.FileStoragePacker.copyToPacktime = failing_copyToPacktime
pack -- it still raises `IOError`
pack -- it still raises `OSError`
>>> db.pack(time.time()+1)
Traceback (most recent call last):
...
IOError: No space left on device
OSError: No space left on device
`data.fs.pack` must not exist
Expand All @@ -233,7 +233,7 @@ def pack_disk_full_copyToPacktime():
>>> db = ZODB.DB(fs)
>>> conn = db.open()
>>> conn.root()[1]
u'foobar'
'foobar'
>>> db.close()
"""

Expand All @@ -247,7 +247,7 @@ def pack_disk_full_copyRest():
>>> fs = ZODB.FileStorage.FileStorage('data.fs')
>>> db = ZODB.DB(fs)
>>> conn = db.open()
>>> conn.root()[1] = u'foobar'
>>> conn.root()[1] = 'foobar'
>>> transaction.commit()
patch `copyToPacktime` to add one more transaction
Expand All @@ -258,7 +258,7 @@ def pack_disk_full_copyRest():
>>> def patched_copyToPacktime(self):
... res = save_copyToPacktime(self)
... conn2 = db.open()
... conn2.root()[2] = u'another bar'
... conn2.root()[2] = 'another bar'
... transaction.commit()
... return res
Expand All @@ -269,17 +269,17 @@ def pack_disk_full_copyRest():
>>> save_copyRest = fspack.FileStoragePacker.copyRest
>>> def failing_copyRest(self, ipos):
... self._tfile.write('somejunkdata')
... raise IOError("No space left on device")
... self._tfile.write(b'somejunkdata')
... raise OSError("No space left on device")
>>> fspack.FileStoragePacker.copyRest = failing_copyRest
pack -- it still raises `IOError`
pack -- it still raises `OSError`
>>> db.pack(time.time()+1)
Traceback (most recent call last):
...
IOError: No space left on device
OSError: No space left on device
`data.fs.pack` must not exist
Expand All @@ -299,9 +299,9 @@ def pack_disk_full_copyRest():
>>> db = ZODB.DB(fs)
>>> conn = db.open()
>>> conn.root()[1]
u'foobar'
'foobar'
>>> conn.root()[2]
u'another bar'
'another bar'
>>> db.close()
"""

Expand Down

0 comments on commit 4dcb6d1

Please sign in to comment.