aboutsummaryrefslogtreecommitdiffstats
path: root/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_interfaces.py
blob: f9f60dab8f229059b06226abfe437d57613d3b32 (plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.

"""
Tests for L{twisted.internet.interfaces}.
"""

from twisted.trial import unittest


class TestIFinishableConsumer(unittest.TestCase):
    """
    L{IFinishableConsumer} is deprecated.
    """

    def lookForDeprecationWarning(self, testmethod):
        """
        Importing C{testmethod} emits a deprecation warning.
        """
        warningsShown = self.flushWarnings([testmethod])
        self.assertEqual(len(warningsShown), 1)
        self.assertIdentical(warningsShown[0]['category'], DeprecationWarning)
        self.assertEqual(
            warningsShown[0]['message'],
            "twisted.internet.interfaces.IFinishableConsumer "
            "was deprecated in Twisted 11.1.0: Please use IConsumer "
            "(and IConsumer.unregisterProducer) instead.")


    def test_deprecationWithDirectImport(self):
        """
        Importing L{IFinishableConsumer} causes a deprecation warning
        """
        from twisted.internet.interfaces import IFinishableConsumer
        self.lookForDeprecationWarning(
            TestIFinishableConsumer.test_deprecationWithDirectImport)


    def test_deprecationWithIndirectImport(self):
        """
        Importing L{interfaces} and implementing
        L{interfaces.IFinishableConsumer} causes a deprecation warning
        """
        from zope.interface import implements
        from twisted.internet import interfaces

        class FakeIFinishableConsumer:
            implements(interfaces.IFinishableConsumer)
            def finish(self):
                pass

        self.lookForDeprecationWarning(
            TestIFinishableConsumer.test_deprecationWithIndirectImport)