This file is indexed.

/usr/lib/python2.7/dist-packages/autopilot/testresult.py is in python-autopilot 1.4.1+17.04.20170305-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
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
#
# Autopilot Functional Test Tool
# Copyright (C) 2012-2013 Canonical
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#


"""Autopilot test result classes"""

from __future__ import absolute_import

import logging

from testtools import (
    ExtendedToOriginalDecorator,
    ExtendedToStreamDecorator,
    TestResultDecorator,
    TextTestResult,
    try_import,
)

from autopilot.globals import get_log_verbose
from autopilot.utilities import _raise_on_unknown_kwargs


class LoggedTestResultDecorator(TestResultDecorator):

    """A decorator that logs messages to python's logging system."""

    def _log(self, level, message):
        """Perform the actual message logging."""
        if get_log_verbose():
            logging.getLogger().log(level, message)

    def _log_details(self, level, details):
        """Log the relavent test details."""
        for detail in details:
            # Skip the test-log as it was logged while the test executed
            if detail == "test-log":
                continue
            text = "%s: {{{\n%s}}}" % (detail, details[detail].as_text())
            self._log(level, text)

    def addSuccess(self, test, details=None):
        self._log(logging.INFO, "OK: %s" % (test.id()))
        return super(LoggedTestResultDecorator, self).addSuccess(test, details)

    def addError(self, test, err=None, details=None):
        self._log(logging.ERROR, "ERROR: %s" % (test.id()))
        if hasattr(test, "getDetails"):
            self._log_details(logging.ERROR, test.getDetails())
        return super(type(self), self).addError(test, err, details)

    def addFailure(self, test, err=None, details=None):
        """Called for a test which failed an assert."""
        self._log(logging.ERROR, "FAIL: %s" % (test.id()))
        if hasattr(test, "getDetails"):
            self._log_details(logging.ERROR, test.getDetails())
        return super(type(self), self).addFailure(test, err, details)


def get_output_formats():
    """Get information regarding the different output formats supported.

    :returns: dict of supported formats and appropriate construct functions

    """
    supported_formats = {}

    supported_formats['text'] = _construct_text

    if try_import('junitxml'):
        supported_formats['xml'] = _construct_xml
    if try_import('subunit'):
        supported_formats['subunit'] = _construct_subunit
    return supported_formats


def get_default_format():
    return 'text'


def _construct_xml(**kwargs):
    from junitxml import JUnitXmlResult
    stream = kwargs.pop('stream')
    failfast = kwargs.pop('failfast')
    _raise_on_unknown_kwargs(kwargs)
    result_object = LoggedTestResultDecorator(
        ExtendedToOriginalDecorator(
            JUnitXmlResult(stream)
        )
    )
    result_object.failfast = failfast
    return result_object


def _construct_text(**kwargs):
    stream = kwargs.pop('stream')
    failfast = kwargs.pop('failfast')
    _raise_on_unknown_kwargs(kwargs)
    return LoggedTestResultDecorator(TextTestResult(stream, failfast))


def _construct_subunit(**kwargs):
    from subunit import StreamResultToBytes
    stream = kwargs.pop('stream')
    failfast = kwargs.pop('failfast')
    _raise_on_unknown_kwargs(kwargs)
    result_object = LoggedTestResultDecorator(
        ExtendedToStreamDecorator(
            StreamResultToBytes(stream)
        )
    )
    result_object.failfast = failfast
    return result_object