/brz/remove-bazaar

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