This file is indexed.

/usr/lib/python3/dist-packages/joblib/test/test_format_stack.py is in python3-joblib 0.10.3+git55-g660fe5d-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
"""
Unit tests for the stack formatting utilities
"""

# Author: Gael Varoquaux <gael dot varoquaux at normalesup dot org>
# Copyright (c) 2010 Gael Varoquaux
# License: BSD Style, 3 clauses.

import re
import sys

from joblib.format_stack import safe_repr, _fixed_getframes, format_records
from joblib.format_stack import format_exc
from joblib.test.common import with_numpy, np

###############################################################################


class Vicious(object):
    def __repr__(self):
        raise ValueError


def test_safe_repr():
    safe_repr(Vicious())


def _change_file_extensions_to_pyc(record):
    _1, filename, _2, _3, _4, _5 = record
    if filename.endswith('.py'):
        filename += 'c'
    return _1, filename, _2, _3, _4, _5


def _raise_exception(a, b):
    """Function that raises with a non trivial call stack
    """
    def helper(a, b):
        raise ValueError('Nope, this can not work')

    helper(a, b)


def test_format_records():
    try:
        _raise_exception('a', 42)
    except ValueError:
        etb = sys.exc_info()[2]
        records = _fixed_getframes(etb)

        # Modify filenames in traceback records from .py to .pyc
        pyc_records = [_change_file_extensions_to_pyc(record)
                       for record in records]

        formatted_records = format_records(pyc_records)

        # Check that the .py file and not the .pyc one is listed in
        # the traceback
        for fmt_rec in formatted_records:
            assert 'test_format_stack.py in' in fmt_rec

        # Check exception stack
        assert "_raise_exception('a', 42)" in formatted_records[0]
        assert 'helper(a, b)' in formatted_records[1]
        assert "a = 'a'" in formatted_records[1]
        assert 'b = 42' in formatted_records[1]
        assert 'Nope, this can not work' in formatted_records[2]


@with_numpy
def test_format_exc_with_compiled_code():
    # Trying to tokenize compiled C code raise SyntaxError.
    # See https://github.com/joblib/joblib/issues/101 for more details.
    try:
        np.random.uniform('invalid_value')
    except Exception:
        exc_type, exc_value, exc_traceback = sys.exc_info()
        formatted_exc = format_exc(exc_type, exc_value,
                                   exc_traceback, context=10)
        # The name of the extension can be something like
        # mtrand.cpython-33m.so
        pattern = 'mtrand[a-z0-9._-]*\.(so|pyd)'
        assert re.search(pattern, formatted_exc)