use absolute imports of exception classes (fixes tests)
This commit is contained in:
parent
73796f3e54
commit
20fce9acd8
@ -7,17 +7,17 @@ import logging
|
|||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
|
|
||||||
import migrate
|
import migrate
|
||||||
from migrate import exceptions
|
|
||||||
from migrate.versioning import genmodel, schemadiff
|
from migrate.versioning import genmodel, schemadiff
|
||||||
from migrate.versioning.config import operations
|
from migrate.versioning.config import operations
|
||||||
from migrate.versioning.template import Template
|
from migrate.versioning.template import Template
|
||||||
from migrate.versioning.script import base
|
from migrate.versioning.script import base
|
||||||
from migrate.versioning.util import import_path, load_model, with_engine
|
from migrate.versioning.util import import_path, load_model, with_engine
|
||||||
|
from migrate.exceptions import MigrateDeprecationWarning, InvalidScriptError, ScriptError
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
__all__ = ['PythonScript']
|
__all__ = ['PythonScript']
|
||||||
|
|
||||||
|
|
||||||
class PythonScript(base.BaseScript):
|
class PythonScript(base.BaseScript):
|
||||||
"""Base for Python scripts"""
|
"""Base for Python scripts"""
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ class PythonScript(base.BaseScript):
|
|||||||
try:
|
try:
|
||||||
assert callable(module.upgrade)
|
assert callable(module.upgrade)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
raise exceptions.InvalidScriptError(path + ': %s' % str(e))
|
raise InvalidScriptError(path + ': %s' % str(e))
|
||||||
return module
|
return module
|
||||||
|
|
||||||
def preview_sql(self, url, step, **args):
|
def preview_sql(self, url, step, **args):
|
||||||
@ -131,7 +131,7 @@ class PythonScript(base.BaseScript):
|
|||||||
elif step < 0:
|
elif step < 0:
|
||||||
op = 'downgrade'
|
op = 'downgrade'
|
||||||
else:
|
else:
|
||||||
raise exceptions.ScriptError("%d is not a valid step" % step)
|
raise ScriptError("%d is not a valid step" % step)
|
||||||
|
|
||||||
funcname = base.operations[op]
|
funcname = base.operations[op]
|
||||||
script_func = self._func(funcname)
|
script_func = self._func(funcname)
|
||||||
@ -140,7 +140,7 @@ class PythonScript(base.BaseScript):
|
|||||||
script_func(engine)
|
script_func(engine)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
warnings.warn("upgrade/downgrade functions must accept engine"
|
warnings.warn("upgrade/downgrade functions must accept engine"
|
||||||
" parameter (since version > 0.5.4)", exceptions.MigrateDeprecationWarning)
|
" parameter (since version > 0.5.4)", MigrateDeprecationWarning)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -155,5 +155,5 @@ class PythonScript(base.BaseScript):
|
|||||||
def _func(self, funcname):
|
def _func(self, funcname):
|
||||||
if not hasattr(self.module, funcname):
|
if not hasattr(self.module, funcname):
|
||||||
msg = "Function '%s' is not defined in this script"
|
msg = "Function '%s' is not defined in this script"
|
||||||
raise exceptions.ScriptError(msg % funcname)
|
raise ScriptError(msg % funcname)
|
||||||
return getattr(self.module, funcname)
|
return getattr(self.module, funcname)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user