This file is indexed.

/usr/lib/python2.7/dist-packages/crochet/tests/test_util.py is in python-crochet 1.4.0-0ubuntu2.

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
"""
Tests for crochet._util.
"""

from __future__ import absolute_import

from twisted.trial.unittest import TestCase

from crochet._util import synchronized


class FakeLock(object):
    locked = False
    def __enter__(self):
        self.locked = True
    def __exit__(self, type, value, traceback):
        self.locked = False


class Lockable(object):
    def __init__(self):
        self._lock = FakeLock()

    @synchronized
    def check(self, x, y):
        if not self._lock.locked:
            raise RuntimeError()
        return x, y

    @synchronized
    def raiser(self):
        if not self._lock.locked:
            raise RuntimeError()
        raise ZeroDivisionError()


class SynchronizedTests(TestCase):
    """
    Tests for the synchronized decorator.
    """
    def test_return(self):
        """
        A method wrapped with @synchronized is called with the lock acquired,
        and it is released on return.
        """
        obj = Lockable()
        self.assertEqual(obj.check(1, y=2), (1, 2))
        self.assertFalse(obj._lock.locked)

    def test_raise(self):
        """
        A method wrapped with @synchronized is called with the lock acquired,
        and it is released on exception raise.
        """
        obj = Lockable()
        self.assertRaises(ZeroDivisionError, obj.raiser)
        self.assertFalse(obj._lock.locked)

    def test_name(self):
        """
        A method wrapped with @synchronized preserves its name.
        """
        self.assertEqual(Lockable.check.__name__, "check")

    def test_marked(self):
        """
        A method wrapped with @synchronized is marked as synchronized.
        """
        self.assertEqual(Lockable.check.synchronized, True)