This file is indexed.

/usr/lib/python2.7/dist-packages/nose2/tests/unit/test_testid_plugin.py is in python-nose2 0.5.0-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
"""Test testid plugin."""
import os.path
import pickle

from six import StringIO

from nose2 import session
from nose2.events import ReportTestEvent
from nose2.plugins import testid
from nose2.tests._common import (FakeStartTestEvent, FakeLoadFromNameEvent,
                                 FakeLoadFromNamesEvent, TestCase)


class UnitTestTestId(TestCase):

    """Test class TestId.

    Tests are carried out in a temporary directory, since TestId stores state
    to file. The temporary directory is removed after testing.
    """
    tags = ['unit']
    _RUN_IN_TEMP = True

    def setUp(self):
        super(UnitTestTestId, self).setUp()
        self.stream = StringIO()
        self.session = session.Session()
        self.plugin = testid.TestId(session=self.session)

    def test___init__(self):
        """Test the __init__ method."""
        plug = self.plugin
        # Test attributes
        for name, exp_val in [(
            'configSection', 'testid'), ('commandLineSwitch',
                                         ('I', 'with-id', 'Add test ids to output')), ('idfile',
                                                                                       os.path.abspath(
                                                                                           '.noseids')), ('ids', {}), ('tests', {}),
                ('id', 0)]:
            try:
                val = getattr(plug, name)
            except AttributeError:
                self.fail(
                    'TestId instance doesn\'t have attribute %s' % (name,))
            self.assertEqual(val, exp_val, 'Attribute %s should have value '
                             '\'%s\', but has value %s' % (name, exp_val, val))

    def test_start_test(self):
        """Test reportStartTest method."""
        self.session.verbosity = 2
        event = ReportTestEvent(FakeStartTestEvent(self), self.stream)
        plug = self.plugin
        plug.reportStartTest(event)

        self.assertEqual(plug.id, 1)
        test_id = self.id()
        self.assertEqual(plug.ids, {1: test_id})
        self.assertEqual(plug.tests, {test_id: 1})
        self.assertEqual(self.stream.getvalue(), '#1 ')

    def test_start_test_twice(self):
        """Test calling reportStartTest twice."""
        self.session.verbosity = 2
        event = ReportTestEvent(FakeStartTestEvent(self), self.stream)
        plug = self.plugin
        plug.reportStartTest(event)
        plug.reportStartTest(event)

        self.assertEqual(plug.id, 1)
        test_id = self.id()
        self.assertEqual(plug.ids, {1: test_id})
        self.assertEqual(plug.tests, {test_id: 1})
        self.assertEqual(self.stream.getvalue(), '#1 #1 ')

    def test_stop_test_run(self):
        """Test stopTestRun method."""
        plug = self.plugin
        plug.reportStartTest(
            ReportTestEvent(FakeStartTestEvent(self), self.stream))
        plug.stopTestRun(None)

        fh = open(plug.idfile, 'rb')
        try:
            data = pickle.load(fh)
        finally:
            fh.close()
        self.assertEqual(data, {'ids': plug.ids, 'tests': plug.tests})

    def test_load_tests_from_name(self):
        """Test loadTestsFromName method."""
        plug = self.plugin
        # By first starting/stopping a test, an ID is assigned by the plugin
        plug.reportStartTest(
            ReportTestEvent(FakeStartTestEvent(self), self.stream))
        plug.stopTestRun(None)
        event = FakeLoadFromNameEvent('1')
        plug.loadTestsFromName(event)

        # The numeric ID should be translated to this test's ID
        self.assertEqual(event.name, self.id())

    def test_load_tests_from_name_no_ids(self):
        """Test calling loadTestsFromName when no IDs have been saved."""
        plug = self.plugin
        event = FakeLoadFromNameEvent('1')
        plug.loadTestsFromName(event)

        # The event's name should be unchanged, since no IDs should be mapped
        self.assertEqual(event.name, '1')

    def test_load_tests_from_names(self):
        """Test loadTestsFromNames method."""
        plug = self.plugin
        # By first starting/stopping a test, an ID is assigned by the plugin
        plug.reportStartTest(
            ReportTestEvent(FakeStartTestEvent(self), self.stream))
        plug.stopTestRun(None)
        event = FakeLoadFromNamesEvent(['1', '2'])
        plug.loadTestsFromNames(event)

        name1, name2 = event.names
        # The first numeric ID should be translated to this test's ID
        self.assertEqual(name1, self.id())
        # The second one should not have a match
        self.assertEqual(name2, '2')