test_packager_l10n.py (5649B)
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 "bar/foo": foo, 30 "chrome/foo/foobar": foobar, 31 "chrome/qux/qux.properties": qux, 32 "chrome/qux/baz/baz.properties": baz, 33 "chrome/chrome.manifest": ManifestFile( 34 "chrome", 35 [ 36 ManifestContent("chrome", "foo", "foo/"), 37 ManifestLocale("chrome", "qux", "en-US", "qux/"), 38 ], 39 ), 40 "chrome.manifest": ManifestFile( 41 "", [Manifest("", "chrome/chrome.manifest")] 42 ), 43 "dict/aa": dict_aa, 44 "app/chrome/bar/barbaz.dtd": barbaz, 45 "app/chrome/chrome.manifest": ManifestFile( 46 "app/chrome", [ManifestLocale("app/chrome", "bar", "en-US", "bar/")] 47 ), 48 "app/chrome.manifest": ManifestFile( 49 "app", [Manifest("app", "chrome/chrome.manifest")] 50 ), 51 "app/dict/bb": dict_bb, 52 "app/dict/cc": dict_cc, 53 "app/chrome/bar/search/foo.xml": foo, 54 "app/chrome/bar/search/bar.xml": bar, 55 "app/chrome/bar/search/lst.txt": lst, 56 "META-INF/foo": foo, # Stripped. 57 "inner/META-INF/foo": foo, # Not stripped. 58 "app/META-INF/foo": foo, # Stripped. 59 "app/inner/META-INF/foo": foo, # Not stripped. 60 }) 61 app_finder.jarlogs = {} 62 app_finder.base = "app" 63 foo_l10n = GeneratedFile(b"foo_l10n") 64 qux_l10n = GeneratedFile(b"qux_l10n") 65 baz_l10n = GeneratedFile(b"baz_l10n") 66 barbaz_l10n = GeneratedFile(b"barbaz_l10n") 67 lst_l10n = GeneratedFile(b"foo\nqux") 68 l10n_finder = MockFinder({ 69 "chrome/qux-l10n/qux.properties": qux_l10n, 70 "chrome/qux-l10n/baz/baz.properties": baz_l10n, 71 "chrome/chrome.manifest": ManifestFile( 72 "chrome", 73 [ 74 ManifestLocale("chrome", "qux", "x-test", "qux-l10n/"), 75 ], 76 ), 77 "chrome.manifest": ManifestFile( 78 "", [Manifest("", "chrome/chrome.manifest")] 79 ), 80 "dict/bb": dict_bb, 81 "dict/cc": dict_cc, 82 "app/chrome/bar-l10n/barbaz.dtd": barbaz_l10n, 83 "app/chrome/chrome.manifest": ManifestFile( 84 "app/chrome", 85 [ManifestLocale("app/chrome", "bar", "x-test", "bar-l10n/")], 86 ), 87 "app/chrome.manifest": ManifestFile( 88 "app", [Manifest("app", "chrome/chrome.manifest")] 89 ), 90 "app/dict/aa": dict_aa, 91 "app/chrome/bar-l10n/search/foo.xml": foo_l10n, 92 "app/chrome/bar-l10n/search/qux.xml": qux_l10n, 93 "app/chrome/bar-l10n/search/lst.txt": lst_l10n, 94 }) 95 l10n_finder.base = "l10n" 96 copier = FileRegistry() 97 formatter = l10n.FlatFormatter(copier) 98 99 l10n._repack( 100 app_finder, 101 l10n_finder, 102 copier, 103 formatter, 104 ["dict", "chrome/**/search/*.xml"], 105 ) 106 self.maxDiff = None 107 108 repacked = { 109 "bar/foo": foo, 110 "chrome/foo/foobar": foobar, 111 "chrome/qux-l10n/qux.properties": qux_l10n, 112 "chrome/qux-l10n/baz/baz.properties": baz_l10n, 113 "chrome/chrome.manifest": ManifestFile( 114 "chrome", 115 [ 116 ManifestContent("chrome", "foo", "foo/"), 117 ManifestLocale("chrome", "qux", "x-test", "qux-l10n/"), 118 ], 119 ), 120 "chrome.manifest": ManifestFile( 121 "", [Manifest("", "chrome/chrome.manifest")] 122 ), 123 "dict/bb": dict_bb, 124 "dict/cc": dict_cc, 125 "app/chrome/bar-l10n/barbaz.dtd": barbaz_l10n, 126 "app/chrome/chrome.manifest": ManifestFile( 127 "app/chrome", 128 [ManifestLocale("app/chrome", "bar", "x-test", "bar-l10n/")], 129 ), 130 "app/chrome.manifest": ManifestFile( 131 "app", [Manifest("app", "chrome/chrome.manifest")] 132 ), 133 "app/dict/aa": dict_aa, 134 "app/chrome/bar-l10n/search/foo.xml": foo_l10n, 135 "app/chrome/bar-l10n/search/qux.xml": qux_l10n, 136 "app/chrome/bar-l10n/search/lst.txt": lst_l10n, 137 "inner/META-INF/foo": foo, 138 "app/inner/META-INF/foo": foo, 139 } 140 141 self.assertEqual( 142 dict((p, f.open().read()) for p, f in copier), 143 dict((p, f.open().read()) for p, f in repacked.items()), 144 ) 145 146 147 if __name__ == "__main__": 148 mozunit.main()