diff options
author | immerrr again <immerrr@gmail.com> | 2020-01-07 03:55:42 +0100 |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2020-01-06 18:55:42 -0800 |
commit | 1988faf3f7a7f77c0eccbbc5192f365400d44deb (patch) | |
tree | cbb35c98e90da9dcd8f319b16c4ffe607d2c2a50 /test_six.py | |
parent | a4d9af96b122e98b7be3649b6545e0f6a04c8335 (diff) | |
download | six-git-1988faf3f7a7f77c0eccbbc5192f365400d44deb.tar.gz |
Fix wraps handing of missing attrs. (#251)
This is pretty-much a straight backport of Py3 implementations of update_wrapper and (privately) wraps.
Fixes #250
Fixes #165
Co-authored-by: Benjamin Peterson <benjamin@python.org>
Diffstat (limited to 'test_six.py')
-rw-r--r-- | test_six.py | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/test_six.py b/test_six.py index 8ada517..ab99ce9 100644 --- a/test_six.py +++ b/test_six.py @@ -832,14 +832,33 @@ def test_wraps(): def f(g, assign, update): def w(): return 42 - w.glue = {"foo" : "bar"} + w.glue = {"foo": "bar"} + w.xyzzy = {"qux": "quux"} return six.wraps(g, assign, update)(w) - k.glue = {"melon" : "egg"} + k.glue = {"melon": "egg"} k.turnip = 43 - k = f(k, ["turnip"], ["glue"]) + k = f(k, ["turnip", "baz"], ["glue", "xyzzy"]) assert k.__name__ == "w" assert k.turnip == 43 - assert k.glue == {"melon" : "egg", "foo" : "bar"} + assert not hasattr(k, "baz") + assert k.glue == {"melon": "egg", "foo": "bar"} + assert k.xyzzy == {"qux": "quux"} + + +def test_wraps_raises_on_missing_updated_field_on_wrapper(): + """Ensure six.wraps doesn't ignore missing attrs wrapper. + + Because that's what happens in Py3's functools.update_wrapper. + """ + def wrapped(): + pass + + def wrapper(): + pass + + with pytest.raises(AttributeError, match='has no attribute.*xyzzy'): + six.wraps(wrapped, [], ['xyzzy'])(wrapper) + def test_add_metaclass(): |