/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/EncodingAdapter.py

  • Committer: John Arbash Meinel
  • Date: 2006-06-11 02:46:51 UTC
  • mto: (1711.7.2 win32)
  • mto: This revision was merged to the branch mainline in revision 1796.
  • Revision ID: john@arbash-meinel.com-20060611024651-720ff62ba21f9690
Pull out sys.stdout.encoding handling into a separate function so it can be tested, and used elsewhere.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 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
 
53
53
 
54
54
# Kanji
55
55
# It is a kanji sequence for nihonjin, or Japanese in English.
56
 
#
 
56
57
57
# '\u4eba' being person, 'u\65e5' sun and '\u672c' origin. Ie,
58
58
# sun-origin-person, 'native from the land where the sun rises'. Note, I'm
59
59
# not a fluent speaker, so this is just my crude breakdown.
60
 
#
 
60
61
61
# Wouter van Heyst
62
62
_nihonjin = u'\u65e5\u672c\u4eba'
63
63
 
79
79
_shalom = u'\u05e9\u05dc\u05d5\u05dd'
80
80
 
81
81
 
82
 
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 = [
83
92
        # Permutation 1 of utf-8
84
 
        ('utf-8,1', {
85
 
            'info': {
86
 
                'committer': _erik,
87
 
                'message': _yellow_horse,
88
 
                'filename': _shrimp_sandwich,
89
 
                'directory': _nihonjin,
90
 
                },
91
 
            'encoding': 'utf-8',
92
 
            }),
 
93
        ('utf-8', 1, {'committer':_erik
 
94
                  , 'message':_yellow_horse
 
95
                  , 'filename':_shrimp_sandwich
 
96
                  , 'directory':_nihonjin}),
93
97
        # Permutation 2 of utf-8
94
 
        ('utf-8,2', {
95
 
            'info': {
96
 
                'committer': _alexander,
97
 
                'message': u'Testing ' + _mu,
98
 
                'filename': _shalom,
99
 
                'directory': _juju,
100
 
                },
101
 
            'encoding': 'utf-8',
102
 
            }),
103
 
        ('iso-8859-1', {
104
 
            'info': {
105
 
                'committer': _erik,
106
 
                'message': u'Testing ' + _mu,
107
 
                'filename': _juju_alt,
108
 
                'directory': _shrimp_sandwich,
109
 
                },
110
 
            'encoding': 'iso-8859-1',
111
 
            }),
112
 
        ('iso-8859-2', {
113
 
            'info': {
114
 
                'committer': _someone,
115
 
                'message': _yellow_horse,
116
 
                'filename': _yellow,
117
 
                'directory': _something,
118
 
                },
119
 
            'encoding': 'iso-8859-2',
120
 
            }),
121
 
        ('cp1251', {
122
 
            'info': {
123
 
                'committer': _alexander,
124
 
                'message': u'Testing ' + _mu,
125
 
                'filename': _russian_test,
126
 
                'directory': _russian_test + 'dir',
127
 
                },
128
 
            'encoding': 'cp1251',
129
 
            }),
130
 
# The iso-8859-1 tests run on a default windows cp437 installation
131
 
# and it takes a long time to run an extra permutation of the tests
132
 
# But just in case we want to add this back in:
133
 
#        ('cp437', {'committer':_erik
134
 
#                  , 'message':u'Testing ' + _mu
135
 
#                  , 'filename':'file_' + _omega
136
 
#                  , 'directory':_epsilon + '_dir',
137
 
#            'encoding': 'cp437'}),
 
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'}),
 
114
        ('cp437', 0, {'committer':_erik
 
115
                  , 'message':u'Testing ' + _mu
 
116
                  , 'filename':'file_' + _omega
 
117
                  , 'directory':_epsilon + '_dir'}),
138
118
    ]
 
119
 
 
120
    def adapt(self, test):
 
121
        result = TestSuite()
 
122
        for encoding, count, info in self._encodings:
 
123
            new_test = deepcopy(test)
 
124
            new_test.encoding = encoding
 
125
            new_test.info = info
 
126
            def make_new_test_id():
 
127
                if count:
 
128
                    new_id = "%s(%s,%s)" % (new_test.id(), encoding, count)
 
129
                else:
 
130
                    new_id = "%s(%s)" % (new_test.id(), encoding)
 
131
                return lambda: new_id
 
132
            new_test.id = make_new_test_id()
 
133
            result.addTest(new_test)
 
134
        return result
 
135
 
 
136