Debian Codegraph @

python/mozbuild/mozpack/test/test_packager_l10n.py

raw
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/.
4
5 import unittest
6
7 import mozunit
8
9 from mozpack.chrome.manifest import Manifest, ManifestContent, ManifestLocale
10 from mozpack.copier import FileRegistry
11 from mozpack.files import GeneratedFile, ManifestFile
12 from mozpack.packager import l10n
13 from test_packager import MockFinder
14
15
16 class TestL10NRepack(unittest.TestCase):
17 def test_l10n_repack(self):
18 foo = GeneratedFile(b"foo")
19 foobar = GeneratedFile(b"foobar")
20 qux = GeneratedFile(b"qux")
21 bar = GeneratedFile(b"bar")
22 baz = GeneratedFile(b"baz")
23 dict_aa = GeneratedFile(b"dict_aa")
24 dict_bb = GeneratedFile(b"dict_bb")
25 dict_cc = GeneratedFile(b"dict_cc")
26 barbaz = GeneratedFile(b"barbaz")
27 lst = GeneratedFile(b"foo\nbar")
28 app_finder = MockFinder(
29 {
30 "bar/foo": foo,
31 "chrome/foo/foobar": foobar,
32 "chrome/qux/qux.properties": qux,
33 "chrome/qux/baz/baz.properties": baz,
34 "chrome/chrome.manifest": ManifestFile(
35 "chrome",
36 [
37 ManifestContent("chrome", "foo", "foo/"),
38 ManifestLocale("chrome", "qux", "en-US", "qux/"),
39 ],
40 ),
41 "chrome.manifest": ManifestFile(
42 "", [Manifest("", "chrome/chrome.manifest")]
43 ),
44 "dict/aa": dict_aa,
45 "app/chrome/bar/barbaz.dtd": barbaz,
46 "app/chrome/chrome.manifest": ManifestFile(
47 "app/chrome", [ManifestLocale("app/chrome", "bar", "en-US", "bar/")]
48 ),
49 "app/chrome.manifest": ManifestFile(
50 "app", [Manifest("app", "chrome/chrome.manifest")]
51 ),
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 "META-INF/foo": foo, # Stripped.
58 "inner/META-INF/foo": foo, # Not stripped.
59 "app/META-INF/foo": foo, # Stripped.
60 "app/inner/META-INF/foo": foo, # Not stripped.
61 }
62 )
63 app_finder.jarlogs = {}
64 app_finder.base = "app"
65 foo_l10n = GeneratedFile(b"foo_l10n")
66 qux_l10n = GeneratedFile(b"qux_l10n")
67 baz_l10n = GeneratedFile(b"baz_l10n")
68 barbaz_l10n = GeneratedFile(b"barbaz_l10n")
69 lst_l10n = GeneratedFile(b"foo\nqux")
70 l10n_finder = MockFinder(
71 {
72 "chrome/qux-l10n/qux.properties": qux_l10n,
73 "chrome/qux-l10n/baz/baz.properties": baz_l10n,
74 "chrome/chrome.manifest": ManifestFile(
75 "chrome",
76 [
77 ManifestLocale("chrome", "qux", "x-test", "qux-l10n/"),
78 ],
79 ),
80 "chrome.manifest": ManifestFile(
81 "", [Manifest("", "chrome/chrome.manifest")]
82 ),
83 "dict/bb": dict_bb,
84 "dict/cc": dict_cc,
85 "app/chrome/bar-l10n/barbaz.dtd": barbaz_l10n,
86 "app/chrome/chrome.manifest": ManifestFile(
87 "app/chrome",
88 [ManifestLocale("app/chrome", "bar", "x-test", "bar-l10n/")],
89 ),
90 "app/chrome.manifest": ManifestFile(
91 "app", [Manifest("app", "chrome/chrome.manifest")]
92 ),
93 "app/dict/aa": dict_aa,
94 "app/chrome/bar-l10n/search/foo.xml": foo_l10n,
95 "app/chrome/bar-l10n/search/qux.xml": qux_l10n,
96 "app/chrome/bar-l10n/search/lst.txt": lst_l10n,
97 }
98 )
99 l10n_finder.base = "l10n"
100 copier = FileRegistry()
101 formatter = l10n.FlatFormatter(copier)
102
103 l10n._repack(
104 app_finder,
105 l10n_finder,
106 copier,
107 formatter,
108 ["dict", "chrome/**/search/*.xml"],
109 )
110 self.maxDiff = None
111
112 repacked = {
113 "bar/foo": foo,
114 "chrome/foo/foobar": foobar,
115 "chrome/qux-l10n/qux.properties": qux_l10n,
116 "chrome/qux-l10n/baz/baz.properties": baz_l10n,
117 "chrome/chrome.manifest": ManifestFile(
118 "chrome",
119 [
120 ManifestContent("chrome", "foo", "foo/"),
121 ManifestLocale("chrome", "qux", "x-test", "qux-l10n/"),
122 ],
123 ),
124 "chrome.manifest": ManifestFile(
125 "", [Manifest("", "chrome/chrome.manifest")]
126 ),
127 "dict/bb": dict_bb,
128 "dict/cc": dict_cc,
129 "app/chrome/bar-l10n/barbaz.dtd": barbaz_l10n,
130 "app/chrome/chrome.manifest": ManifestFile(
131 "app/chrome",
132 [ManifestLocale("app/chrome", "bar", "x-test", "bar-l10n/")],
133 ),
134 "app/chrome.manifest": ManifestFile(
135 "app", [Manifest("app", "chrome/chrome.manifest")]
136 ),
137 "app/dict/aa": dict_aa,
138 "app/chrome/bar-l10n/search/foo.xml": foo_l10n,
139 "app/chrome/bar-l10n/search/qux.xml": qux_l10n,
140 "app/chrome/bar-l10n/search/lst.txt": lst_l10n,
141 "inner/META-INF/foo": foo,
142 "app/inner/META-INF/foo": foo,
143 }
144
145 self.assertEqual(
146 dict((p, f.open().read()) for p, f in copier),
147 dict((p, f.open().read()) for p, f in repacked.items()),
148 )
149
150
151 if __name__ == "__main__":
152 mozunit.main()