[CalendarServer-changes] [14508] CalendarServer/trunk/txdav/common/datastore/test

source_changes at macosforge.org source_changes at macosforge.org
Thu Mar 5 10:27:14 PST 2015


Revision: 14508
          http://trac.calendarserver.org//changeset/14508
Author:   wsanchez at apple.com
Date:     2015-03-05 10:27:14 -0800 (Thu, 05 Mar 2015)
Log Message:
-----------
Remove trivial uses of inlineCallbacks.
Lint.

Modified Paths:
--------------
    CalendarServer/trunk/txdav/common/datastore/test/test_sql.py
    CalendarServer/trunk/txdav/common/datastore/test/util.py

Modified: CalendarServer/trunk/txdav/common/datastore/test/test_sql.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/test/test_sql.py	2015-03-05 02:41:22 UTC (rev 14507)
+++ CalendarServer/trunk/txdav/common/datastore/test/test_sql.py	2015-03-05 18:27:14 UTC (rev 14508)
@@ -71,9 +71,9 @@
         txn = self.transactionUnderTest()
         cs = schema.CALENDARSERVER
         version = (yield Select(
-            [cs.VALUE, ],
+            [cs.VALUE],
             From=cs,
-            Where=cs.NAME == 'VERSION',
+            Where=cs.NAME == "VERSION",
         ).on(txn))
         self.assertNotEqual(version, None)
         self.assertEqual(len(version), 1)

Modified: CalendarServer/trunk/txdav/common/datastore/test/util.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/test/util.py	2015-03-05 02:41:22 UTC (rev 14507)
+++ CalendarServer/trunk/txdav/common/datastore/test/util.py	2015-03-05 18:27:14 UTC (rev 14508)
@@ -108,10 +108,13 @@
     def __init__(self, count=0):
         self.sharedService = None
         self.currentTestID = None
-        self.sharedDBPath = "_test_sql_db" + str(os.getpid()) + ("-{}".format(count) if count else "")
         self.ampPort = config.WorkQueue.ampPort + count
 
+        self.sharedDBPath = "_test_sql_db-{}-{}".format(
+            os.getpid(), count
+        )
 
+
     def createService(self, serviceFactory):
         """
         Create a L{PostgresService} to use for building a store.
@@ -157,7 +160,10 @@
         return cds
 
 
-    def buildStore(self, testCase, notifierFactory, directoryService=None, homes=None, enableJobProcessing=True):
+    def buildStore(
+        self, testCase, notifierFactory,
+        directoryService=None, homes=None, enableJobProcessing=True,
+    ):
         """
         Do the necessary work to build a store for a particular test case.
 
@@ -169,34 +175,45 @@
         # The directory will be given to us later via setDirectoryService
         if self.sharedService is None:
             ready = Deferred()
+
             def getReady(connectionFactory, storageService):
                 self.makeAndCleanStore(
-                    testCase, notifierFactory, directoryService, attachmentRoot, enableJobProcessing
+                    testCase, notifierFactory, directoryService,
+                    attachmentRoot, enableJobProcessing
                 ).chainDeferred(ready)
                 return Service()
+
             self.sharedService = self.createService(getReady)
             self.sharedService.startService()
+
             def startStopping():
                 log.info("Starting stopping.")
                 self.sharedService.unpauseMonitor()
                 return self.sharedService.stopService()
-            reactor.addSystemEventTrigger(#@UndefinedVariable
+
+            reactor.addSystemEventTrigger(
                 "before", "shutdown", startStopping)
             result = ready
         else:
             result = self.makeAndCleanStore(
-                testCase, notifierFactory, directoryService, attachmentRoot, enableJobProcessing
+                testCase, notifierFactory, directoryService,
+                attachmentRoot, enableJobProcessing
             )
+
         def cleanUp():
             def stopit():
                 self.sharedService.pauseMonitor()
             return deferLater(reactor, 0.1, stopit)
+
         testCase.addCleanup(cleanUp)
         return result
 
 
     @inlineCallbacks
-    def makeAndCleanStore(self, testCase, notifierFactory, directoryService, attachmentRoot, enableJobProcessing=True):
+    def makeAndCleanStore(
+        self, testCase, notifierFactory, directoryService,
+        attachmentRoot, enableJobProcessing=True
+    ):
         """
         Create a L{CommonDataStore} specific to the given L{TestCase}.
 
@@ -213,14 +230,19 @@
         attachmentRoot.createDirectory()
 
         currentTestID = testCase.id()
-        cp = ConnectionPool(self.sharedService.produceConnection, maxConnections=4)
+        cp = ConnectionPool(
+            self.sharedService.produceConnection, maxConnections=4
+        )
         quota = deriveQuota(testCase)
         store = CommonDataStore(
             cp.connection,
             {"push": notifierFactory} if notifierFactory is not None else {},
             directoryService,
             attachmentRoot,
-            "https://example.com/calendars/__uids__/%(home)s/attachments/%(name)s",
+            (
+                "https://example.com/calendars/__uids__/"
+                "%(home)s/attachments/%(name)s"
+            ),
             quota=quota
         )
         store.label = currentTestID
@@ -279,11 +301,13 @@
         # table' statements are issued, so it's not possible to reference a
         # later table.  Therefore it's OK to drop them in the (reverse) order
         # that they happen to be in.
-        tables = [t.name for t in schema.model.tables #@UndefinedVariable
-                  # All tables with rows _in_ the schema are populated
-                  # exclusively _by_ the schema and shouldn't be manipulated
-                  # while the server is running, so we leave those populated.
-                  if not t.schemaRows][::-1]
+        tables = [
+            t.name for t in schema.model.tables
+            # All tables with rows _in_ the schema are populated
+            # exclusively _by_ the schema and shouldn't be manipulated
+            # while the server is running, so we leave those populated.
+            if not t.schemaRows
+        ][::-1]
 
         for table in tables:
             try:
@@ -446,24 +470,32 @@
             try:
                 if config.RestrictCalendarsToOneComponentType:
                     for name in ical.allowedStoreComponents:
-                        yield home.removeCalendarWithName(home._componentCalendarName[name])
+                        yield home.removeCalendarWithName(
+                            home._componentCalendarName[name]
+                        )
                 else:
                     yield home.removeCalendarWithName("calendar")
                 yield home.removeCalendarWithName("inbox")
             except NoSuchHomeChildError:
                 pass
+
             for calendarName in calendars:
                 calendarObjNames = calendars[calendarName]
+
                 if calendarObjNames is not None:
                     # XXX should not be yielding!  this SQL will be executed
                     # first!
                     yield home.createCalendarWithName(calendarName)
                     calendar = yield home.calendarWithName(calendarName)
+
                     for objectName in calendarObjNames:
                         objData, metadata = calendarObjNames[objectName]
+
                         yield calendar._createCalendarObjectWithNameInternal(
                             objectName,
-                            VComponent.fromString(updateToCurrentYear(objData)),
+                            VComponent.fromString(
+                                updateToCurrentYear(objData)
+                            ),
                             internal_state=ComponentUpdateState.RAW,
                             options=metadata,
                         )
@@ -474,7 +506,8 @@
 
 def updateToCurrentYear(data):
     """
-    Update the supplied iCalendar data so that all dates are updated to the current year.
+    Update the supplied iCalendar data so that all dates are updated to the
+    current year.
     """
 
     nowYear = DateTime.getToday().getYear()
@@ -486,7 +519,8 @@
 
 def componentUpdate(data):
     """
-    Update the supplied iCalendar data so that all dates are updated to the current year.
+    Update the supplied iCalendar data so that all dates are updated to the
+    current year.
     """
 
     if len(relativeDateSubstitutions) == 0:
@@ -533,10 +567,12 @@
                     calendar = yield home.calendarWithName(calendarName)
                     for objectName in calendarObjNames:
                         md5 = calendarObjNames[objectName]
-                        obj = yield calendar.calendarObjectWithName(
-                            objectName,
+                        obj = (
+                            yield calendar.calendarObjectWithName(objectName)
+                        ),
+                        obj.properties()[md5key] = (
+                            TwistedGETContentMD5.fromString(md5)
                         )
-                        obj.properties()[md5key] = TwistedGETContentMD5.fromString(md5)
     yield populateTxn.commit()
 
 
@@ -567,7 +603,9 @@
                     # XXX should not be yielding!  this SQL will be executed
                     # first!
                     yield home.createAddressBookWithName(addressbookName)
-                    addressbook = yield home.addressbookWithName(addressbookName)
+                    addressbook = (
+                        yield home.addressbookWithName(addressbookName)
+                    )
                     for objectName in addressbookObjNames:
                         objData = addressbookObjNames[objectName]
                         yield addressbook.createAddressBookObjectWithName(
@@ -598,13 +636,17 @@
                 if addressbookObjNames is not None:
                     # XXX should not be yielding!  this SQL will be executed
                     # first!
-                    addressbook = yield home.addressbookWithName(addressbookName)
+                    addressbook = (
+                        yield home.addressbookWithName(addressbookName)
+                    )
                     for objectName in addressbookObjNames:
                         md5 = addressbookObjNames[objectName]
                         obj = yield addressbook.addressbookObjectWithName(
                             objectName,
                         )
-                        obj.properties()[md5key] = TwistedGETContentMD5.fromString(md5)
+                        obj.properties()[md5key] = (
+                            TwistedGETContentMD5.fromString(md5)
+                        )
     yield populateTxn.commit()
 
 
@@ -627,8 +669,8 @@
 
 
 def buildTestDirectory(
-    store, dataRoot, accounts=None, resources=None, augments=None, proxies=None,
-    serversDB=None, cacheSeconds=0
+    store, dataRoot, accounts=None, resources=None, augments=None,
+    proxies=None, serversDB=None, cacheSeconds=0,
 ):
     """
     @param store: the store for the directory to use
@@ -738,7 +780,8 @@
     @inlineCallbacks
     def buildStoreAndDirectory(
         self, accounts=None, resources=None, augments=None, proxies=None,
-        extraUids=None, serversDB=None, cacheSeconds=0, storeBuilder=theStoreBuilder
+        extraUids=None, serversDB=None, cacheSeconds=0,
+        storeBuilder=theStoreBuilder,
     ):
 
         self.serverRoot = self.mktemp()
@@ -791,10 +834,12 @@
         if not os.path.exists(config.LogRoot):
             os.makedirs(config.LogRoot)
 
-        # Work queues for implicit scheduling slow down tests a lot and require them all to add
-        # "waits" for work to complete. Rewriting all the current tests to do that is not practical
-        # right now, so we will turn this off by default. Instead we will have a set of tests dedicated
-        # to work queue-based scheduling which will patch this option to True.
+        # Work queues for implicit scheduling slow down tests a lot and require
+        # them all to add "waits" for work to complete.
+        # Rewriting all the current tests to do that is not practical right
+        # now, so we will turn this off by default.
+        # Instead we will have a set of tests dedicated to work queue-based
+        # scheduling which will patch this option to True.
         config.Scheduling.Options.WorkQueues.Enabled = False
 
         self.config = config
@@ -828,20 +873,25 @@
         """
         if self.savedStore is None:
             self.savedStore = self.storeUnderTest()
+
         self.counter += 1
+
         if txn is None:
             txn = self.savedStore.newTransaction(
                 self.id() + " #" + str(self.counter)
             )
         else:
             txn._label = self.id() + " #" + str(self.counter)
+
         @inlineCallbacks
         def maybeCommitThis():
             try:
                 yield txn.commit()
             except AlreadyFinishedError:
                 pass
+
         self.addCleanup(maybeCommitThis)
+
         return txn
 
 
@@ -872,14 +922,13 @@
         return self.store
 
 
-    @inlineCallbacks
     def homeUnderTest(self, txn=None, name="home1", create=False):
         """
         Get the calendar home detailed by C{requirements['home1']}.
         """
         if txn is None:
             txn = self.transactionUnderTest()
-        returnValue((yield txn.calendarHomeWithUID(name, create=create)))
+        return txn.calendarHomeWithUID(name, create=create)
 
 
     @inlineCallbacks
@@ -887,19 +936,24 @@
         """
         Get the calendar detailed by C{requirements['home1']['calendar_1']}.
         """
-        returnValue((
-            yield (yield self.homeUnderTest(txn, home)).calendarWithName(name)
-        ))
+        home = yield self.homeUnderTest(txn, home)
+        calendar = yield home.calendarWithName(name)
+        returnValue(calendar)
 
 
     @inlineCallbacks
-    def calendarObjectUnderTest(self, txn=None, name="1.ics", calendar_name="calendar_1", home="home1"):
+    def calendarObjectUnderTest(
+        self, txn=None, name="1.ics", calendar_name="calendar_1", home="home1"
+    ):
         """
         Get the calendar detailed by
         C{requirements[home][calendar_name][name]}.
         """
-        returnValue((yield (yield self.calendarUnderTest(txn, name=calendar_name, home=home))
-                     .calendarObjectWithName(name)))
+        calendar = yield self.calendarUnderTest(
+            txn, name=calendar_name, home=home
+        )
+        object = yield calendar.calendarObjectWithName(name)
+        returnValue(object)
 
 
     def addressbookHomeUnderTest(self, txn=None, name="home1"):
@@ -914,52 +968,58 @@
     @inlineCallbacks
     def addressbookUnderTest(self, txn=None, name="addressbook", home="home1"):
         """
-        Get the addressbook detailed by C{requirements['home1']['addressbook']}.
+        Get the addressbook detailed by
+        C{requirements['home1']['addressbook']}.
         """
-        returnValue((
-            yield (yield self.addressbookHomeUnderTest(txn=txn, name=home)).addressbookWithName(name)
-        ))
+        home = yield self.addressbookHomeUnderTest(txn=txn, name=home)
+        addressbook = yield home.addressbookWithName(name)
+        returnValue(addressbook)
 
 
     @inlineCallbacks
-    def addressbookObjectUnderTest(self, txn=None, name="1.vcf", addressbook_name="addressbook", home="home1"):
+    def addressbookObjectUnderTest(
+        self, txn=None, name="1.vcf",
+        addressbook_name="addressbook", home="home1",
+    ):
         """
         Get the addressbook detailed by
         C{requirements['home1']['addressbook']['1.vcf']}.
         """
-        returnValue((yield (yield self.addressbookUnderTest(txn=txn, name=addressbook_name, home=home))
-                    .addressbookObjectWithName(name)))
+        addressBook = yield self.addressbookUnderTest(
+            txn=txn, name=addressbook_name, home=home
+        )
+        object = yield addressBook.addressbookObjectWithName(name)
+        returnValue(object)
 
 
-    @inlineCallbacks
     def userRecordWithShortName(self, shortname):
-        record = yield self.directory.recordWithShortName(self.directory.recordType.user, shortname)
-        returnValue(record)
+        return self.directory.recordWithShortName(
+            self.directory.recordType.user, shortname
+        )
 
 
     @inlineCallbacks
     def userUIDFromShortName(self, shortname):
-        record = yield self.directory.recordWithShortName(self.directory.recordType.user, shortname)
+        record = yield self.directory.recordWithShortName(
+            self.directory.recordType.user, shortname
+        )
         returnValue(record.uid if record is not None else None)
 
 
-    @inlineCallbacks
     def addRecordFromFields(self, fields):
         updatedRecord = DirectoryRecord(self.directory, fields)
-        yield self.directory.updateRecords((updatedRecord,), create=True)
+        return self.directory.updateRecords((updatedRecord,), create=True)
 
 
-    @inlineCallbacks
     def removeRecord(self, uid):
-        yield self.directory.removeRecords([uid])
+        return self.directory.removeRecords([uid])
 
 
-    @inlineCallbacks
     def changeRecord(self, record, fieldname, value):
         fields = record.fields.copy()
         fields[fieldname] = value
         updatedRecord = DirectoryRecord(self.directory, fields)
-        yield self.directory.updateRecords((updatedRecord,))
+        return self.directory.updateRecords((updatedRecord,))
 
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150305/6bd3546d/attachment-0001.html>


More information about the calendarserver-changes mailing list