Rev 71: Merge the testscenarios changes to trunk. in http://bazaar.launchpad.net/+branch/u1db

John Arbash Meinel john at arbash-meinel.com
Thu Oct 13 10:47:24 UTC 2011


At http://bazaar.launchpad.net/+branch/u1db

------------------------------------------------------------
revno: 71 [merge]
revision-id: john at arbash-meinel.com-20111013104659-vha9rpr2d9nojfs1
parent: john at arbash-meinel.com-20111013103356-6zm4bv7ajekcz3cc
parent: john at arbash-meinel.com-20111013104506-tljskgkslktlvnkh
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: u1db
timestamp: Thu 2011-10-13 12:46:59 +0200
message:
  Merge the testscenarios changes to trunk.
modified:
  Makefile                       makefile-20110907101001-ow74diiul7837hkb-1
  u1db/tests/__init__.py         __init__.py-20110907100834-dekceojbjm2ken0c-5
  u1db/tests/test_backends.py    test_client.py-20110907100834-dekceojbjm2ken0c-6
-------------- next part --------------
=== modified file 'Makefile'
--- a/Makefile	2011-09-12 14:42:00 +0000
+++ b/Makefile	2011-10-13 10:45:06 +0000
@@ -2,4 +2,4 @@
 .PHONY: check
 
 check:
-	nosetests u1db
+	python -m testtools.run discover

=== modified file 'u1db/tests/__init__.py'
--- a/u1db/tests/__init__.py	2011-10-13 10:33:56 +0000
+++ b/u1db/tests/__init__.py	2011-10-13 10:46:59 +0000
@@ -15,4 +15,20 @@
 """Test infrastructure for U1DB Client"""
 
 
-from testtools import TestCase
+import testscenarios
+import testtools
+
+
+TestCase = testtools.TestCase
+
+
+def load_with_scenarios(loader, standard_tests, pattern):
+    """Load the tests in a given module.
+
+    This just applies testscenarios.generate_scenarios to all the tests that
+    are present. We do it at load time rather than at run time, because it
+    plays nicer with various tools.
+    """
+    suite = loader.suiteClass()
+    suite.addTests(testscenarios.generate_scenarios(standard_tests))
+    return suite

=== modified file 'u1db/tests/test_backends.py'
--- a/u1db/tests/test_backends.py	2011-10-13 10:33:56 +0000
+++ b/u1db/tests/test_backends.py	2011-10-13 10:46:59 +0000
@@ -14,7 +14,6 @@
 
 """The Client class for U1DB."""
 
-
 import u1db
 from u1db import (
     tests,
@@ -29,10 +28,27 @@
 simple_doc = '{"key": "value"}'
 
 
-class DatabaseBaseTests(object):
-
-    def create_database(self, machine_id):
-        raise NotImplementedError(self.create_database)
+def create_memory_database(machine_id):
+    return inmemory.InMemoryDatabase(machine_id)
+
+
+def create_sqlite_database(machine_id):
+    db = sqlite_backend.SQLiteDatabase(':memory:')
+    db._set_machine_id(machine_id)
+    return db
+
+
+class DatabaseBaseTests(tests.TestCase):
+
+    create_database = None
+    scenarios = [
+        ('mem', {'create_database': create_memory_database}),
+        ('sqlite', {'create_database': create_sqlite_database}),
+        ]
+
+
+    def shortDescription(self):
+        return self.id()
 
     def close_database(self, database):
         """Close the database that was opened by create_database.
@@ -49,20 +65,6 @@
         super(DatabaseBaseTests, self).tearDown()
 
 
-class InMemoryDatabaseMixin(object):
-
-    def create_database(self, machine_id):
-        return inmemory.InMemoryDatabase(machine_id)
-
-
-class SQLiteDatabaseMixin(object):
-
-    def create_database(self, machine_id):
-        db = sqlite_backend.SQLiteDatabase(':memory:')
-        db._set_machine_id(machine_id)
-        return db
-
-
 class DatabaseTests(DatabaseBaseTests):
 
     def test_create_doc_allocating_doc_id(self):
@@ -231,16 +233,6 @@
         self.assertEqual(([], [], 2), result)
 
 
-class TestInMemoryDatabase(InMemoryDatabaseMixin, DatabaseTests,
-                           tests.TestCase):
-    pass
-
-
-class TestSQLiteDatabase(SQLiteDatabaseMixin, DatabaseTests,
-                         tests.TestCase):
-    pass
-
-
 class DatabaseIndexTests(DatabaseBaseTests):
 
     def test_create_index(self):
@@ -335,16 +327,6 @@
         self.assertEqual([], self.c.get_from_index('test-idx', [('value',)]))
 
 
-class TestInMemoryDatabaseIndexes(InMemoryDatabaseMixin, DatabaseIndexTests,
-                                  tests.TestCase):
-    pass
-
-
-class TestSQLiteDatabaseIndexes(SQLiteDatabaseMixin, DatabaseIndexTests,
-                                tests.TestCase):
-    pass
-
-
 class DatabaseSyncTests(DatabaseBaseTests):
 
     def setUp(self):
@@ -652,12 +634,5 @@
                          self.c1.get_doc_conflicts(doc_id))
 
 
-class TestInMemoryDatabaseSync(InMemoryDatabaseMixin, DatabaseSyncTests,
-                               tests.TestCase):
-    pass
-
-
-class TestSQLiteDatabaseSync(SQLiteDatabaseMixin, DatabaseSyncTests,
-                             tests.TestCase):
-    pass
-
+# Use a custom loader to apply the scenarios at load time.
+load_tests = tests.load_with_scenarios



More information about the bazaar-commits mailing list