From bebe86584804822d3da03fef67bef1d51e753e42 Mon Sep 17 00:00:00 2001 From: iElectric Date: Sat, 6 Jun 2009 12:20:47 +0000 Subject: [PATCH] make @usedb work correctly --- test/fixture/base.py | 17 ++++++++--------- test/fixture/database.py | 19 ++++++++----------- test/versioning/test_script.py | 2 +- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/test/fixture/base.py b/test/fixture/base.py index dd81033..c64df7b 100644 --- a/test/fixture/base.py +++ b/test/fixture/base.py @@ -1,6 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +import re import unittest from nose.tools import raises, eq_ @@ -18,15 +19,13 @@ class Base(unittest.TestCase): """Compares two strings that should be\ identical except for whitespace """ - def createLines(s): - s = s.replace(' ', '') - lines = s.split('\n') - return filter(None, lines) - lines1 = createLines(v1) - lines2 = createLines(v2) - self.assertEquals(len(lines1), len(lines2)) - for line1, line2 in zip(lines1, lines2): - self.assertEquals(line1, line2) + def strip_whitespace(s): + return re.sub(r'\s', '', s) + + line1 = strip_whitespace(v1) + line2 = strip_whitespace(v2) + + self.assertEquals(line1, line2, "%s != %s" % (v1, v2)) def ignoreErrors(self, func, *p,**k): """Call a function, ignoring any exceptions""" diff --git a/test/fixture/database.py b/test/fixture/database.py index 5a04e94..b948278 100644 --- a/test/fixture/database.py +++ b/test/fixture/database.py @@ -68,15 +68,12 @@ def usedb(supported=None, not_supported=None): my_urls = [url for url in urls if is_supported(url, supported, not_supported)] - def dec(func): - def entangle(self): - for url in my_urls: - self._setup(url) - yield func, self - self._teardown() - entangle.__name__ = func.__name__ - entangle.__doc__ = func.__doc__ - return entangle + @decorator + def dec(f, self, *a, **kw): + for url in my_urls: + self._setup(url) + f(self, *a, **kw) + self._teardown() return dec @@ -88,7 +85,7 @@ class DB(Base): level = TXN - def _engineInfo(self,url=None): + def _engineInfo(self, url=None): if url is None: url = self.url return url @@ -99,7 +96,7 @@ class DB(Base): def _teardown(self): self._disconnect() - def _connect(self,url): + def _connect(self, url): self.url = url self.engine = engines[url] self.meta = MetaData(bind=self.engine) diff --git a/test/versioning/test_script.py b/test/versioning/test_script.py index ab48a47..7fabece 100644 --- a/test/versioning/test_script.py +++ b/test/versioning/test_script.py @@ -9,7 +9,7 @@ from migrate.versioning import exceptions, version from test import fixture -class TestPyScript(fixture.Pathed): +class TestPyScript(fixture.Pathed, fixture.DB): cls = PythonScript def test_create(self): """We can create a migration script"""