Selected Warning messages disabled in pylintrc: * unused-argument: Quite a large and disruptive change if enabled. * broad-except: Most required in-depth investigation to determine type. * fixme: Not important * protected-access: Complicated to fix * import-error: Too many false-positives * unidiomatic-typecheck: Should be fixed in the next round of checks. * unused-variable: Again large and disruptive changes. * global-statement: Most usage is required. * attribute-defined-outside-init: Should be fixed in next round of checks. * arguments-differ: Possible false-positives, needs revisited. * no-init, non-parent-init-called, super-init-not-called: False-positives? * signature-differs: False-positives?
44 lines
1.1 KiB
Python
44 lines
1.1 KiB
Python
from twisted.trial import unittest
|
|
|
|
from deluge.decorators import proxy
|
|
|
|
|
|
class DecoratorsTestCase(unittest.TestCase):
|
|
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
|
|
|
|
self.assertTrue(something(False))
|
|
self.assertFalse(something(True))
|
|
self.assertTrue(double_nothing(True))
|
|
self.assertFalse(double_nothing(False))
|
|
|
|
def test_proxy_with_class_method(self):
|
|
def negate(func, *args, **kwargs):
|
|
return -func(*args, **kwargs)
|
|
|
|
class Test(object):
|
|
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)
|
|
self.assertEqual(t.diff(1), -4)
|
|
self.assertEqual(t.no_diff(1), 4)
|