~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/translations/utilities/tests/test_xpi_manifest.py

  • Committer: Jeroen Vermeulen
  • Date: 2010-01-06 06:15:11 UTC
  • mto: This revision was merged to the branch mainline in revision 10123.
  • Revision ID: jeroen.vermeulen@canonical.com-20100106061511-u2ydbxearl3es4g9
A leading newline in a manifest is now an error, so fix up breaking tests and add a new one.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
 
10
10
from lp.translations.utilities.xpi_manifest import XpiManifest
11
11
 
 
12
from lp.translations.interfaces.translationimporter import (
 
13
    TranslationFormatSyntaxError)
 
14
 
12
15
 
13
16
class XpiManifestTestCase(unittest.TestCase):
14
17
    """Test `XpiManifest`."""
38
41
            There are no usable
39
42
            locale lines
40
43
            in this file.
41
 
            """)
 
44
            """.lstrip())
42
45
        self.assertEqual(len(manifest._locales), 0)
43
46
        chrome_path, locale = manifest.getChromePathAndLocale('lines')
44
47
        self.failIf(chrome_path is not None, "Empty manifest matched a path.")
61
64
            locale bar en-US bardir/
62
65
            locale ixx en-US ixxdir/
63
66
            locale gna en-US gnadir/
64
 
            """)
 
67
            """.lstrip())
65
68
        self.assertEqual(len(manifest._locales), 4)
66
69
        self._checkSortOrder(manifest)
67
70
        for dir in ['gna', 'bar', 'ixx', 'foo']:
107
110
            locale okay fr foodir/
108
111
            locale overlong fr foordir/ etc. etc. etc.
109
112
            locale incomplete fr
110
 
            """)
 
113
            """.lstrip())
111
114
        self.assertEqual(len(manifest._locales), 1)
112
115
        chrome_path, locale = manifest.getChromePathAndLocale('foodir/x')
113
116
        self.failIf(chrome_path is None, "Garbage lines messed up match.")
119
122
        manifest = XpiManifest("""
120
123
            locale dup fy boppe
121
124
            locale dup fy boppe
122
 
            """)
 
125
            """.lstrip())
123
126
        self.assertEqual(len(manifest._locales), 1)
124
127
 
125
128
    def _checkLookup(self, manifest, path, chrome_path, locale):
162
165
        manifest = XpiManifest("""
163
166
            locale short el /ploink/squit
164
167
            locale long he /ploink/squittle
165
 
            """)
 
168
            """.lstrip())
166
169
        self._checkSortOrder(manifest)
167
170
        self._checkLookup(manifest, 'ploink/squit/x', 'short/x', 'el')
168
171
        self._checkLookup(manifest, '/ploink/squittle/x', 'long/x', 'he')
175
178
            locale foo2 ca a/b/
176
179
            locale foo3 ca a/b/c/x1
177
180
            locale foo4 ca a/b/c/x2
178
 
            """)
 
181
            """.lstrip())
179
182
        self._checkSortOrder(manifest)
180
183
        self._checkLookup(manifest, 'a/bb', 'foo1/bb', 'ca')
181
184
        self._checkLookup(manifest, 'a/bb/c', 'foo1/bb/c', 'ca')
190
193
        manifest = XpiManifest("""
191
194
            locale foo en_GB jar:foo.jar!/dir/
192
195
            locale bar id jar:bar.jar!/
193
 
            """)
 
196
            """.lstrip())
194
197
        self._checkSortOrder(manifest)
195
198
        self._checkLookup(
196
199
            manifest, 'jar:foo.jar!/dir/file', 'foo/file', 'en_GB')
227
230
            locale croatian hr jar:translations.jar!/hr/
228
231
            locale docs sr jar:docs.jar!/sr/
229
232
            locale docs hr jar:docs.jar!/hr/
230
 
            """)
 
233
            """.lstrip())
231
234
        self._checkSortOrder(manifest)
232
235
        self._checkLookup(
233
236
            manifest, 'jar:translations.jar!/sr/x', 'serbian/x', 'sr')
242
245
            locale x it jar:dir/x.jar!/subdir/y.jar!/
243
246
            locale y it jar:dir/x.jar!/subdir/y.jar!/deep/
244
247
            locale z it jar:dir/x.jar!/subdir/z.jar!/
245
 
            """)
 
248
            """.lstrip())
246
249
        self._checkSortOrder(manifest)
247
250
        self._checkLookup(
248
251
            manifest, 'jar:dir/x.jar!/subdir/y.jar!/foo', 'x/foo', 'it')
291
294
            locale browser en-US jar:locales/
292
295
            locale browser en-US jar:locales/en-US.jar!/chrome/
293
296
            locale browser en-US jar:locales/en-US.jar!/
294
 
            """)
 
297
            """.lstrip())
295
298
        path = manifest.findMatchingXpiPath('browser/gui/print.dtd', 'en-US')
296
299
        self.assertEqual(path, "jar:locales/en-US.jar!/chrome/gui/print.dtd")
297
300
 
 
301
    def test_blank_line(self):
 
302
        # Manifests must not begin with newline.
 
303
        self.assertRaises(
 
304
            TranslationFormatSyntaxError,
 
305
            XpiManifest, """
 
306
            locale browser en-US jar:locales
 
307
            """)
 
308
 
298
309
 
299
310
def test_suite():
300
311
    return unittest.defaultTestLoader.loadTestsFromName(__name__)