/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-05-02 20:46:11 UTC
  • mto: This revision was merged to the branch mainline in revision 1752.
  • Revision ID: john@arbash-meinel.com-20060502204611-02caa5c20fb84ef8
Moved url functions into bzrlib.urlutils

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006 by Canonical Ltd
 
2
# -*- coding: utf-8 -*-
 
3
 
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; either version 2 of the License, or
 
7
# (at your option) any later version.
 
8
 
 
9
# This program is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details.
 
13
 
 
14
# You should have received a copy of the GNU General Public License
 
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
 
17
 
 
18
"""\
 
19
Adapter for running test cases against multiple encodings.
 
20
"""
 
21
 
 
22
from copy import deepcopy
 
23
 
 
24
from bzrlib.tests import TestSuite
 
25
 
 
26
# prefix for micro (1/1000000)
 
27
_mu = u'\xb5'
 
28
 
 
29
# Swedish?
 
30
_erik = u'Erik B\xe5gfors'
 
31
 
 
32
# Swedish 'räksmörgås' means shrimp sandwich
 
33
_shrimp_sandwich = u'r\xe4ksm\xf6rg\xe5s'
 
34
 
 
35
# Arabic, probably only Unicode encodings can handle this one
 
36
_juju = u'\u062c\u0648\u062c\u0648'
 
37
 
 
38
# iso-8859-1 alternative for juju
 
39
_juju_alt = u'j\xfbj\xfa'
 
40
 
 
41
# Russian, 'Alexander' in russian
 
42
_alexander = u'\u0410\u043b\u0435\u043a\u0441\u0430\u043d\u0434\u0440'
 
43
# No idea if this means anything, but we need another string
 
44
_alex = u'\u0410\u043b\u0435\u043a'
 
45
 
 
46
# Kanji
 
47
# It is a kanji sequence for nihonjin, or Japanese in English.
 
48
 
49
# '\u4eba' being person, 'u\65e5' sun and '\u672c' origin. Ie,
 
50
# sun-origin-person, 'native from the land where the sun rises'. Note, I'm
 
51
# not a fluent speaker, so this is just my crude breakdown.
 
52
 
53
# Wouter van Heyst
 
54
_nihonjin = u'\u65e5\u672c\u4eba'
 
55
 
 
56
# Czech
 
57
# It's what is usually used for showing how fonts look, because it contains
 
58
# most accented characters, ie. in places where Englishman use 'Quick brown fox
 
59
# jumped over a lazy dog'. The literal translation of the Czech version would
 
60
# be something like 'Yellow horse groaned devilish codes'. Actually originally
 
61
# the last word used to be 'ódy' (odes). The 'k' was added as a pun when using
 
62
# the sentece to check whether one has properly set encoding.
 
63
_yellow_horse = (u'\u017dlu\u0165ou\u010dk\xfd k\u016f\u0148'
 
64
                 u' \xfap\u011bl \u010f\xe1belsk\xe9 k\xf3dy')
 
65
_yellow = u'\u017dlu\u0165ou\u010dk\xfd'
 
66
_someone = u'Some\u016f\u0148\u011b'
 
67
_something = u'\u0165ou\u010dk\xfd'
 
68
 
 
69
# Hebrew
 
70
# Shalom -> 'hello' or 'peace', used as a common greeting
 
71
_shalom = u'\u05e9\u05dc\u05d5\u05dd'
 
72
 
 
73
 
 
74
class EncodingTestAdapter(object):
 
75
    """A tool to generate a suite, testing multiple encodings for a single test.
 
76
    
 
77
    This is similar to bzrlib.transport.TransportTestProviderAdapter.
 
78
    It is done by copying the test once for each encoding, and injecting
 
79
    the encoding name, and the list of valid strings for that encoding.
 
80
    Each copy is also given a new id() to make it easy to identify.
 
81
    """
 
82
 
 
83
    _encodings = [
 
84
        # Permutation 1 of utf-8
 
85
        ('utf-8', 1, {'committer':_erik
 
86
                  , 'message':_yellow_horse
 
87
                  , 'filename':_shrimp_sandwich
 
88
                  , 'directory':_nihonjin}),
 
89
        # Permutation 2 of utf-8
 
90
        ('utf-8', 2, {'committer':_alexander
 
91
                  , 'message':u'Testing ' + _mu
 
92
                  , 'filename':_shalom
 
93
                  , 'directory':_juju}),
 
94
        ('iso-8859-1', 0, {'committer':_erik
 
95
                  , 'message':u'Testing ' + _mu
 
96
                  , 'filename':_juju_alt
 
97
                  , 'directory':_shrimp_sandwich}),
 
98
        ('iso-8859-2', 0, {'committer':_someone
 
99
                  , 'message':_yellow_horse
 
100
                  , 'filename':_yellow
 
101
                  , 'directory':_something}),
 
102
        ('cp1251', 0, {'committer':_alexander
 
103
                  , 'message':u'Testing ' + _mu
 
104
                  , 'filename':_alex
 
105
                  , 'directory':_alex + 'dir'}),
 
106
    ]
 
107
 
 
108
    def adapt(self, test):
 
109
        result = TestSuite()
 
110
        for encoding, count, info in self._encodings:
 
111
            new_test = deepcopy(test)
 
112
            new_test.encoding = encoding
 
113
            new_test.info = info
 
114
            def make_new_test_id():
 
115
                if count:
 
116
                    new_id = "%s(%s,%s)" % (new_test.id(), encoding, count)
 
117
                else:
 
118
                    new_id = "%s(%s)" % (new_test.id(), encoding)
 
119
                return lambda: new_id
 
120
            new_test.id = make_new_test_id()
 
121
            result.addTest(new_test)
 
122
        return result
 
123
 
 
124