Initial import to Tizen
[profile/ivi/python-twisted.git] / twisted / internet / test / test_interfaces.py
1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
3
4 """
5 Tests for L{twisted.internet.interfaces}.
6 """
7
8 from twisted.trial import unittest
9
10
11 class TestIFinishableConsumer(unittest.TestCase):
12     """
13     L{IFinishableConsumer} is deprecated.
14     """
15
16     def lookForDeprecationWarning(self, testmethod):
17         """
18         Importing C{testmethod} emits a deprecation warning.
19         """
20         warningsShown = self.flushWarnings([testmethod])
21         self.assertEqual(len(warningsShown), 1)
22         self.assertIdentical(warningsShown[0]['category'], DeprecationWarning)
23         self.assertEqual(
24             warningsShown[0]['message'],
25             "twisted.internet.interfaces.IFinishableConsumer "
26             "was deprecated in Twisted 11.1.0: Please use IConsumer "
27             "(and IConsumer.unregisterProducer) instead.")
28
29
30     def test_deprecationWithDirectImport(self):
31         """
32         Importing L{IFinishableConsumer} causes a deprecation warning
33         """
34         from twisted.internet.interfaces import IFinishableConsumer
35         self.lookForDeprecationWarning(
36             TestIFinishableConsumer.test_deprecationWithDirectImport)
37
38
39     def test_deprecationWithIndirectImport(self):
40         """
41         Importing L{interfaces} and implementing
42         L{interfaces.IFinishableConsumer} causes a deprecation warning
43         """
44         from zope.interface import implements
45         from twisted.internet import interfaces
46
47         class FakeIFinishableConsumer:
48             implements(interfaces.IFinishableConsumer)
49             def finish(self):
50                 pass
51
52         self.lookForDeprecationWarning(
53             TestIFinishableConsumer.test_deprecationWithIndirectImport)