give the ContainerVersionError exceptions a nice str

This commit is contained in:
Jean-Paul Calderone 2021-11-16 18:32:35 -05:00
parent 3a8432713f
commit e8adca40ab
2 changed files with 9 additions and 0 deletions

View File

@ -21,6 +21,12 @@ class UnknownContainerVersionError(Exception):
self.filename = filename
self.version = version
def __str__(self):
return "sharefile {!r} had unexpected version {!r}".format(
self.filename,
self.version,
)
class UnknownMutableContainerVersionError(UnknownContainerVersionError):
pass

View File

@ -651,6 +651,7 @@ class Server(unittest.TestCase):
ss.remote_get_buckets, b"si1")
self.assertEqual(e.filename, fn)
self.assertEqual(e.version, 0)
self.assertIn("had unexpected version 0", str(e))
def test_disconnect(self):
# simulate a disconnection
@ -1136,6 +1137,8 @@ class MutableServer(unittest.TestCase):
read, b"si1", [0], [(0,10)])
self.assertEqual(e.filename, fn)
self.assertTrue(e.version.startswith(b"BAD MAGIC"))
self.assertIn("had unexpected version", str(e))
self.assertIn("BAD MAGIC", str(e))
def test_container_size(self):
ss = self.create("test_container_size")