rearange tests

This commit is contained in:
iElectric 2009-06-07 00:05:51 +00:00
parent 14fe28bc8c
commit 820da74334
12 changed files with 47 additions and 75 deletions

3
TODO
View File

@ -1,8 +1,5 @@
- better MySQL support
- fix unit tests for other databases than PostgreSQL (MySQL and SQLite
fail at test_changeset.test_fk(..))
- document dotted_name parsing changes
- document shell parsing
- document engine parameters usage/parsing
- better SQL scripts support (testing, source viewing)

View File

@ -319,7 +319,7 @@ database you're working with::
'sqlite'
Writings .sql scripts
------------
---------------------
You might prefer to write your change scripts in SQL, as .sql files,
rather than as Python scripts. SQLAlchemy-migrate can work with that::

View File

@ -1,8 +1,14 @@
"""
This module provides an external API to the versioning system.
Used by the shell utility; could also be used by other scripts
.. versionchanged:: 0.4.5
``--preview_sql`` displays source file when using SQL scripts. If Python script is used,
it runs the action with mocked engine and returns captured SQL statements.
.. versionchanged:: 0.4.5
Deprecated ``--echo`` parameter in favour of new :func:`migrate.versioning.util.construct_engine` behavior.
"""
# Dear migrate developers,
#
# please do not comment this module using sphinx syntax because its

View File

@ -47,23 +47,6 @@ class NoSuchTableError(ControlledSchemaError):
pass
class LogSqlError(Error):
"""A SQLError, with a traceback of where that statement was logged."""
def __init__(self, sqlerror, entry):
Exception.__init__(self)
self.sqlerror = sqlerror
self.entry = entry
def __str__(self):
"""SQL error in statement:
%s
Traceback from change script:
%s%s""" % (self.entry,
''.join(traceback.format_list(self.entry.traceback)),
self.sqlerror)
class PathError(Error):
"""Base class for path errors."""
pass

View File

@ -5,9 +5,9 @@
import os
import shutil
from migrate.versioning import exceptions
from migrate.versioning.base import *
from migrate.versioning.util import KeyedInstance
from migrate.versioning import exceptions
class Pathed(KeyedInstance):
@ -41,7 +41,6 @@ class Pathed(KeyedInstance):
Parameters: the child object; the path to this object (its
parent)
"""
pass
@classmethod
def _parent_path(cls, path):

View File

@ -102,12 +102,11 @@ class PythonScript(base.BaseScript):
migrate.migrate_engine = None
#migrate.run.migrate_engine = migrate.migrate_engine = None
def _get_module(self):
@property
def module(self):
if not hasattr(self,'_module'):
self._module = self.verify_module(self.path)
return self._module
module = property(_get_module)
def _func(self, funcname):
fn = getattr(self.module, funcname, None)

View File

@ -47,8 +47,6 @@ class PassiveOptionParser(OptionParser):
elif self.allow_interspersed_args:
largs.append(arg)
del rargs[0]
else:
return
def main(argv=None, **kwargs):
"""kwargs are default options that can be overriden with passing --some_option to cmdline"""
@ -157,5 +155,5 @@ def main(argv=None, **kwargs):
parser.print_help()
parser.error(e.args[0])
if __name__=="__main__":
if __name__ == "__main__":
main()

View File

@ -13,7 +13,13 @@ from migrate.versioning.util.importpath import import_path
def load_model(dotted_name):
''' Import module and use module-level variable -- assume model is of form "mod1.mod2:varname". '''
"""Import module and use module-level variable".
:param dotted_name: path to model in form of string: ``some.python.module:Class``
.. versionchanged:: 0.5.4
"""
if isinstance(dotted_name, basestring):
if ':' not in dotted_name:
# backwards compatibility
@ -72,12 +78,14 @@ def catch_known_errors(f, *a, **kw):
def construct_engine(url, **opts):
"""Constructs and returns SQLAlchemy engine.
Currently, there are 2 ways to pass create_engine options to api functions:
Currently, there are 2 ways to pass create_engine options to :mod:`migrate.versioning.api` functions:
* keyword parameters (starting with `engine_arg_*`)
* python dictionary of options (`engine_dict`)
* keyword parameters (starting with ``engine_arg_*``)
* python dictionary of options (``engine_dict``)
NOTE: keyword parameters override `engine_dict` values.
.. note::
keyword parameters override ``engine_dict`` values.
.. versionadded:: 0.5.4
"""

View File

@ -1,25 +1,28 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
class KeyedInstance(object):
"""A class whose instances have a unique identifier of some sort
No two instances with the same unique ID should exist - if we try to create
a second instance, the first should be returned.
"""
# _instances[class][instance]
_instances=dict()
def __new__(cls,*p,**k):
_instances = dict()
def __new__(cls, *p, **k):
instances = cls._instances
clskey = str(cls)
if clskey not in instances:
instances[clskey] = dict()
instances = instances[clskey]
key = cls._key(*p,**k)
key = cls._key(*p, **k)
if key not in instances:
instances[key] = super(KeyedInstance,cls).__new__(cls)
self = instances[key]
return self
instances[key] = super(KeyedInstance, cls).__new__(cls)
return instances[key]
@classmethod
def _key(cls,*p,**k):
def _key(cls, *p, **k):
"""Given a unique identifier, return a dictionary key
This should be overridden by child classes, to specify which parameters
should determine an object's uniqueness
@ -27,10 +30,7 @@ class KeyedInstance(object):
raise NotImplementedError()
@classmethod
def clear(cls,cls2=None):
# Allow cls.clear() as well as niqueInstance.clear(cls)
if cls2 is not None:
cls=cls2
def clear(cls):
# Allow cls.clear() as well as uniqueInstance.clear(cls)
if str(cls) in cls._instances:
del cls._instances[str(cls)]

View File

@ -7,7 +7,7 @@ tag_svn_revision = 1
tag_build = .dev
[nosetests]
pdb = true
#pdb = true
#pdb-failures = true
[aliases]

View File

@ -95,29 +95,5 @@ def upgrade():
self.cls.verify(path)
class TestSqlScript(fixture.Pathed):
def test_selection(self):
"""Verify right sql script is selected"""
# Create empty directory.
path=self.tmp_repos()
os.mkdir(path)
# Create files -- files must be present or you'll get an exception later.
sqlite_upgrade_file = '001_sqlite_upgrade.sql'
default_upgrade_file = '001_default_upgrade.sql'
for file_ in [sqlite_upgrade_file, default_upgrade_file]:
filepath = '%s/%s' % (path, file_)
open(filepath, 'w').close()
ver = version.Version(1, path, [sqlite_upgrade_file])
self.assertEquals(os.path.basename(ver.script('sqlite', 'upgrade').path), sqlite_upgrade_file)
ver = version.Version(1, path, [default_upgrade_file])
self.assertEquals(os.path.basename(ver.script('default', 'upgrade').path), default_upgrade_file)
ver = version.Version(1, path, [sqlite_upgrade_file, default_upgrade_file])
self.assertEquals(os.path.basename(ver.script('sqlite', 'upgrade').path), sqlite_upgrade_file)
ver = version.Version(1, path, [sqlite_upgrade_file, default_upgrade_file])
self.assertEquals(os.path.basename(ver.script('postgres', 'upgrade').path), default_upgrade_file)
pass

View File

@ -12,6 +12,7 @@ from sqlalchemy import MetaData,Table
from migrate.versioning.repository import Repository
from migrate.versioning import genmodel, shell, api
from migrate.versioning.exceptions import *
from test import fixture
@ -103,6 +104,11 @@ class TestShellCommands(Shell):
self.assertSuccess(self.cmd('-h'), runshell=True)
self.assertSuccess(self.cmd('--help'), runshell=True)
self.assertSuccess(self.cmd('help'), runshell=True)
self.assertSuccess(self.cmd('help'))
self.assertRaises(UsageError, api.help)
self.assertRaises(UsageError, api.help, 'foobar')
self.assert_(isinstance(api.help('create'), str))
def test_help_commands(self):
"""Display help on a specific command"""
@ -245,7 +251,7 @@ class TestShellDatabase(Shell, fixture.DB):
def test_wrapped_kwargs(self):
"""Commands with default arguments set by manage.py"""
path_repos = repos = self.tmp_repos()
self.assertSuccess(self.cmd('create', 'repository_name'), repository=path_repos)
self.assertSuccess(self.cmd('create', '--', '--name=repository_name'), repository=path_repos)
self.exitcode(self.cmd('drop_version_control'), url=self.url, repository=path_repos)
self.assertSuccess(self.cmd('version_control'), url=self.url, repository=path_repos)