~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/EncodingAdapter.py

  • Committer: Alexander Belchenko
  • Date: 2006-07-30 16:43:12 UTC
  • mto: (1711.2.111 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1906.
  • Revision ID: bialix@ukr.net-20060730164312-b025fd3ff0cee59e
rename  gpl.txt => COPYING.txt

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2006 by Canonical Ltd
2
2
# -*- coding: utf-8 -*-
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
13
13
#
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
17
17
 
18
18
"""Adapter for running test cases against multiple encodings."""
19
19
 
20
20
from copy import deepcopy
21
21
 
 
22
from bzrlib.tests import TestSuite
 
23
 
 
24
 
22
25
# prefix for micro (1/1000000)
23
26
_mu = u'\xb5'
24
27
 
50
53
 
51
54
# Kanji
52
55
# It is a kanji sequence for nihonjin, or Japanese in English.
53
 
#
 
56
54
57
# '\u4eba' being person, 'u\65e5' sun and '\u672c' origin. Ie,
55
58
# sun-origin-person, 'native from the land where the sun rises'. Note, I'm
56
59
# not a fluent speaker, so this is just my crude breakdown.
57
 
#
 
60
58
61
# Wouter van Heyst
59
62
_nihonjin = u'\u65e5\u672c\u4eba'
60
63
 
76
79
_shalom = u'\u05e9\u05dc\u05d5\u05dd'
77
80
 
78
81
 
79
 
encoding_scenarios = [
 
82
class EncodingTestAdapter(object):
 
83
    """A tool to generate a suite, testing multiple encodings for a single test.
 
84
    
 
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.
 
89
    """
 
90
 
 
91
    _encodings = [
80
92
        # Permutation 1 of utf-8
81
 
        ('utf-8,1', {
82
 
            'info': {
83
 
                'committer': _erik,
84
 
                'message': _yellow_horse,
85
 
                'filename': _shrimp_sandwich,
86
 
                'directory': _nihonjin,
87
 
                },
88
 
            'encoding': 'utf-8',
89
 
            }),
 
93
        ('utf-8', 1, {'committer':_erik
 
94
                  , 'message':_yellow_horse
 
95
                  , 'filename':_shrimp_sandwich
 
96
                  , 'directory':_nihonjin}),
90
97
        # Permutation 2 of utf-8
91
 
        ('utf-8,2', {
92
 
            'info': {
93
 
                'committer': _alexander,
94
 
                'message': u'Testing ' + _mu,
95
 
                'filename': _shalom,
96
 
                'directory': _juju,
97
 
                },
98
 
            'encoding': 'utf-8',
99
 
            }),
100
 
        ('iso-8859-1', {
101
 
            'info': {
102
 
                'committer': _erik,
103
 
                'message': u'Testing ' + _mu,
104
 
                'filename': _juju_alt,
105
 
                'directory': _shrimp_sandwich,
106
 
                },
107
 
            'encoding': 'iso-8859-1',
108
 
            }),
109
 
        ('iso-8859-2', {
110
 
            'info': {
111
 
                'committer': _someone,
112
 
                'message': _yellow_horse,
113
 
                'filename': _yellow,
114
 
                'directory': _something,
115
 
                },
116
 
            'encoding': 'iso-8859-2',
117
 
            }),
118
 
        ('cp1251', {
119
 
            'info': {
120
 
                'committer': _alexander,
121
 
                'message': u'Testing ' + _mu,
122
 
                'filename': _russian_test,
123
 
                'directory': _russian_test + 'dir',
124
 
                },
125
 
            'encoding': 'cp1251',
126
 
            }),
 
98
        ('utf-8', 2, {'committer':_alexander
 
99
                  , 'message':u'Testing ' + _mu
 
100
                  , 'filename':_shalom
 
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
 
108
                  , 'filename':_yellow
 
109
                  , 'directory':_something}),
 
110
        ('cp1251', 0, {'committer':_alexander
 
111
                  , 'message':u'Testing ' + _mu
 
112
                  , 'filename':_russian_test
 
113
                  , 'directory':_russian_test + 'dir'}),
127
114
# The iso-8859-1 tests run on a default windows cp437 installation
128
115
# and it takes a long time to run an extra permutation of the tests
129
116
# But just in case we want to add this back in:
130
 
#        ('cp437', {'committer':_erik
 
117
#        ('cp437', 0, {'committer':_erik
131
118
#                  , 'message':u'Testing ' + _mu
132
119
#                  , 'filename':'file_' + _omega
133
 
#                  , 'directory':_epsilon + '_dir',
134
 
#            'encoding': 'cp437'}),
 
120
#                  , 'directory':_epsilon + '_dir'}),
135
121
    ]
 
122
 
 
123
    def adapt(self, test):
 
124
        result = TestSuite()
 
125
        for encoding, count, info in self._encodings:
 
126
            new_test = deepcopy(test)
 
127
            new_test.encoding = encoding
 
128
            new_test.info = info
 
129
            def make_new_test_id():
 
130
                if count:
 
131
                    new_id = "%s(%s,%s)" % (new_test.id(), encoding, count)
 
132
                else:
 
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)
 
137
        return result
 
138
 
 
139