This file is indexed.

/usr/lib/python2.7/dist-packages/nevow/test/test_nit.py is in python-nevow 0.14.2-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
 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
# Copyright (c) 2008 Divmod.  See LICENSE for details.

"""
Tests for L{nevow.livetrial} and L{nevow.scripts.nit}.
"""

import sys

from twisted.trial.unittest import TestCase
from twisted.python.failure import Failure

from nevow.appserver import NevowSite
from nevow.testutil import FragmentWrapper, renderLivePage
from nevow.livetrial.testcase import TestSuite, TestError
from nevow.livetrial.runner import TestFrameworkRoot
from nevow.scripts import nit

MESSAGE = u'I am an error'



class _DummyErrorHolder(object):
    """
    A dummy object that implements the parts of the ErrorHolder API we use,
    supplying an appropriate Failure.
    """

    def createFailure(self):
        """Create a Failure with traceback and all."""
        try:
            raise Exception(MESSAGE)
        except Exception:
            return Failure()


    def run(self, thing):
        thing.addError(self, self.createFailure())



class _DummySuite(TestSuite):
    """A dummy test suite containing a dummy Failure holder."""

    holderType = _DummyErrorHolder

    def __init__(self):
        self.name = 'Dummy Suite'
        holder = _DummyErrorHolder()
        self.tests = [holder]



class NevowInteractiveTesterTest(TestCase):

    def test_gatherError(self):
        """
        Attempt collection of tests in the presence of an Failure that has
        occurred during trial's collection.
        """
        suite = _DummySuite()
        instances = suite.gatherInstances()
        te = instances[0]
        self.assertIdentical(type(te), TestError)


    def test_errorRendering(self):
        te = TestError(_DummyErrorHolder())
        return renderLivePage(FragmentWrapper(te)).addCallback(
            lambda output: self.assertIn(MESSAGE, output))


    def test_portOption(self):
        """
        L{nit.NitOptions.parseOptions} accepts the I{--port} option and sets
        the port number based on it.
        """
        options = nit.NitOptions()
        options.parseOptions(['--port', '1234'])
        self.assertEqual(options['port'], 1234)


    def test_portOptionDefault(self):
        """
        If no I{--port} option is given, a default port number is used.
        """
        options = nit.NitOptions()
        options.parseOptions([])
        self.assertEqual(options['port'], 8080)


    def test_testModules(self):
        """
        All extra positional arguments are interpreted as test modules.
        """
        options = nit.NitOptions()
        options.parseOptions(['foo', 'bar'])
        self.assertEqual(options['testmodules'], ('foo', 'bar'))


    def test_getSuite(self):
        """
        L{nit._getSuite} returns a L{nevow.livetrial.testcase.TestSuite} with
        L{TestCase} instances added to it as specified by the list of module
        names passed to it.
        """
        suite = nit._getSuite(['nevow.test.livetest_athena'])
        self.assertTrue(suite.tests[0].tests)


    def test_runInvalidOptions(self):
        """
        L{nit.run} raises L{SystemExit} if invalid options are used.
        """
        self.patch(sys, 'argv', ["nit", "--foo"])
        self.assertRaises(SystemExit, nit.run)


    def test_runWithoutModules(self):
        """
        If no modules to test are given on the command line, L{nit.run} raises
        L{SystemExit}.
        """
        self.patch(sys, 'argv', ['nit'])
        self.assertRaises(SystemExit, nit.run)


    def test_run(self):
        """
        Given a valid port number and a test module, L{nit.run} starts logging
        to stdout, starts a L{NevowSite} listening on the specified port
        serving a L{TestFrameworkRoot}, and runs the reactor.
        """
        class FakeReactor:
            def listenTCP(self, port, factory):
                events.append(('listen', port, factory))

            def run(self):
                events.append(('run',))

        events = []
        self.patch(
            nit, 'startLogging', lambda out: events.append(('logging', out)))
        self.patch(nit, 'reactor', FakeReactor())
        self.patch(sys, 'argv', ['nit', '--port', '123', 'nevow'])
        nit.run()
        self.assertEqual(events[0], ('logging', sys.stdout))
        self.assertEqual(events[1][:2], ('listen', 123))
        self.assertTrue(isinstance(events[1][2], NevowSite))
        self.assertTrue(isinstance(events[1][2].resource, TestFrameworkRoot))
        self.assertEqual(events[2], ('run',))