summaryrefslogtreecommitdiff
path: root/test_six.py
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2014-10-03 14:13:36 -0400
committerBrett Cannon <brett@python.org>2014-10-03 14:13:36 -0400
commit2ac60fc976fe04a390903ee0d612bda8d3431eca (patch)
tree629a959ab488856ad9de1be04e0326aa2762be28 /test_six.py
parent25ba0d5ed66d34bee28734ca9d731df2e26963e8 (diff)
downloadsix-git-2ac60fc976fe04a390903ee0d612bda8d3431eca.tar.gz
Introduce viewkeys(), viewvalues(), and viewitems().
Closes issue #92
Diffstat (limited to 'test_six.py')
-rw-r--r--test_six.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/test_six.py b/test_six.py
index 0125d6b..4ca3200 100644
--- a/test_six.py
+++ b/test_six.py
@@ -389,6 +389,35 @@ def test_dictionary_iterators(monkeypatch):
monkeypatch.undo()
+def test_dictionary_views(monkeypatch):
+ if sys.version_info[:2] <= (2, 6):
+ py.test.skip("view methods on dictionaries only available on 2.7+")
+ def stock_method_name(viewwhat):
+ """Given a method suffix like "keys" or "values", return the name
+ of the dict method that delivers those on the version of Python
+ we're running in."""
+ if six.PY3:
+ return viewwhat
+ return 'view' + viewwhat
+
+ class MyDict(dict):
+ pass
+
+ d = MyDict(zip(range(10), reversed(range(10))))
+ for name in "keys", "values", "items":
+ meth = getattr(six, "view" + name)
+ view = meth(d)
+ assert set(view) == set(getattr(d, name)())
+ record = []
+ def with_kw(*args, **kw):
+ record.append(kw["kw"])
+ return old(*args)
+ old = getattr(MyDict, stock_method_name(name))
+ monkeypatch.setattr(MyDict, stock_method_name(name), with_kw)
+ meth(d, kw=42)
+ assert record == [42]
+ monkeypatch.undo()
+
def test_advance_iterator():
assert six.next is six.advance_iterator
l = [1, 2]