Skip to content

Commit 2094f4c

Browse files
committed
add unittest case for setattr via decorator on class member
1 parent 8d27b51 commit 2094f4c

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_class-set-attrib.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2018,2019, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -102,3 +102,24 @@ def test_assignments():
102102
assert object.baz == 119, "custom set"
103103

104104

105+
def test_setattr_via_decorator():
106+
def setdec(func):
107+
setattr(func, 'SPECIAL_ATTR', {'a': 1, 'b': 2})
108+
return func
109+
110+
@setdec
111+
def f():
112+
return 1
113+
114+
assert hasattr(f, 'SPECIAL_ATTR')
115+
assert getattr(f, 'SPECIAL_ATTR') == {'a': 1, 'b': 2}
116+
117+
118+
class MyClass(object):
119+
@setdec
120+
def f(self):
121+
return 1
122+
123+
m = MyClass()
124+
assert hasattr(m.f, 'SPECIAL_ATTR')
125+
assert getattr(m.f, 'SPECIAL_ATTR') == {'a': 1, 'b': 2}

0 commit comments

Comments
 (0)