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
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
18
"""Adapter for running test cases against multiple encodings."""
20
from copy import deepcopy
22
from bzrlib.tests import TestSuite
20
25
# prefix for micro (1/1000000)
74
79
_shalom = u'\u05e9\u05dc\u05d5\u05dd'
77
encoding_scenarios = [
82
class EncodingTestAdapter(object):
83
"""A tool to generate a suite, testing multiple encodings for a single test.
85
This is similar to bzrlib.transport.TransportTestProviderAdapter.
86
It is done by copying the test once for each encoding, and injecting
87
the encoding name, and the list of valid strings for that encoding.
88
Each copy is also given a new id() to make it easy to identify.
78
92
# Permutation 1 of utf-8
82
'message': _yellow_horse,
83
'filename': _shrimp_sandwich,
84
'directory': _nihonjin,
93
('utf-8', 1, {'committer':_erik
94
, 'message':_yellow_horse
95
, 'filename':_shrimp_sandwich
96
, 'directory':_nihonjin}),
88
97
# 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',
98
('utf-8', 2, {'committer':_alexander
99
, 'message':u'Testing ' + _mu
101
, 'directory':_juju}),
102
('iso-8859-1', 0, {'committer':_erik
103
, 'message':u'Testing ' + _mu
104
, 'filename':_juju_alt
105
, 'directory':_shrimp_sandwich}),
106
('iso-8859-2', 0, {'committer':_someone
107
, 'message':_yellow_horse
109
, 'directory':_something}),
110
('cp1251', 0, {'committer':_alexander
111
, 'message':u'Testing ' + _mu
112
, 'filename':_russian_test
113
, 'directory':_russian_test + 'dir'}),
125
114
# The iso-8859-1 tests run on a default windows cp437 installation
126
115
# and it takes a long time to run an extra permutation of the tests
127
116
# But just in case we want to add this back in:
128
# ('cp437', {'committer':_erik
117
# ('cp437', 0, {'committer':_erik
129
118
# , 'message':u'Testing ' + _mu
130
119
# , 'filename':'file_' + _omega
131
# , 'directory':_epsilon + '_dir',
132
# 'encoding': 'cp437'}),
120
# , 'directory':_epsilon + '_dir'}),
123
def adapt(self, test):
125
for encoding, count, info in self._encodings:
126
new_test = deepcopy(test)
127
new_test.encoding = encoding
129
def make_new_test_id():
131
new_id = "%s(%s,%s)" % (new_test.id(), encoding, count)
133
new_id = "%s(%s)" % (new_test.id(), encoding)
134
return lambda: new_id
135
new_test.id = make_new_test_id()
136
result.addTest(new_test)