This file is indexed.

/usr/lib/python2.7/dist-packages/flufl/i18n/tests/test_translator.py is in python-flufl.i18n 1.1.3-4.

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
129
130
131
132
# Copyright (C) 2009-2014 by Barry A. Warsaw
#
# This file is part of flufl.i18n
#
# flufl.i18n is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# flufl.i18n 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 Lesser General Public
# License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with flufl.i18n.  If not, see <http://www.gnu.org/licenses/>.

"""Tests for the Translator class.

This cannot be a doctest because of the sys._getframe() manipulations.  That
does not play well with the way doctest executes Python code.  But see
translator.txt for a description of how this should work in real Python code.
"""

from __future__ import absolute_import, print_function, unicode_literals

__metaclass__ = type
__all__ = [
    ]


import unittest

from flufl.i18n._translator import Translator

# Some globals for following tests.
purple = 'porpoises'
magenta = 'monkeys'
green = 'gerbil'



class Catalog:
    """Test catalog."""

    def __init__(self):
        self.translation = None

    def ugettext(self, original):
        """Return the translation."""
        return self.translation

    # For Python 3.
    gettext = ugettext

    def charset(self):
        """Return the encoding."""
        # The default is ascii.
        return None



class TranslatorTests(unittest.TestCase):
    """Tests of the Translator class."""

    def setUp(self):
        self.catalog = Catalog()
        # We need depth=1 because we're calling the translation at the same
        # level as the locals we care about.
        self.translator = Translator(self.catalog, depth=1)

    def test_locals(self):
        # Test that locals get properly substituted.
        aqua = 'aardvarks'
        blue = 'badgers'
        cyan = 'cats'
        self.catalog.translation = '$blue and $cyan and $aqua'
        self.assertEqual(self.translator.translate('source string'),
                         'badgers and cats and aardvarks')

    def test_globals(self):
        # Test that globals get properly substituted.
        self.catalog.translation = '$purple and $magenta and $green'
        self.assertEqual(self.translator.translate('source string'),
                         'porpoises and monkeys and gerbil')

    def test_dict_overrides_locals(self):
        # Test that explicit mappings override locals.
        aqua = 'aardvarks'
        blue = 'badgers'
        cyan = 'cats'
        overrides = dict(blue='bats')
        self.catalog.translation = '$blue and $cyan and $aqua'
        self.assertEqual(self.translator.translate('source string', overrides),
                         'bats and cats and aardvarks')

    def test_globals_with_overrides(self):
        # Test that globals with overrides get properly substituted.
        self.catalog.translation = '$purple and $magenta and $green'
        overrides = dict(green='giraffe')
        self.assertEqual(self.translator.translate('source string', overrides),
                         'porpoises and monkeys and giraffe')

    def test_empty_string(self):
        # The empty string is always translated as the empty string.
        self.assertEqual(self.translator.translate(''), '')

    def test_dedent(self):
        # By default, the translated string is always dedented.
        aqua = 'aardvarks'
        blue = 'badgers'
        cyan = 'cats'
        self.catalog.translation = """\
        These are the $blue
        These are the $cyan
        These are the $aqua
        """
        for line in self.translator.translate('source string').splitlines():
            self.assertTrue(line[:5], 'These')

    def test_no_dedent(self):
        # You can optionally suppress the dedent.
        aqua = 'aardvarks'
        blue = 'badgers'
        cyan = 'cats'
        self.catalog.translation = """\
        These are the $blue
        These are the $cyan
        These are the $aqua
        """
        translator = Translator(self.catalog, dedent=False)
        for line in translator.translate('source string').splitlines():
            self.assertTrue(line[:9], '    These')