← Back to team overview

testtools-dev team mailing list archive

[Merge] lp:~jml/testtools/gather-details-dict-801027 into lp:testtools

 

Jonathan Lange has proposed merging lp:~jml/testtools/gather-details-dict-801027 into lp:testtools.

Requested reviews:
  testtools developers (testtools-dev)
Related bugs:
  Bug #801027 in testtools: "gather_details API could be easier to use"
  https://bugs.launchpad.net/testtools/+bug/801027

For more details, see:
https://code.launchpad.net/~jml/testtools/gather-details-dict-801027/+merge/68599

Pretty simple. Changes gather_details to take dicts rather than detailed objects.
-- 
https://code.launchpad.net/~jml/testtools/gather-details-dict-801027/+merge/68599
Your team testtools developers is requested to review the proposed merge of lp:~jml/testtools/gather-details-dict-801027 into lp:testtools.
=== modified file 'NEWS'
--- NEWS	2011-07-20 08:48:46 +0000
+++ NEWS	2011-07-20 20:31:31 +0000
@@ -4,6 +4,12 @@
 NEXT
 ~~~~
 
+Changes
+-------
+
+* ``gather_details`` takes two dicts, rather than two detailed objects.
+  (Jonathan Lange, #801027)
+
 Improvements
 ------------
 

=== modified file 'testtools/testcase.py'
--- testtools/testcase.py	2011-06-20 11:57:32 +0000
+++ testtools/testcase.py	2011-07-20 20:31:31 +0000
@@ -118,21 +118,19 @@
     return content.Content(content_object.content_type, content_callback)
 
 
-def gather_details(source, target):
-    """Merge the details from `source` into `target`.
+def gather_details(source_dict, target_dict):
+    """Merge the details from `source_dict` into `target_dict`.
 
-    :param source: A *detailed* object from which details will be gathered.
-    :param target: A *detailed* object into which details will be gathered.
+    :param source_dict: A dictionary of details will be gathered.
+    :param target_dict: A dictionary into which details will be gathered.
     """
-    source_details = source.getDetails()
-    target_details = target.getDetails()
-    for name, content_object in source_details.items():
+    for name, content_object in source_dict.items():
         new_name = name
         disambiguator = itertools.count(1)
-        while new_name in target_details:
+        while new_name in target_dict:
             new_name = '%s-%d' % (name, advance_iterator(disambiguator))
         name = new_name
-        target.addDetail(name, _copy_content(content_object))
+        target_dict[name] = _copy_content(content_object)
 
 
 class TestCase(unittest.TestCase):
@@ -577,11 +575,12 @@
         try:
             fixture.setUp()
         except:
-            gather_details(fixture, self)
+            gather_details(fixture.getDetails(), self.getDetails())
             raise
         else:
             self.addCleanup(fixture.cleanUp)
-            self.addCleanup(gather_details, fixture, self)
+            self.addCleanup(
+                gather_details, fixture.getDetails(), self.getDetails())
             return fixture
 
     def setUp(self):


Follow ups