diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 21:38:38 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 21:38:38 +0000 |
commit | 2e2851dc13d73352530dd4495c7e05603b2e520d (patch) | |
tree | 622b9cd8e5d32091c9aa9e4937b533975a40356c /deluge/tests/test_decorators.py | |
parent | Initial commit. (diff) | |
download | deluge-2e2851dc13d73352530dd4495c7e05603b2e520d.tar.xz deluge-2e2851dc13d73352530dd4495c7e05603b2e520d.zip |
Adding upstream version 2.1.2~dev0+20240219.upstream/2.1.2_dev0+20240219upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'deluge/tests/test_decorators.py')
-rw-r--r-- | deluge/tests/test_decorators.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/deluge/tests/test_decorators.py b/deluge/tests/test_decorators.py new file mode 100644 index 0000000..d2ecd1a --- /dev/null +++ b/deluge/tests/test_decorators.py @@ -0,0 +1,48 @@ +# +# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with +# the additional special exception to link portions of this program with the OpenSSL library. +# See LICENSE for more details. +# + + +from deluge.decorators import proxy + + +class TestDecorators: + def test_proxy_with_simple_functions(self): + def negate(func, *args, **kwargs): + return not func(*args, **kwargs) + + @proxy(negate) + def something(_bool): + return _bool + + @proxy(negate) + @proxy(negate) + def double_nothing(_bool): + return _bool + + assert something(False) + assert not something(True) + assert double_nothing(True) + assert not double_nothing(False) + + def test_proxy_with_class_method(self): + def negate(func, *args, **kwargs): + return -func(*args, **kwargs) + + class Test: + def __init__(self, number): + self.number = number + + @proxy(negate) + def diff(self, number): + return self.number - number + + @proxy(negate) + def no_diff(self, number): + return self.diff(number) + + t = Test(5) + assert t.diff(1) == -4 + assert t.no_diff(1) == 4 |