/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/EncodingAdapter.py

  • Committer: John Arbash Meinel
  • Date: 2006-01-13 04:22:06 UTC
  • mto: (1685.1.1 bzr-encoding)
  • mto: This revision was merged to the branch mainline in revision 1752.
  • Revision ID: john@arbash-meinel.com-20060113042206-e76c0678a46eacf0
New encoder with multiple strings.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006 by Canonical Ltd
 
2
# -*- coding: utf-8 -*-
 
3
 
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; either version 2 of the License, or
 
7
# (at your option) any later version.
 
8
 
 
9
# This program is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details.
 
13
 
 
14
# You should have received a copy of the GNU General Public License
 
15
# along with this program; if not, write to the Free Software
 
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
 
 
18
"""\
 
19
Adapter for running test cases against multiple encodings.
 
20
"""
 
21
 
 
22
from copy import deepcopy
 
23
 
 
24
from bzrlib.tests import TestSuite
 
25
 
 
26
# prefix for micro (1/1000)
 
27
_mu = u'\xb5'
 
28
 
 
29
# Swedish?
 
30
_erik = u'Erik B\xe5gfors'
 
31
 
 
32
# Swedish 'räksmörgås' means shrimp sandwich
 
33
_shrimp_sandwich = u'r\xe4ksm\xf6rg\xe5s'
 
34
 
 
35
# Arabic, probably only Unicode encodings can handle this one
 
36
_juju = u'\u062c\u0648\u062c\u0648'
 
37
 
 
38
# iso-8859-1 alternative for juju
 
39
_juju_alt = u'j\xfbj\xfa'
 
40
 
 
41
# Russian, 'Alexander' in russian
 
42
_alexander = u'\u0410\u043b\u0435\u043a\u0441\u0430\u043d\u0434\u0440'
 
43
 
 
44
# Kanji
 
45
# It is a kanji sequence for nihonjin, or Japanese in English.
 
46
 
47
# '\u4eba' being person, 'u\65e5' sun and '\u672c' origin. Ie,
 
48
# sun-origin-person, 'native from the land where the sun rises'. Note, I'm
 
49
# not a fluent speaker, so this is just my crude breakdown.
 
50
 
51
# Wouter van Heyst
 
52
_nihonjin = u'\u65e5\u672c\u4eba'
 
53
 
 
54
# Czech
 
55
# It's what is usually used for showing how fonts look, because it contains
 
56
# most accented characters, ie. in places where Englishman use 'Quick brown fox
 
57
# jumped over a lazy dog'. The literal translation of the Czech version would
 
58
# be something like 'Yellow horse groaned devilish codes'. Actually originally
 
59
# the last word used to be 'ódy' (odes). The 'k' was added as a pun when using
 
60
# the sentece to check whether one has properly set encoding.
 
61
_yellow_horse = (u'\u017dlu\u0165ou\u010dk\xfd k\u016f\u0148'
 
62
                 u' \xfap\u011bl \u010f\xe1belsk\xe9 k\xf3dy')
 
63
 
 
64
 
 
65
class EncodingTestAdapter(object):
 
66
    """A tool to generate a suite, testing multiple encodings for a single test.
 
67
    
 
68
    This is similar to bzrlib.transport.TransportTestProviderAdapter.
 
69
    It is done by copying the test once for each encoding, and injecting
 
70
    the encoding name, and the list of valid strings for that encoding.
 
71
    Each copy is also given a new id() to make it easy to identify.
 
72
    """
 
73
 
 
74
    def adapt(self, test):
 
75
        result = TestSuite()
 
76
        for encoding, info in self._test_permutations():
 
77
            new_test = deepcopy(test)
 
78
            new_test.encoding = encoding
 
79
            new_test.info = info
 
80
            def new_test_id():
 
81
                return '%s(%s)' % (new_test.id(), encoding)
 
82
            new_test.id = new_test_id
 
83
            result.addTest(new_test)
 
84
        return result
 
85
 
 
86
    def _test_permutations(self):
 
87
        """Return a list of encoding/info pairs to test.
 
88
 
 
89
        encoding should be a string such as 'utf-8'
 
90
        info is a dictionary containing 'committer', 'filename', 'message',
 
91
             'directory'
 
92
        """
 
93
        return [
 
94
            # Permutation 1 of utf-8
 
95
            ('utf-8', {'committer':_erik
 
96
                      , 'message':_yellow_horse
 
97
                      , 'filename':_shrimp_sandwich
 
98
                      , 'directory':_nihonjin}),
 
99
            # Permutation 2 of utf-8
 
100
            ('utf-8', {'committer':_alexander
 
101
                      , 'message':u'Testing ' + _mu
 
102
                      , 'filename':_juju,
 
103
                      , 'directory':_juju_alt}),
 
104
            ('iso-8859-1', {'committer':_erik
 
105
                      , 'message':u'Testing ' + _mu
 
106
                      , 'filename':_juju_alt
 
107
                      , 'directory':_shrimp_sandwich}),
 
108
            ('iso-8859-2', {'committer':'TODO-iso8859-2-committer'
 
109
                      , 'message':_yellow_horse
 
110
                      , 'filename':'TODO-iso8859-2-filename'
 
111
                      , 'directory':'TODO-iso8859-2-dir'}),
 
112
            ('cp1251', {'committer':_alexander
 
113
                      , 'message':u'Testing ' + _mu
 
114
                      , 'filename':'TODO-cp1251-filename'
 
115
                      , 'directory':'TODO-cp1251-dir'}),
 
116
        ]
 
117
 
 
118
 
 
119