This file is indexed.

/usr/lib/python3/dist-packages/twisted/trial/test/test_suppression.py is in python3-twisted-experimental 13.2.0-0ubuntu1.

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
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.

"""
Tests for warning suppression features of Trial.
"""

from __future__ import division, absolute_import

import unittest as pyunit

from twisted.trial import unittest
from twisted.trial.test import suppression


class SuppressionMixin(object):
    """
    Tests for the warning suppression features of
    L{twisted.trial.unittest.SynchronousTestCase}.
    """
    def runTests(self, suite):
        suite.run(pyunit.TestResult())


    def _load(self, cls, methodName):
        """
        Return a new L{unittest.TestSuite} with a single test method in it.

        @param cls: A L{TestCase} subclass defining a test method.

        @param methodName: The name of the test method from C{cls}.
        """
        return pyunit.TestSuite([cls(methodName)])


    def _assertWarnings(self, warnings, which):
        """
        Assert that a certain number of warnings with certain messages were
        emitted in a certain order.

        @param warnings: A list of emitted warnings, as returned by
            C{flushWarnings}.

        @param which: A list of strings giving warning messages that should
            appear in C{warnings}.

        @raise self.failureException: If the warning messages given by C{which}
            do not match the messages in the warning information in C{warnings},
            or if they do not appear in the same order.
        """
        self.assertEqual(
            [warning['message'] for warning in warnings],
            which)


    def test_setUpSuppression(self):
        """
        Suppressions defined by the test method being run are applied to any
        warnings emitted while running the C{setUp} fixture.
        """
        self.runTests(
            self._load(self.TestSetUpSuppression, "testSuppressMethod"))
        warningsShown = self.flushWarnings([
                self.TestSetUpSuppression._emit])
        self._assertWarnings(
            warningsShown,
            [suppression.CLASS_WARNING_MSG, suppression.MODULE_WARNING_MSG,
             suppression.CLASS_WARNING_MSG, suppression.MODULE_WARNING_MSG])


    def test_tearDownSuppression(self):
        """
        Suppressions defined by the test method being run are applied to any
        warnings emitted while running the C{tearDown} fixture.
        """
        self.runTests(
            self._load(self.TestTearDownSuppression, "testSuppressMethod"))
        warningsShown = self.flushWarnings([
                self.TestTearDownSuppression._emit])
        self._assertWarnings(
            warningsShown,
            [suppression.CLASS_WARNING_MSG, suppression.MODULE_WARNING_MSG,
             suppression.CLASS_WARNING_MSG, suppression.MODULE_WARNING_MSG])


    def test_suppressMethod(self):
        """
        A suppression set on a test method prevents warnings emitted by that
        test method which the suppression matches from being emitted.
        """
        self.runTests(
            self._load(self.TestSuppression, "testSuppressMethod"))
        warningsShown = self.flushWarnings([
                self.TestSuppression._emit])
        self._assertWarnings(
            warningsShown,
            [suppression.CLASS_WARNING_MSG, suppression.MODULE_WARNING_MSG])


    def test_suppressClass(self):
        """
        A suppression set on a L{SynchronousTestCase} subclass prevents warnings
        emitted by any test methods defined on that class which match the
        suppression from being emitted.
        """
        self.runTests(
            self._load(self.TestSuppression, "testSuppressClass"))
        warningsShown = self.flushWarnings([
                self.TestSuppression._emit])
        self.assertEqual(
            warningsShown[0]['message'], suppression.METHOD_WARNING_MSG)
        self.assertEqual(
            warningsShown[1]['message'], suppression.MODULE_WARNING_MSG)
        self.assertEqual(len(warningsShown), 2)


    def test_suppressModule(self):
        """
        A suppression set on a module prevents warnings emitted by any test
        mewthods defined in that module which match the suppression from being
        emitted.
        """
        self.runTests(
            self._load(self.TestSuppression2, "testSuppressModule"))
        warningsShown = self.flushWarnings([
                self.TestSuppression._emit])
        self.assertEqual(
            warningsShown[0]['message'], suppression.METHOD_WARNING_MSG)
        self.assertEqual(
            warningsShown[1]['message'], suppression.CLASS_WARNING_MSG)
        self.assertEqual(len(warningsShown), 2)


    def test_overrideSuppressClass(self):
        """
        The suppression set on a test method completely overrides a suppression
        with wider scope; if it does not match a warning emitted by that test
        method, the warning is emitted, even if a wider suppression matches.
        """
        self.runTests(
            self._load(self.TestSuppression, "testOverrideSuppressClass"))
        warningsShown = self.flushWarnings([
                self.TestSuppression._emit])
        self.assertEqual(
            warningsShown[0]['message'], suppression.METHOD_WARNING_MSG)
        self.assertEqual(
            warningsShown[1]['message'], suppression.CLASS_WARNING_MSG)
        self.assertEqual(
            warningsShown[2]['message'], suppression.MODULE_WARNING_MSG)
        self.assertEqual(len(warningsShown), 3)



class SynchronousSuppressionTest(SuppressionMixin, unittest.SynchronousTestCase):
    """
    @see: L{twisted.trial.test.test_tests}
    """
    from twisted.trial.test.suppression import (
        SynchronousTestSetUpSuppression as TestSetUpSuppression,
        SynchronousTestTearDownSuppression as TestTearDownSuppression,
        SynchronousTestSuppression as TestSuppression,
        SynchronousTestSuppression2 as TestSuppression2)