This file is indexed.

/usr/lib/python3/dist-packages/aeidon/unittest.py is in python3-aeidon 0.24.3-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
# -*- coding: utf-8 -*-

# Copyright (C) 2005-2009,2011 Osmo Salomaa
#
# This file is part of Gaupol.
#
# Gaupol 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.
#
# Gaupol 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
# Gaupol. If not, see <http://www.gnu.org/licenses/>.

"""Base class for unit test cases."""

import aeidon
import os

__all__ = ("TestCase",)


class TestCase(object, metaclass=aeidon.Contractual):

    """
    Base class for unit test cases.

    Unit tests are designed to be run with ``py.test``, ``nose`` or something
    compatible. Tests should use plain ``assert`` statements to allow multiple
    different tools to be used to run the tests.
    """

    def assert_raises(self, exception, function, *args, **kwargs):
        """Assert that calling `function` raises `exception`."""
        try:
            function(*args, **kwargs)
        except exception:
            return
        raise AssertionError("{} failed to raise {}"
                             .format(repr(function),
                                     repr(exception)))

    def get_sample_text_ensure(self, value, format, name=None):
        assert value.count("a") > 10

    @aeidon.deco.memoize(100)
    def get_sample_text(self, format, name=None):
        """
        Return sample text for subtitle file `format`.

        `name` can be specified if different from ``format.name.lower()``.
        This is useful for variants of a format, e.g. "subrip-extended".
        """
        name = name or format.name.lower()
        basename = "".join((name, format.extension))
        path = os.path.join(aeidon.DATA_DIR, "samples", basename)
        with open(path, "r", encoding="ascii") as fobj:
            return fobj.read().strip()

    def new_microdvd_file_ensure(self, value):
        assert os.path.isfile(value)

    def new_microdvd_file(self):
        """Return path to a new temporary ``MicroDVD`` file."""
        return self.new_temp_file(aeidon.formats.MICRODVD)

    def new_project_ensure(self, value):
        assert value.subtitles

    def new_project(self):
        """Return a new project with both main and translation files."""
        project = aeidon.Project()
        project.open_main(self.new_subrip_file(), "ascii")
        project.open_translation(self.new_microdvd_file(), "ascii")
        return project

    def new_subrip_file_ensure(self, value):
        assert os.path.isfile(value)

    def new_subrip_file(self):
        """Return path to a new temporary ``SubRip`` file."""
        return self.new_temp_file(aeidon.formats.SUBRIP)

    def new_temp_file_ensure(self, value, format, name=None):
        assert os.path.isfile(value)

    def new_temp_file(self, format, name=None):
        """Return path to a new temporary subtitle file."""
        text = self.get_sample_text(format, name)
        path = aeidon.temp.create(format.extension)
        aeidon.temp.close(path)
        with open(path, "w", encoding="ascii") as fobj:
            fobj.write(text)
        return path

    def setUp(self):
        """Compatibility alias for :meth:`setup_method`."""
        self.setup_method(None)

    def setup_method(self, method):
        """Set state for executing tests in `method`."""
        pass

    def tearDown(self):
        """Compatibility alias for :meth:`teardown_method`."""
        self.teardown_method(None)

    def teardown_method(self, method):
        """Remove state set for executing tests in `method`."""
        pass

    def test___init__(self):
        """Make sure that :meth:`setup_method` is always run."""
        pass