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