1
# Copyright (C) 2006 by Canonical Ltd
2
# -*- coding: utf-8 -*-
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.
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.
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
19
Adapter for running test cases against multiple encodings.
22
from copy import deepcopy
24
from bzrlib.tests import TestSuite
26
# prefix for micro (1/1000)
30
_erik = u'Erik B\xe5gfors'
32
# Swedish 'räksmörgås' means shrimp sandwich
33
_shrimp_sandwich = u'r\xe4ksm\xf6rg\xe5s'
35
# Arabic, probably only Unicode encodings can handle this one
36
_juju = u'\u062c\u0648\u062c\u0648'
38
# iso-8859-1 alternative for juju
39
_juju_alt = u'j\xfbj\xfa'
41
# Russian, 'Alexander' in russian
42
_alexander = u'\u0410\u043b\u0435\u043a\u0441\u0430\u043d\u0434\u0440'
45
# It is a kanji sequence for nihonjin, or Japanese in English.
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.
52
_nihonjin = u'\u65e5\u672c\u4eba'
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')
65
class EncodingTestAdapter(object):
66
"""A tool to generate a suite, testing multiple encodings for a single test.
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.
74
def adapt(self, test):
76
for encoding, info in self._test_permutations():
77
new_test = deepcopy(test)
78
new_test.encoding = encoding
81
return '%s(%s)' % (new_test.id(), encoding)
82
new_test.id = new_test_id
83
result.addTest(new_test)
86
def _test_permutations(self):
87
"""Return a list of encoding/info pairs to test.
89
encoding should be a string such as 'utf-8'
90
info is a dictionary containing 'committer', 'filename', 'message',
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
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'}),