~bzr-pqm/bzr/bzr.dev

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
133
134
135
136
137
138
# Copyright (C) 2006 Canonical Ltd
# -*- coding: utf-8 -*-
#
# 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 2 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, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

"""Adapter for running test cases against multiple encodings."""

from copy import deepcopy

from bzrlib.tests import TestSuite


# prefix for micro (1/1000000)
_mu = u'\xb5'

# greek letter omega, not to be confused with
# the Ohm sign, u'\u2126'. Though they are probably identical
# cp437 can handle the first, but not the second
_omega = u'\u03a9'

# smallest error possible, epsilon
# cp437 handles u03b5, but not u2208 the 'element of' operator
_epsilon = u'\u03b5'

# Swedish?
_erik = u'Erik B\xe5gfors'

# Swedish 'räksmörgås' means shrimp sandwich
_shrimp_sandwich = u'r\xe4ksm\xf6rg\xe5s'

# Arabic, probably only Unicode encodings can handle this one
_juju = u'\u062c\u0648\u062c\u0648'

# iso-8859-1 alternative for juju
_juju_alt = u'j\xfbj\xfa'

# Russian, 'Alexander' in russian
_alexander = u'\u0410\u043b\u0435\u043a\u0441\u0430\u043d\u0434\u0440'
# The word 'test' in Russian
_russian_test = u'\u0422\u0435\u0441\u0442'

# Kanji
# It is a kanji sequence for nihonjin, or Japanese in English.
#
# '\u4eba' being person, 'u\65e5' sun and '\u672c' origin. Ie,
# sun-origin-person, 'native from the land where the sun rises'. Note, I'm
# not a fluent speaker, so this is just my crude breakdown.
#
# Wouter van Heyst
_nihonjin = u'\u65e5\u672c\u4eba'

# Czech
# It's what is usually used for showing how fonts look, because it contains
# most accented characters, ie. in places where Englishman use 'Quick brown fox
# jumped over a lazy dog'. The literal translation of the Czech version would
# be something like 'Yellow horse groaned devilish codes'. Actually originally
# the last word used to be 'ódy' (odes). The 'k' was added as a pun when using
# the sentece to check whether one has properly set encoding.
_yellow_horse = (u'\u017dlu\u0165ou\u010dk\xfd k\u016f\u0148'
                 u' \xfap\u011bl \u010f\xe1belsk\xe9 k\xf3dy')
_yellow = u'\u017dlu\u0165ou\u010dk\xfd'
_someone = u'Some\u016f\u0148\u011b'
_something = u'\u0165ou\u010dk\xfd'

# Hebrew
# Shalom -> 'hello' or 'peace', used as a common greeting
_shalom = u'\u05e9\u05dc\u05d5\u05dd'


encoding_scenarios = [
        # Permutation 1 of utf-8
        ('utf-8,1', {
            'info': {
                'committer': _erik,
                'message': _yellow_horse,
                'filename': _shrimp_sandwich,
                'directory': _nihonjin,
                },
            'encoding': 'utf-8',
            }),
        # Permutation 2 of utf-8
        ('utf-8,2', {
            'info': {
                'committer': _alexander,
                'message': u'Testing ' + _mu,
                'filename': _shalom,
                'directory': _juju,
                },
            'encoding': 'utf-8',
            }),
        ('iso-8859-1', {
            'info': {
                'committer': _erik,
                'message': u'Testing ' + _mu,
                'filename': _juju_alt,
                'directory': _shrimp_sandwich,
                },
            'encoding': 'iso-8859-1',
            }),
        ('iso-8859-2', {
            'info': {
                'committer': _someone,
                'message': _yellow_horse,
                'filename': _yellow,
                'directory': _something,
                },
            'encoding': 'iso-8859-2',
            }),
        ('cp1251', {
            'info': {
                'committer': _alexander,
                'message': u'Testing ' + _mu,
                'filename': _russian_test,
                'directory': _russian_test + 'dir',
                },
            'encoding': 'cp1251',
            }),
# The iso-8859-1 tests run on a default windows cp437 installation
# and it takes a long time to run an extra permutation of the tests
# But just in case we want to add this back in:
#        ('cp437', {'committer':_erik
#                  , 'message':u'Testing ' + _mu
#                  , 'filename':'file_' + _omega
#                  , 'directory':_epsilon + '_dir',
#            'encoding': 'cp437'}),
    ]