Initial import to Tizen
[profile/ivi/python-twisted.git] / twisted / persisted / test / test_styles.py
1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
3
4 """
5 Tests for L{twisted.persisted.styles}.
6 """
7
8 from twisted.trial import unittest
9 from twisted.persisted.styles import unpickleMethod
10
11
12 class Foo:
13     """
14     Helper class.
15     """
16     def method(self):
17         """
18         Helper method.
19         """
20
21
22
23 class Bar:
24     """
25     Helper class.
26     """
27
28
29
30 class UnpickleMethodTestCase(unittest.TestCase):
31     """
32     Tests for the unpickleMethod function.
33     """
34
35     def test_instanceBuildingNamePresent(self):
36         """
37         L{unpickleMethod} returns an instance method bound to the
38         instance passed to it.
39         """
40         foo = Foo()
41         m = unpickleMethod('method', foo, Foo)
42         self.assertEqual(m, foo.method)
43         self.assertNotIdentical(m, foo.method)
44
45
46     def test_instanceBuildingNameNotPresent(self):
47         """
48         If the named method is not present in the class,
49         L{unpickleMethod} finds a method on the class of the instance
50         and returns a bound method from there.
51         """
52         foo = Foo()
53         m = unpickleMethod('method', foo, Bar)
54         self.assertEqual(m, foo.method)
55         self.assertNotIdentical(m, foo.method)