python/mozbuild/mozpack/test/test_packager_l10n.py

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

michael@0 1 # This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 # License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 4
michael@0 5 import unittest
michael@0 6 import mozunit
michael@0 7 from test_packager import MockFinder
michael@0 8 from mozpack.packager import l10n
michael@0 9 from mozpack.files import (
michael@0 10 GeneratedFile,
michael@0 11 ManifestFile,
michael@0 12 )
michael@0 13 from mozpack.chrome.manifest import (
michael@0 14 Manifest,
michael@0 15 ManifestLocale,
michael@0 16 ManifestContent,
michael@0 17 )
michael@0 18 from mozpack.copier import FileRegistry
michael@0 19 from mozpack.packager.formats import FlatFormatter
michael@0 20
michael@0 21
michael@0 22 class TestL10NRepack(unittest.TestCase):
michael@0 23 def test_l10n_repack(self):
michael@0 24 foo = GeneratedFile('foo')
michael@0 25 foobar = GeneratedFile('foobar')
michael@0 26 qux = GeneratedFile('qux')
michael@0 27 bar = GeneratedFile('bar')
michael@0 28 baz = GeneratedFile('baz')
michael@0 29 dict_aa = GeneratedFile('dict_aa')
michael@0 30 dict_bb = GeneratedFile('dict_bb')
michael@0 31 dict_cc = GeneratedFile('dict_cc')
michael@0 32 barbaz = GeneratedFile('barbaz')
michael@0 33 lst = GeneratedFile('foo\nbar')
michael@0 34 app_finder = MockFinder({
michael@0 35 'bar/foo': foo,
michael@0 36 'chrome/foo/foobar': foobar,
michael@0 37 'chrome/qux/qux.properties': qux,
michael@0 38 'chrome/qux/baz/baz.properties': baz,
michael@0 39 'chrome/chrome.manifest': ManifestFile('chrome', [
michael@0 40 ManifestContent('chrome', 'foo', 'foo/'),
michael@0 41 ManifestLocale('chrome', 'qux', 'en-US', 'qux/'),
michael@0 42 ]),
michael@0 43 'chrome.manifest':
michael@0 44 ManifestFile('', [Manifest('', 'chrome/chrome.manifest')]),
michael@0 45 'dict/aa': dict_aa,
michael@0 46 'app/chrome/bar/barbaz.dtd': barbaz,
michael@0 47 'app/chrome/chrome.manifest': ManifestFile('app/chrome', [
michael@0 48 ManifestLocale('app/chrome', 'bar', 'en-US', 'bar/')
michael@0 49 ]),
michael@0 50 'app/chrome.manifest':
michael@0 51 ManifestFile('app', [Manifest('app', 'chrome/chrome.manifest')]),
michael@0 52 'app/dict/bb': dict_bb,
michael@0 53 'app/dict/cc': dict_cc,
michael@0 54 'app/chrome/bar/search/foo.xml': foo,
michael@0 55 'app/chrome/bar/search/bar.xml': bar,
michael@0 56 'app/chrome/bar/search/lst.txt': lst,
michael@0 57 })
michael@0 58 app_finder.jarlogs = {}
michael@0 59 app_finder.base = 'app'
michael@0 60 foo_l10n = GeneratedFile('foo_l10n')
michael@0 61 qux_l10n = GeneratedFile('qux_l10n')
michael@0 62 baz_l10n = GeneratedFile('baz_l10n')
michael@0 63 barbaz_l10n = GeneratedFile('barbaz_l10n')
michael@0 64 lst_l10n = GeneratedFile('foo\nqux')
michael@0 65 l10n_finder = MockFinder({
michael@0 66 'chrome/qux-l10n/qux.properties': qux_l10n,
michael@0 67 'chrome/qux-l10n/baz/baz.properties': baz_l10n,
michael@0 68 'chrome/chrome.manifest': ManifestFile(' chrome', [
michael@0 69 ManifestLocale('chrome', 'qux', 'x-test', 'qux-l10n/'),
michael@0 70 ]),
michael@0 71 'chrome.manifest':
michael@0 72 ManifestFile('', [Manifest('', 'chrome/chrome.manifest')]),
michael@0 73 'dict/bb': dict_bb,
michael@0 74 'dict/cc': dict_cc,
michael@0 75 'app/chrome/bar-l10n/barbaz.dtd': barbaz_l10n,
michael@0 76 'app/chrome/chrome.manifest': ManifestFile('app/chrome', [
michael@0 77 ManifestLocale('app/chrome', 'bar', 'x-test', 'bar-l10n/')
michael@0 78 ]),
michael@0 79 'app/chrome.manifest':
michael@0 80 ManifestFile('app', [Manifest('app', 'chrome/chrome.manifest')]),
michael@0 81 'app/dict/aa': dict_aa,
michael@0 82 'app/chrome/bar-l10n/search/foo.xml': foo_l10n,
michael@0 83 'app/chrome/bar-l10n/search/qux.xml': qux_l10n,
michael@0 84 'app/chrome/bar-l10n/search/lst.txt': lst_l10n,
michael@0 85 })
michael@0 86 l10n_finder.base = 'l10n'
michael@0 87 copier = FileRegistry()
michael@0 88 formatter = FlatFormatter(copier)
michael@0 89
michael@0 90 l10n._repack(app_finder, l10n_finder, copier, formatter,
michael@0 91 ['dict', 'chrome/**/search/*.xml'])
michael@0 92 self.maxDiff = None
michael@0 93
michael@0 94 repacked = {
michael@0 95 'bar/foo': foo,
michael@0 96 'chrome/foo/foobar': foobar,
michael@0 97 'chrome/qux-l10n/qux.properties': qux_l10n,
michael@0 98 'chrome/qux-l10n/baz/baz.properties': baz_l10n,
michael@0 99 'chrome/chrome.manifest': ManifestFile('chrome', [
michael@0 100 ManifestContent('chrome', 'foo', 'foo/'),
michael@0 101 ManifestLocale('chrome', 'qux', 'x-test', 'qux-l10n/'),
michael@0 102 ]),
michael@0 103 'chrome.manifest':
michael@0 104 ManifestFile('', [Manifest('', 'chrome/chrome.manifest')]),
michael@0 105 'dict/bb': dict_bb,
michael@0 106 'dict/cc': dict_cc,
michael@0 107 'app/chrome/bar-l10n/barbaz.dtd': barbaz_l10n,
michael@0 108 'app/chrome/chrome.manifest': ManifestFile('app/chrome', [
michael@0 109 ManifestLocale('app/chrome', 'bar', 'x-test', 'bar-l10n/')
michael@0 110 ]),
michael@0 111 'app/chrome.manifest':
michael@0 112 ManifestFile('app', [Manifest('app', 'chrome/chrome.manifest')]),
michael@0 113 'app/dict/aa': dict_aa,
michael@0 114 'app/chrome/bar-l10n/search/foo.xml': foo_l10n,
michael@0 115 'app/chrome/bar-l10n/search/qux.xml': qux_l10n,
michael@0 116 'app/chrome/bar-l10n/search/lst.txt': lst_l10n,
michael@0 117 }
michael@0 118
michael@0 119 self.assertEqual(
michael@0 120 dict((p, f.open().read()) for p, f in copier),
michael@0 121 dict((p, f.open().read()) for p, f in repacked.iteritems())
michael@0 122 )
michael@0 123
michael@0 124
michael@0 125 if __name__ == '__main__':
michael@0 126 mozunit.main()

mercurial