~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/EncodingAdapter.py

  • Committer: Matt Nordhoff
  • Date: 2009-04-04 02:50:01 UTC
  • mfrom: (4253 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4256.
  • Revision ID: mnordhoff@mattnordhoff.com-20090404025001-z1403k0tatmc8l91
Merge bzr.dev, fixing conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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
 
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 = [
 
82
encoding_scenarios = [
92
83
        # Permutation 1 of utf-8
93
 
        ('utf-8', 1, {'committer':_erik
94
 
                  , 'message':_yellow_horse
95
 
                  , 'filename':_shrimp_sandwich
96
 
                  , 'directory':_nihonjin}),
 
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
            }),
97
93
        # Permutation 2 of utf-8
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'}),
 
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
            }),
114
130
# The iso-8859-1 tests run on a default windows cp437 installation
115
131
# and it takes a long time to run an extra permutation of the tests
116
132
# But just in case we want to add this back in:
117
 
#        ('cp437', 0, {'committer':_erik
 
133
#        ('cp437', {'committer':_erik
118
134
#                  , 'message':u'Testing ' + _mu
119
135
#                  , 'filename':'file_' + _omega
120
 
#                  , 'directory':_epsilon + '_dir'}),
 
136
#                  , 'directory':_epsilon + '_dir',
 
137
#            'encoding': 'cp437'}),
121
138
    ]
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