/usr/lib/python3/dist-packages/pyutilib/misc/tests/test_method.py is in python3-pyutilib 5.3.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #
# Unit Tests for util/method
#
#
import pyutilib.th as unittest
import pyutilib.misc
class MethodDebug(unittest.TestCase):
def test_add_method(self):
"""Verify that we can add a method to a class"""
class A(object):
def __init__(self):
pass
def foo(self, x):
return (x,)
a=A()
pyutilib.misc.add_method(a,foo)
self.assertEqual(a.foo("a"),("a",))
pyutilib.misc.add_method(a,foo,"bar")
self.assertEqual(a.bar("b"),("b",))
def test_add_method_by_name(self):
"""Verify that we can add a method to a class"""
class A(object):
def __init__(self):
pass
def foo(self, x):
return (x,)
a=A()
pyutilib.misc.add_method_by_name(a,"foo",locals=locals())
self.assertEqual(a.foo("a"),("a",))
pyutilib.misc.add_method_by_name(a,"foo","bar",locals=locals())
self.assertEqual(a.bar("b"),("b",))
if __name__ == "__main__":
unittest.main()
|