1 new commit in pytest:

https://bitbucket.org/hpk42/pytest/commits/85e374c50722/
Changeset:   85e374c50722
User:        magopian
Date:        2013-08-01 14:48:34
Summary:     refs #279: sequence assertions can also deal with 
(Mutable)Sequence instances
Affected #:  2 files

diff -r c402fa0d27e54e930deb9f210e7c30aa76c5f77b -r 
85e374c5072248cae6bab63ecf9e6cd9fdebf2a5 _pytest/assertion/util.py
--- a/_pytest/assertion/util.py
+++ b/_pytest/assertion/util.py
@@ -1,6 +1,10 @@
 """Utilities for assertion debugging"""
 
 import py
+try:
+    from collections.abc import Sequence
+except ImportError:
+    from collections import Sequence
 
 BuiltinAssertionError = py.builtin.builtins.AssertionError
 
@@ -91,7 +95,8 @@
     right_repr = py.io.saferepr(right, maxsize=width-len(left_repr))
     summary = '%s %s %s' % (left_repr, op, right_repr)
 
-    issequence = lambda x: isinstance(x, (list, tuple))
+    issequence = lambda x: (isinstance(x, (list, tuple, Sequence))
+                            and not isinstance(x, basestring))
     istext = lambda x: isinstance(x, basestring)
     isdict = lambda x: isinstance(x, dict)
     isset = lambda x: isinstance(x, (set, frozenset))
@@ -198,7 +203,7 @@
     common = set(left).intersection(set(right))
     same = dict((k, left[k]) for k in common if left[k] == right[k])
     if same and not verbose:
-        explanation += ['Hiding %s identical items, use -v to show' %
+        explanation += ['Omitting %s identical items, use -v to show' %
                         len(same)]
     elif same:
         explanation += ['Common items:']

diff -r c402fa0d27e54e930deb9f210e7c30aa76c5f77b -r 
85e374c5072248cae6bab63ecf9e6cd9fdebf2a5 testing/test_assertion.py
--- a/testing/test_assertion.py
+++ b/testing/test_assertion.py
@@ -3,6 +3,11 @@
 import py, pytest
 import _pytest.assertion as plugin
 from _pytest.assertion import reinterpret, util
+try:
+    from collections.abc import MutableSequence
+except ImportError:
+    from collections import MutableSequence
+
 
 needsnewassert = pytest.mark.skipif("sys.version_info < (2,6)")
 
@@ -95,13 +100,48 @@
         expl = callequal({'a': 0}, {'a': 1})
         assert len(expl) > 1
 
+    def test_dict_omitting(self):
+        lines = callequal({'a': 0, 'b': 1}, {'a': 1, 'b': 1})
+        assert lines[1].startswith('Omitting 1 identical item')
+        assert 'Common items' not in lines
+        for line in lines[1:]:
+            assert 'b' not in line
+
+    def test_dict_omitting_verbose(self):
+        lines = callequal({'a': 0, 'b': 1}, {'a': 1, 'b': 1}, verbose=True)
+        assert lines[1].startswith('Common items:')
+        assert 'Omitting' not in lines[1]
+        assert lines[2] == "{'b': 1}"
+
     def test_set(self):
         expl = callequal(set([0, 1]), set([0, 2]))
         assert len(expl) > 1
 
     def test_frozenzet(self):
         expl = callequal(frozenset([0, 1]), set([0, 2]))
-        print (expl)
+        assert len(expl) > 1
+
+    def test_Sequence(self):
+        class TestSequence(MutableSequence):  # works with a Sequence subclass
+            def __init__(self, iterable):
+                self.elements = list(iterable)
+
+            def __getitem__(self, item):
+                return self.elements[item]
+
+            def __len__(self):
+                return len(self.elements)
+
+            def __setitem__(self, item, value):
+                pass
+
+            def __delitem__(self, item):
+                pass
+
+            def insert(self, item, index):
+                pass
+
+        expl = callequal(TestSequence([0, 1]), list([0, 2]))
         assert len(expl) > 1
 
     def test_list_tuples(self):

Repository URL: https://bitbucket.org/hpk42/pytest/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
_______________________________________________
pytest-commit mailing list
pytest-commit@python.org
http://mail.python.org/mailman/listinfo/pytest-commit

Reply via email to