michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: import unittest michael@0: import mozunit michael@0: from test_packager import MockFinder michael@0: from mozpack.packager import l10n michael@0: from mozpack.files import ( michael@0: GeneratedFile, michael@0: ManifestFile, michael@0: ) michael@0: from mozpack.chrome.manifest import ( michael@0: Manifest, michael@0: ManifestLocale, michael@0: ManifestContent, michael@0: ) michael@0: from mozpack.copier import FileRegistry michael@0: from mozpack.packager.formats import FlatFormatter michael@0: michael@0: michael@0: class TestL10NRepack(unittest.TestCase): michael@0: def test_l10n_repack(self): michael@0: foo = GeneratedFile('foo') michael@0: foobar = GeneratedFile('foobar') michael@0: qux = GeneratedFile('qux') michael@0: bar = GeneratedFile('bar') michael@0: baz = GeneratedFile('baz') michael@0: dict_aa = GeneratedFile('dict_aa') michael@0: dict_bb = GeneratedFile('dict_bb') michael@0: dict_cc = GeneratedFile('dict_cc') michael@0: barbaz = GeneratedFile('barbaz') michael@0: lst = GeneratedFile('foo\nbar') michael@0: app_finder = MockFinder({ michael@0: 'bar/foo': foo, michael@0: 'chrome/foo/foobar': foobar, michael@0: 'chrome/qux/qux.properties': qux, michael@0: 'chrome/qux/baz/baz.properties': baz, michael@0: 'chrome/chrome.manifest': ManifestFile('chrome', [ michael@0: ManifestContent('chrome', 'foo', 'foo/'), michael@0: ManifestLocale('chrome', 'qux', 'en-US', 'qux/'), michael@0: ]), michael@0: 'chrome.manifest': michael@0: ManifestFile('', [Manifest('', 'chrome/chrome.manifest')]), michael@0: 'dict/aa': dict_aa, michael@0: 'app/chrome/bar/barbaz.dtd': barbaz, michael@0: 'app/chrome/chrome.manifest': ManifestFile('app/chrome', [ michael@0: ManifestLocale('app/chrome', 'bar', 'en-US', 'bar/') michael@0: ]), michael@0: 'app/chrome.manifest': michael@0: ManifestFile('app', [Manifest('app', 'chrome/chrome.manifest')]), michael@0: 'app/dict/bb': dict_bb, michael@0: 'app/dict/cc': dict_cc, michael@0: 'app/chrome/bar/search/foo.xml': foo, michael@0: 'app/chrome/bar/search/bar.xml': bar, michael@0: 'app/chrome/bar/search/lst.txt': lst, michael@0: }) michael@0: app_finder.jarlogs = {} michael@0: app_finder.base = 'app' michael@0: foo_l10n = GeneratedFile('foo_l10n') michael@0: qux_l10n = GeneratedFile('qux_l10n') michael@0: baz_l10n = GeneratedFile('baz_l10n') michael@0: barbaz_l10n = GeneratedFile('barbaz_l10n') michael@0: lst_l10n = GeneratedFile('foo\nqux') michael@0: l10n_finder = MockFinder({ michael@0: 'chrome/qux-l10n/qux.properties': qux_l10n, michael@0: 'chrome/qux-l10n/baz/baz.properties': baz_l10n, michael@0: 'chrome/chrome.manifest': ManifestFile(' chrome', [ michael@0: ManifestLocale('chrome', 'qux', 'x-test', 'qux-l10n/'), michael@0: ]), michael@0: 'chrome.manifest': michael@0: ManifestFile('', [Manifest('', 'chrome/chrome.manifest')]), michael@0: 'dict/bb': dict_bb, michael@0: 'dict/cc': dict_cc, michael@0: 'app/chrome/bar-l10n/barbaz.dtd': barbaz_l10n, michael@0: 'app/chrome/chrome.manifest': ManifestFile('app/chrome', [ michael@0: ManifestLocale('app/chrome', 'bar', 'x-test', 'bar-l10n/') michael@0: ]), michael@0: 'app/chrome.manifest': michael@0: ManifestFile('app', [Manifest('app', 'chrome/chrome.manifest')]), michael@0: 'app/dict/aa': dict_aa, michael@0: 'app/chrome/bar-l10n/search/foo.xml': foo_l10n, michael@0: 'app/chrome/bar-l10n/search/qux.xml': qux_l10n, michael@0: 'app/chrome/bar-l10n/search/lst.txt': lst_l10n, michael@0: }) michael@0: l10n_finder.base = 'l10n' michael@0: copier = FileRegistry() michael@0: formatter = FlatFormatter(copier) michael@0: michael@0: l10n._repack(app_finder, l10n_finder, copier, formatter, michael@0: ['dict', 'chrome/**/search/*.xml']) michael@0: self.maxDiff = None michael@0: michael@0: repacked = { michael@0: 'bar/foo': foo, michael@0: 'chrome/foo/foobar': foobar, michael@0: 'chrome/qux-l10n/qux.properties': qux_l10n, michael@0: 'chrome/qux-l10n/baz/baz.properties': baz_l10n, michael@0: 'chrome/chrome.manifest': ManifestFile('chrome', [ michael@0: ManifestContent('chrome', 'foo', 'foo/'), michael@0: ManifestLocale('chrome', 'qux', 'x-test', 'qux-l10n/'), michael@0: ]), michael@0: 'chrome.manifest': michael@0: ManifestFile('', [Manifest('', 'chrome/chrome.manifest')]), michael@0: 'dict/bb': dict_bb, michael@0: 'dict/cc': dict_cc, michael@0: 'app/chrome/bar-l10n/barbaz.dtd': barbaz_l10n, michael@0: 'app/chrome/chrome.manifest': ManifestFile('app/chrome', [ michael@0: ManifestLocale('app/chrome', 'bar', 'x-test', 'bar-l10n/') michael@0: ]), michael@0: 'app/chrome.manifest': michael@0: ManifestFile('app', [Manifest('app', 'chrome/chrome.manifest')]), michael@0: 'app/dict/aa': dict_aa, michael@0: 'app/chrome/bar-l10n/search/foo.xml': foo_l10n, michael@0: 'app/chrome/bar-l10n/search/qux.xml': qux_l10n, michael@0: 'app/chrome/bar-l10n/search/lst.txt': lst_l10n, michael@0: } michael@0: michael@0: self.assertEqual( michael@0: dict((p, f.open().read()) for p, f in copier), michael@0: dict((p, f.open().read()) for p, f in repacked.iteritems()) michael@0: ) michael@0: michael@0: michael@0: if __name__ == '__main__': michael@0: mozunit.main()