Merge "Raise VersionNotFoundError instead of KeyError"
This commit is contained in:
commit
d58469a6ae
@ -27,6 +27,10 @@ class InvalidVersionError(ControlledSchemaError):
|
||||
"""Invalid version number."""
|
||||
|
||||
|
||||
class VersionNotFoundError(KeyError):
|
||||
"""Specified version is not present."""
|
||||
|
||||
|
||||
class DatabaseNotControlledError(ControlledSchemaError):
|
||||
"""Database should be under version control, but it's not."""
|
||||
|
||||
|
@ -103,6 +103,10 @@ class TestVersion(fixture.Pathed):
|
||||
self.assertEqual(coll.latest, 4)
|
||||
self.assertEqual(len(coll.versions), 4)
|
||||
self.assertEqual(coll.version(4), coll.version(coll.latest))
|
||||
# Check for non-existing version
|
||||
self.assertRaises(VersionNotFoundError, coll.version, 5)
|
||||
# Check for the current version
|
||||
self.assertEqual('4', coll.version(4).version)
|
||||
|
||||
coll2 = Collection(self.temp_usable_dir)
|
||||
self.assertEqual(coll.versions, coll2.versions)
|
||||
|
@ -156,11 +156,22 @@ class Collection(pathed.Pathed):
|
||||
self.versions[ver].add_script(filepath)
|
||||
|
||||
def version(self, vernum=None):
|
||||
"""Returns latest Version if vernum is not given.
|
||||
Otherwise, returns wanted version"""
|
||||
"""Returns required version.
|
||||
|
||||
If vernum is not given latest version will be returned otherwise
|
||||
required version will be returned.
|
||||
:raises: : exceptions.VersionNotFoundError if respective migration
|
||||
script file of version is not present in the migration repository.
|
||||
"""
|
||||
if vernum is None:
|
||||
vernum = self.latest
|
||||
return self.versions[VerNum(vernum)]
|
||||
|
||||
try:
|
||||
return self.versions[VerNum(vernum)]
|
||||
except KeyError:
|
||||
raise exceptions.VersionNotFoundError(
|
||||
("Database schema file with version %(args)s doesn't "
|
||||
"exist.") % {'args': VerNum(vernum)})
|
||||
|
||||
@classmethod
|
||||
def clear(cls):
|
||||
|
Loading…
Reference in New Issue
Block a user