← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~wgrant/launchpad/cleanup-canonical.lp into lp:launchpad

 

William Grant has proposed merging lp:~wgrant/launchpad/cleanup-canonical.lp into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~wgrant/launchpad/cleanup-canonical.lp/+merge/75180

Clean up canonical.lp's tests. Most of them were testing old ZopelessTransactionManager functionality that is now in Storm, so they've been deleted. test_initZopelessTwice has moved to canonical.database.sqlbase, since the guts of initZopeless lives there.
-- 
https://code.launchpad.net/~wgrant/launchpad/cleanup-canonical.lp/+merge/75180
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~wgrant/launchpad/cleanup-canonical.lp into lp:launchpad.
=== modified file 'lib/canonical/database/tests/test_zopeless_transaction_manager.py'
--- lib/canonical/database/tests/test_zopeless_transaction_manager.py	2011-08-12 11:37:08 +0000
+++ lib/canonical/database/tests/test_zopeless_transaction_manager.py	2011-09-13 13:39:30 +0000
@@ -1,12 +1,19 @@
 # Copyright 2009 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
+import warnings
+
+from storm.zope.interfaces import IZStorm
 from zope.component import getUtility
 
-from storm.zope.interfaces import IZStorm
-
-from canonical.database.sqlbase import ZopelessTransactionManager
-from canonical.testing.layers import LaunchpadZopelessLayer
+from canonical.database.sqlbase import (
+    alreadyInstalledMsg,
+    ZopelessTransactionManager,
+    )
+from canonical.testing.layers import (
+    LaunchpadZopelessLayer,
+    ZopelessDatabaseLayer,
+    )
 from lp.testing import TestCase
 
 
@@ -23,3 +30,41 @@
         new_active_stores = [
             item[0] for item in getUtility(IZStorm).iterstores()]
         self.assertContentEqual(active_stores, new_active_stores)
+
+
+class TestInitZopeless(TestCase):
+
+    layer = ZopelessDatabaseLayer
+
+    def test_initZopelessTwice(self):
+        # Hook the warnings module, so we can verify that we get the expected
+        # warning.  The warnings module has two key functions, warn and
+        # warn_explicit, the first calling the second. You might, therefore,
+        # think that we should hook the second, to catch all warnings in one
+        # place.  However, from Python 2.6, both of these are replaced with
+        # entries into a C extension if available, and the C implementation of
+        # the first will not call a monkeypatched Python implementation of the
+        # second.  Therefore, we hook warn, as is the one actually called by
+        # the particular code we are interested in testing.
+        original_warn = warnings.warn
+        warnings.warn = self.warn_hooked
+        self.warned = False
+        try:
+            # Calling initZopeless with the same arguments twice should return
+            # the exact same object twice, but also emit a warning.
+            try:
+                tm1 = ZopelessTransactionManager.initZopeless(
+                    dbuser='launchpad')
+                tm2 = ZopelessTransactionManager.initZopeless(
+                    dbuser='launchpad')
+                self.failUnless(tm1 is tm2)
+                self.failUnless(self.warned)
+            finally:
+                tm1.uninstall()
+        finally:
+            # Put the warnings module back the way we found it.
+            warnings.warn = original_warn
+
+    def warn_hooked(self, message, category=None, stacklevel=1):
+        self.failUnlessEqual(alreadyInstalledMsg, str(message))
+        self.warned = True

=== modified file 'lib/canonical/lp/ftests/test_zopeless.py'
--- lib/canonical/lp/ftests/test_zopeless.py	2011-09-06 09:03:15 +0000
+++ lib/canonical/lp/ftests/test_zopeless.py	2011-09-13 13:39:30 +0000
@@ -6,196 +6,8 @@
 """
 
 from doctest import DocTestSuite
-from threading import Thread
-import unittest
-import warnings
-
-import psycopg2
-from sqlobject import StringCol, IntCol
-
-from canonical.database.sqlbase import (
-    alreadyInstalledMsg,
-    connect,
-    cursor,
-    SQLBase,
-    )
 from canonical.lp import initZopeless
-from canonical.testing.layers import LaunchpadScriptLayer
-
-
-class MoreBeer(SQLBase):
-    '''Simple SQLObject class used for testing'''
-    # test_sqlos defines a Beer SQLObject already, so we call this one
-    # MoreBeer to avoid confusing SQLObject.
-    name = StringCol(alternateID=True, notNull=True)
-    rating = IntCol(default=None)
-
-
-class TestInitZopeless(unittest.TestCase):
-
-    layer = LaunchpadScriptLayer
-
-    def test_initZopelessTwice(self):
-        # Hook the warnings module, so we can verify that we get the expected
-        # warning.  The warnings module has two key functions, warn and
-        # warn_explicit, the first calling the second. You might, therefore,
-        # think that we should hook the second, to catch all warnings in one
-        # place.  However, from Python 2.6, both of these are replaced with
-        # entries into a C extension if available, and the C implementation of
-        # the first will not call a monkeypatched Python implementation of the
-        # second.  Therefore, we hook warn, as is the one actually called by
-        # the particular code we are interested in testing.
-        original_warn = warnings.warn
-        warnings.warn = self.warn_hooked
-        self.warned = False
-        try:
-            # Calling initZopeless with the same arguments twice should return
-            # the exact same object twice, but also emit a warning.
-            try:
-                tm1 = initZopeless(dbuser='launchpad')
-                tm2 = initZopeless(dbuser='launchpad')
-                self.failUnless(tm1 is tm2)
-                self.failUnless(self.warned)
-            finally:
-                tm1.uninstall()
-        finally:
-            # Put the warnings module back the way we found it.
-            warnings.warn = original_warn
-
-    def warn_hooked(self, message, category=None, stacklevel=1):
-        self.failUnlessEqual(alreadyInstalledMsg, str(message))
-        self.warned = True
-
-
-class TestZopeless(unittest.TestCase):
-
-    layer = LaunchpadScriptLayer
-
-    def setUp(self):
-        self.tm = initZopeless(dbuser='launchpad')
-
-        c = cursor()
-        c.execute("CREATE TABLE morebeer ("
-                  "  id SERIAL PRIMARY KEY,"
-                  "  name text NOT NULL UNIQUE,"
-                  "  rating integer"
-                  ")")
-        self.tm.commit()
-
-    def tearDown(self):
-        self.tm.uninstall()
-
-    def test_simple(self):
-        # Create a few MoreBeers and make sure we can access them
-        b = MoreBeer(name='Victoria Bitter')
-        id1 = b.id
-        b = MoreBeer(name='XXXX')
-        id2 = b.id
-
-        b = MoreBeer.get(id1)
-        b.rating = 3
-        b = MoreBeer.get(id2)
-        b.rating = 2
-
-        b = MoreBeer.get(id1)
-        self.failUnlessEqual(b.rating, 3)
-
-    def test_multipleTransactions(self):
-        # Here we create a MoreBeer and make modifications in a number
-        # of different transactions
-
-        b = MoreBeer(name='Victoria Bitter')
-        id = b.id
-        self.tm.commit()
-
-        b = MoreBeer.get(id)
-        self.failUnlessEqual(b.name, 'Victoria Bitter')
-        b.rating = 4
-        self.tm.commit()
-
-        b = MoreBeer.get(id)
-        self.failUnlessEqual(b.rating, 4)
-        b.rating = 5
-        self.tm.commit()
-
-        b = MoreBeer.get(id)
-        self.failUnlessEqual(b.rating, 5)
-        b.rating = 2
-        self.tm.abort()
-
-        b = MoreBeer.get(id)
-        self.failUnlessEqual(b.rating, 5)
-        b.rating = 4
-        self.tm.commit()
-
-        b = MoreBeer.get(id)
-        self.failUnlessEqual(b.rating, 4)
-
-    def test_threads(self):
-        # Here we create a number of MoreBeers in seperate threads
-        def doit():
-            self.tm.begin()
-            b = MoreBeer(name=beer_name)
-            b.rating = beer_rating
-            self.tm.commit()
-
-        beer_name = 'Victoria Bitter'
-        beer_rating = 4
-        t = Thread(target=doit)
-        t.start()
-        t.join()
-
-        beer_name = 'Singa'
-        beer_rating = 6
-        t = Thread(target=doit)
-        t.start()
-        t.join()
-
-        # And make sure they are both seen
-        beers = MoreBeer.select()
-        self.failUnlessEqual(beers.count(), 2)
-        self.tm.commit()
-
-    def test_exception(self):
-
-        # We have observed if a database transaction ends badly, it is
-        # not reset for future transactions. To test this, we cause
-        # a database exception
-        beer1 = MoreBeer(name='Victoria Bitter')
-        beer1.syncUpdate()
-        try:
-            beer2 = MoreBeer(name='Victoria Bitter')
-            beer2.syncUpdate()
-        except psycopg2.DatabaseError:
-            pass
-        else:
-            self.fail('Unique constraint was not triggered')
-        self.tm.abort()
-
-        # Now start a new transaction and see if we can do anything
-        self.tm.begin()
-        beer3 = MoreBeer(name='Singa')
-        beer3.syncUpdate()
-
-    def test_externalChange(self):
-        # Make a change
-        MoreBeer(name='Victoria Bitter')
-
-        # Commit our local change
-        self.tm.commit()
-
-        # Make another change from a non-SQLObject connection, and commit that
-        conn = connect()
-        cur = conn.cursor()
-        cur.execute("BEGIN TRANSACTION;")
-        cur.execute("UPDATE MoreBeer SET rating=4 "
-                    "WHERE name='Victoria Bitter';")
-        cur.execute("COMMIT TRANSACTION;")
-        cur.close()
-        conn.close()
-
-        # We should now be able to see the external change in our connection
-        self.failUnlessEqual(4, MoreBeer.byName('Victoria Bitter').rating)
+from canonical.testing.layers import ZopelessDatabaseLayer
 
 
 def test_isZopeless():
@@ -217,10 +29,6 @@
 
 
 def test_suite():
-    suite = unittest.TestSuite()
-    suite.addTest(unittest.makeSuite(TestZopeless))
-    suite.addTest(unittest.makeSuite(TestInitZopeless))
     doctests = DocTestSuite()
-    doctests.layer = LaunchpadScriptLayer
-    suite.addTest(doctests)
-    return suite
+    doctests.layer = ZopelessDatabaseLayer
+    return doctests

=== removed directory 'lib/canonical/lp/tests'
=== removed file 'lib/canonical/lp/tests/__init__.py'