1
# Copyright (C) 2006, 2009, 2010, 2011 Canonical Ltd
1
# Copyright (C) 2006 by Canonical Ltd
2
2
# -*- coding: utf-8 -*-
4
4
# This program is free software; you can redistribute it and/or modify
5
5
# it under the terms of the GNU General Public License as published by
6
6
# the Free Software Foundation; either version 2 of the License, or
7
7
# (at your option) any later version.
9
9
# This program is distributed in the hope that it will be useful,
10
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
12
# GNU General Public License for more details.
14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
"""Adapter for running test cases against multiple encodings."""
20
# prefix for micro (1/1000000)
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)
23
# greek letter omega, not to be confused with
24
# the Ohm sign, u'\u2126'. Though they are probably identical
25
# cp437 can handle the first, but not the second
28
# smallest error possible, epsilon
29
# cp437 handles u03b5, but not u2208 the 'element of' operator
33
30
_erik = u'Erik B\xe5gfors'
44
41
# Russian, 'Alexander' in russian
45
42
_alexander = u'\u0410\u043b\u0435\u043a\u0441\u0430\u043d\u0434\u0440'
46
# The word 'test' in Russian
47
_russian_test = u'\u0422\u0435\u0441\u0442'
43
# No idea if this means anything, but we need another string
44
_alex = u'\u0410\u043b\u0435\u043a'
50
47
# It is a kanji sequence for nihonjin, or Japanese in English.
52
49
# '\u4eba' being person, 'u\65e5' sun and '\u672c' origin. Ie,
53
50
# sun-origin-person, 'native from the land where the sun rises'. Note, I'm
54
51
# not a fluent speaker, so this is just my crude breakdown.
57
54
_nihonjin = u'\u65e5\u672c\u4eba'
73
70
# Shalom -> 'hello' or 'peace', used as a common greeting
74
71
_shalom = u'\u05e9\u05dc\u05d5\u05dd'
73
class EncodingTestAdapter(object):
74
"""A tool to generate a suite, testing multiple encodings for a single test.
76
This is similar to bzrlib.transport.TransportTestProviderAdapter.
77
It is done by copying the test once for each encoding, and injecting
78
the encoding name, and the list of valid strings for that encoding.
79
Each copy is also given a new id() to make it easy to identify.
77
encoding_scenarios = [
78
# Permutation 1 of utf-8
82
'message': _yellow_horse,
83
'filename': _shrimp_sandwich,
84
'directory': _nihonjin,
88
# Permutation 2 of utf-8
91
'committer': _alexander,
92
'message': u'Testing ' + _mu,
101
'message': u'Testing ' + _mu,
102
'filename': _juju_alt,
103
'directory': _shrimp_sandwich,
105
'encoding': 'iso-8859-1',
109
'committer': _someone,
110
'message': _yellow_horse,
112
'directory': _something,
114
'encoding': 'iso-8859-2',
118
'committer': _alexander,
119
'message': u'Testing ' + _mu,
120
'filename': _russian_test,
121
'directory': _russian_test + 'dir',
123
'encoding': 'cp1251',
125
# The iso-8859-1 tests run on a default windows cp437 installation
126
# and it takes a long time to run an extra permutation of the tests
127
# But just in case we want to add this back in:
128
# ('cp437', {'committer':_erik
129
# , 'message':u'Testing ' + _mu
130
# , 'filename':'file_' + _omega
131
# , 'directory':_epsilon + '_dir',
132
# 'encoding': 'cp437'}),
83
# Permutation 1 of utf-8
84
('utf-8', 1, {'committer':_erik
85
, 'message':_yellow_horse
86
, 'filename':_shrimp_sandwich
87
, 'directory':_nihonjin}),
88
# Permutation 2 of utf-8
89
('utf-8', 2, {'committer':_alexander
90
, 'message':u'Testing ' + _mu
92
, 'directory':_juju}),
93
('iso-8859-1', 0, {'committer':_erik
94
, 'message':u'Testing ' + _mu
95
, 'filename':_juju_alt
96
, 'directory':_shrimp_sandwich}),
97
('iso-8859-2', 0, {'committer':_someone
98
, 'message':_yellow_horse
100
, 'directory':_something}),
101
('cp1251', 0, {'committer':_alexander
102
, 'message':u'Testing ' + _mu
104
, 'directory':_alex + 'dir'}),
107
def adapt(self, test):
109
for encoding, count, info in self._encodings:
110
new_test = deepcopy(test)
111
new_test.encoding = encoding
113
def make_new_test_id():
115
new_id = "%s(%s,%s)" % (new_test.id(), encoding, count)
117
new_id = "%s(%s)" % (new_test.id(), encoding)
118
return lambda: new_id
119
new_test.id = make_new_test_id()
120
result.addTest(new_test)