Pārlūkot izejas kodu

Fix Index.iterblobs behaviour, add test.

Jelmer Vernooij 7 gadi atpakaļ
vecāks
revīzija
0715211453
3 mainītis faili ar 37 papildinājumiem un 2 dzēšanām
  1. 5 0
      NEWS
  2. 2 2
      dulwich/index.py
  3. 30 0
      dulwich/tests/test_index.py

+ 5 - 0
NEWS

@@ -1,5 +1,10 @@
 0.19.2	UNRELEASED
 
+ BUG FIXES
+
+  * Fix deprecated Index.iterblobs method.
+    (Jelmer Vernooij)
+
 0.19.1	2018-04-05
 
  IMPROVEMENTS

+ 2 - 2
dulwich/index.py

@@ -275,8 +275,8 @@ class Index(object):
 
     def iterblobs(self):
         import warnings
-        warnings.warn(PendingDeprecationWarning, 'Use iterobjects() instead.')
-        return self.iterblobs()
+        warnings.warn('Use iterobjects() instead.', PendingDeprecationWarning)
+        return self.iterobjects()
 
     def clear(self):
         """Remove all contents from this index."""

+ 30 - 0
dulwich/tests/test_index.py

@@ -30,6 +30,7 @@ import stat
 import struct
 import sys
 import tempfile
+import warnings
 
 from dulwich.index import (
     Index,
@@ -62,6 +63,9 @@ from dulwich.tests import (
     TestCase,
     skipIf,
     )
+from dulwich.tests.utils import (
+    setup_warning_catcher,
+    )
 
 
 class IndexTestCase(TestCase):
@@ -80,6 +84,32 @@ class SimpleIndexTestCase(IndexTestCase):
     def test_iter(self):
         self.assertEqual([b'bla'], list(self.get_simple_index("index")))
 
+    def test_iterobjects(self):
+        self.assertEqual(
+                [(b'bla', b'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391', 33188)],
+                list(self.get_simple_index("index").iterobjects()))
+
+    def test_iterblobs(self):
+        warnings.simplefilter("always", UserWarning)
+        self.addCleanup(warnings.resetwarnings)
+        warnings_list, restore_warnings = setup_warning_catcher()
+        self.addCleanup(restore_warnings)
+
+        self.assertEqual(
+                [(b'bla', b'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391', 33188)],
+                list(self.get_simple_index("index").iterblobs()))
+
+        expected_warning = PendingDeprecationWarning(
+            'Use iterobjects() instead.')
+        for w in warnings_list:
+            if (type(w) == type(expected_warning) and
+                    w.args == expected_warning.args):
+                break
+        else:
+            raise AssertionError(
+                'Expected warning %r not in %r' %
+                (expected_warning, warnings_list))
+
     def test_getitem(self):
         self.assertEqual(
                 ((1230680220, 0), (1230680220, 0), 2050, 3761020,