Bug 910660 - Refactor test_packager_formats.py so that it's easier to follow. r=gps, a=sledru
This commit is contained in:
@@ -3,83 +3,94 @@
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
import mozunit
|
||||
import unittest
|
||||
from mozpack.packager.formats import (
|
||||
FlatFormatter,
|
||||
JarFormatter,
|
||||
OmniJarFormatter,
|
||||
)
|
||||
from mozpack.copier import FileRegistry
|
||||
from mozpack.files import GeneratedFile
|
||||
from mozpack.files import (
|
||||
GeneratedFile,
|
||||
ManifestFile,
|
||||
)
|
||||
from mozpack.chrome.manifest import (
|
||||
ManifestContent,
|
||||
ManifestComponent,
|
||||
ManifestResource,
|
||||
ManifestBinaryComponent,
|
||||
)
|
||||
from mozpack.test.test_files import (
|
||||
TestWithTmpDir,
|
||||
MockDest,
|
||||
foo_xpt,
|
||||
bar_xpt,
|
||||
read_interfaces,
|
||||
)
|
||||
|
||||
|
||||
class TestFlatFormatter(TestWithTmpDir):
|
||||
def test_flat_formatter(self):
|
||||
registry = FileRegistry()
|
||||
formatter = FlatFormatter(registry)
|
||||
formatter.add_base('app')
|
||||
formatter.add('f/oo/bar', GeneratedFile('foobar'))
|
||||
formatter.add('f/oo/baz', GeneratedFile('foobaz'))
|
||||
formatter.add('f/oo/qux', GeneratedFile('fooqux'))
|
||||
formatter.add_manifest(ManifestContent('f/oo', 'bar', 'bar'))
|
||||
formatter.add_manifest(ManifestContent('f/oo', 'qux', 'qux'))
|
||||
self.assertEqual(registry.paths(),
|
||||
['f/oo/bar', 'f/oo/baz', 'f/oo/qux',
|
||||
'chrome.manifest', 'f/f.manifest',
|
||||
'f/oo/oo.manifest'])
|
||||
self.assertEqual(registry['chrome.manifest'].open().read(),
|
||||
'manifest f/f.manifest\n')
|
||||
self.assertEqual(registry['f/f.manifest'].open().read(),
|
||||
'manifest oo/oo.manifest\n')
|
||||
self.assertEqual(registry['f/oo/oo.manifest'].open().read(), ''.join([
|
||||
'content bar bar\n',
|
||||
'content qux qux\n',
|
||||
]))
|
||||
CONTENTS = {
|
||||
'bases': [
|
||||
'app',
|
||||
],
|
||||
'manifests': [
|
||||
ManifestContent('chrome/f', 'oo', 'oo/'),
|
||||
ManifestContent('chrome/f', 'bar', 'oo/bar/'),
|
||||
ManifestResource('chrome/f', 'foo', 'resource://bar/'),
|
||||
ManifestBinaryComponent('components', 'foo.so'),
|
||||
ManifestContent('app/chrome', 'content', 'foo/'),
|
||||
ManifestComponent('app/components', '{foo-id}', 'foo.js'),
|
||||
],
|
||||
'chrome/f/oo/bar/baz': GeneratedFile('foobarbaz'),
|
||||
'chrome/f/oo/baz': GeneratedFile('foobaz'),
|
||||
'chrome/f/oo/qux': GeneratedFile('fooqux'),
|
||||
'components/foo.so': GeneratedFile('foo.so'),
|
||||
'components/foo.xpt': foo_xpt,
|
||||
'components/bar.xpt': bar_xpt,
|
||||
'foo': GeneratedFile('foo'),
|
||||
'app/chrome/foo/foo': GeneratedFile('appfoo'),
|
||||
'app/components/foo.js': GeneratedFile('foo.js'),
|
||||
}
|
||||
|
||||
formatter.add_interfaces('components/foo.xpt', foo_xpt)
|
||||
formatter.add_interfaces('components/bar.xpt', bar_xpt)
|
||||
self.assertEqual(registry.paths(),
|
||||
['f/oo/bar', 'f/oo/baz', 'f/oo/qux',
|
||||
'chrome.manifest', 'f/f.manifest',
|
||||
'f/oo/oo.manifest', 'components/components.manifest',
|
||||
'components/interfaces.xpt'])
|
||||
self.assertEqual(registry['chrome.manifest'].open().read(), ''.join([
|
||||
'manifest f/f.manifest\n',
|
||||
'manifest components/components.manifest\n',
|
||||
]))
|
||||
self.assertEqual(
|
||||
registry['components/components.manifest'].open().read(),
|
||||
'interfaces interfaces.xpt\n'
|
||||
)
|
||||
|
||||
registry['components/interfaces.xpt'] \
|
||||
.copy(self.tmppath('interfaces.xpt'))
|
||||
linked = read_interfaces(self.tmppath('interfaces.xpt'))
|
||||
foo = read_interfaces(foo_xpt.open())
|
||||
bar = read_interfaces(bar_xpt.open())
|
||||
self.assertEqual(foo['foo'], linked['foo'])
|
||||
self.assertEqual(bar['bar'], linked['bar'])
|
||||
class MockDest(MockDest):
|
||||
def exists(self):
|
||||
return False
|
||||
|
||||
formatter.add_manifest(ManifestContent('app/chrome', 'content',
|
||||
'foo/'))
|
||||
self.assertEqual(registry['chrome.manifest'].open().read(), ''.join([
|
||||
'manifest f/f.manifest\n',
|
||||
'manifest components/components.manifest\n',
|
||||
]))
|
||||
self.assertEqual(registry['app/chrome.manifest'].open().read(),
|
||||
'manifest chrome/chrome.manifest\n')
|
||||
self.assertEqual(registry['app/chrome/chrome.manifest'].open().read(),
|
||||
'content content foo/\n')
|
||||
|
||||
def fill_formatter(formatter, contents):
|
||||
for base in contents['bases']:
|
||||
formatter.add_base(base)
|
||||
|
||||
for manifest in contents['manifests']:
|
||||
formatter.add_manifest(manifest)
|
||||
|
||||
for k, v in contents.iteritems():
|
||||
if k in ('bases', 'manifests'):
|
||||
continue
|
||||
if k.endswith('.xpt'):
|
||||
formatter.add_interfaces(k, v)
|
||||
else:
|
||||
formatter.add(k, v)
|
||||
|
||||
|
||||
def get_contents(registry):
|
||||
result = {}
|
||||
for k, v in registry:
|
||||
if k.endswith('.xpt'):
|
||||
tmpfile = MockDest()
|
||||
registry[k].copy(tmpfile)
|
||||
result[k] = read_interfaces(tmpfile)
|
||||
elif isinstance(v, FileRegistry):
|
||||
result[k] = get_contents(v)
|
||||
elif isinstance(v, ManifestFile):
|
||||
result[k] = v.open().read().splitlines()
|
||||
else:
|
||||
result[k] = v
|
||||
return result
|
||||
|
||||
|
||||
class TestFormatters(unittest.TestCase):
|
||||
maxDiff = None
|
||||
|
||||
def test_bases(self):
|
||||
formatter = FlatFormatter(FileRegistry())
|
||||
@@ -92,146 +103,161 @@ class TestFlatFormatter(TestWithTmpDir):
|
||||
self.assertEqual(formatter._get_base('webapprt/webapprt.ini'),
|
||||
'webapprt')
|
||||
|
||||
def test_flat_formatter(self):
|
||||
registry = FileRegistry()
|
||||
formatter = FlatFormatter(registry)
|
||||
|
||||
fill_formatter(formatter, CONTENTS)
|
||||
|
||||
RESULT = {
|
||||
'chrome.manifest': [
|
||||
'manifest chrome/chrome.manifest',
|
||||
'manifest components/components.manifest',
|
||||
],
|
||||
'chrome/chrome.manifest': [
|
||||
'manifest f/f.manifest',
|
||||
],
|
||||
'chrome/f/f.manifest': [
|
||||
'content oo oo/',
|
||||
'content bar oo/bar/',
|
||||
'resource foo resource://bar/',
|
||||
],
|
||||
'chrome/f/oo/bar/baz': CONTENTS['chrome/f/oo/bar/baz'],
|
||||
'chrome/f/oo/baz': CONTENTS['chrome/f/oo/baz'],
|
||||
'chrome/f/oo/qux': CONTENTS['chrome/f/oo/qux'],
|
||||
'components/components.manifest': [
|
||||
'binary-component foo.so',
|
||||
'interfaces interfaces.xpt',
|
||||
],
|
||||
'components/foo.so': CONTENTS['components/foo.so'],
|
||||
'components/interfaces.xpt': {
|
||||
'foo': read_interfaces(foo_xpt.open())['foo'],
|
||||
'bar': read_interfaces(bar_xpt.open())['bar'],
|
||||
},
|
||||
'foo': CONTENTS['foo'],
|
||||
'app/chrome.manifest': [
|
||||
'manifest chrome/chrome.manifest',
|
||||
'manifest components/components.manifest',
|
||||
],
|
||||
'app/chrome/chrome.manifest': [
|
||||
'content content foo/',
|
||||
],
|
||||
'app/chrome/foo/foo': CONTENTS['app/chrome/foo/foo'],
|
||||
'app/components/components.manifest': [
|
||||
'component {foo-id} foo.js',
|
||||
],
|
||||
'app/components/foo.js': CONTENTS['app/components/foo.js'],
|
||||
}
|
||||
|
||||
self.assertEqual(get_contents(registry), RESULT)
|
||||
|
||||
class TestJarFormatter(TestWithTmpDir):
|
||||
def test_jar_formatter(self):
|
||||
registry = FileRegistry()
|
||||
formatter = JarFormatter(registry)
|
||||
formatter.add_manifest(ManifestContent('f', 'oo', 'oo/'))
|
||||
formatter.add_manifest(ManifestContent('f', 'bar', 'oo/bar/'))
|
||||
formatter.add('f/oo/bar/baz', GeneratedFile('foobarbaz'))
|
||||
formatter.add('f/oo/qux', GeneratedFile('fooqux'))
|
||||
|
||||
self.assertEqual(registry.paths(),
|
||||
['chrome.manifest', 'f/f.manifest', 'f/oo.jar'])
|
||||
self.assertEqual(registry['chrome.manifest'].open().read(),
|
||||
'manifest f/f.manifest\n')
|
||||
self.assertEqual(registry['f/f.manifest'].open().read(), ''.join([
|
||||
'content oo jar:oo.jar!/\n',
|
||||
'content bar jar:oo.jar!/bar/\n',
|
||||
]))
|
||||
self.assertTrue(formatter.contains('f/oo/bar/baz'))
|
||||
self.assertFalse(formatter.contains('foo/bar/baz'))
|
||||
self.assertEqual(registry['f/oo.jar'].paths(), ['bar/baz', 'qux'])
|
||||
fill_formatter(formatter, CONTENTS)
|
||||
|
||||
formatter.add_manifest(ManifestResource('f', 'foo', 'resource://bar/'))
|
||||
self.assertEqual(registry['f/f.manifest'].open().read(), ''.join([
|
||||
'content oo jar:oo.jar!/\n',
|
||||
'content bar jar:oo.jar!/bar/\n',
|
||||
'resource foo resource://bar/\n',
|
||||
]))
|
||||
RESULT = {
|
||||
'chrome.manifest': [
|
||||
'manifest chrome/chrome.manifest',
|
||||
'manifest components/components.manifest',
|
||||
],
|
||||
'chrome/chrome.manifest': [
|
||||
'manifest f/f.manifest',
|
||||
],
|
||||
'chrome/f/f.manifest': [
|
||||
'content oo jar:oo.jar!/',
|
||||
'content bar jar:oo.jar!/bar/',
|
||||
'resource foo resource://bar/',
|
||||
],
|
||||
'chrome/f/oo.jar': {
|
||||
'bar/baz': CONTENTS['chrome/f/oo/bar/baz'],
|
||||
'baz': CONTENTS['chrome/f/oo/baz'],
|
||||
'qux': CONTENTS['chrome/f/oo/qux'],
|
||||
},
|
||||
'components/components.manifest': [
|
||||
'binary-component foo.so',
|
||||
'interfaces interfaces.xpt',
|
||||
],
|
||||
'components/foo.so': CONTENTS['components/foo.so'],
|
||||
'components/interfaces.xpt': {
|
||||
'foo': read_interfaces(foo_xpt.open())['foo'],
|
||||
'bar': read_interfaces(bar_xpt.open())['bar'],
|
||||
},
|
||||
'foo': CONTENTS['foo'],
|
||||
'app/chrome.manifest': [
|
||||
'manifest chrome/chrome.manifest',
|
||||
'manifest components/components.manifest',
|
||||
],
|
||||
'app/chrome/chrome.manifest': [
|
||||
'content content jar:foo.jar!/',
|
||||
],
|
||||
'app/chrome/foo.jar': {
|
||||
'foo': CONTENTS['app/chrome/foo/foo'],
|
||||
},
|
||||
'app/components/components.manifest': [
|
||||
'component {foo-id} foo.js',
|
||||
],
|
||||
'app/components/foo.js': CONTENTS['app/components/foo.js'],
|
||||
}
|
||||
|
||||
self.assertEqual(get_contents(registry), RESULT)
|
||||
|
||||
class TestOmniJarFormatter(TestWithTmpDir):
|
||||
def test_omnijar_formatter(self):
|
||||
registry = FileRegistry()
|
||||
formatter = OmniJarFormatter(registry, 'omni.foo')
|
||||
formatter.add_base('app')
|
||||
formatter.add('chrome/f/oo/bar', GeneratedFile('foobar'))
|
||||
formatter.add('chrome/f/oo/baz', GeneratedFile('foobaz'))
|
||||
formatter.add('chrome/f/oo/qux', GeneratedFile('fooqux'))
|
||||
formatter.add_manifest(ManifestContent('chrome/f/oo', 'bar', 'bar'))
|
||||
formatter.add_manifest(ManifestContent('chrome/f/oo', 'qux', 'qux'))
|
||||
self.assertEqual(registry.paths(), ['omni.foo'])
|
||||
self.assertEqual(registry['omni.foo'].paths(), [
|
||||
'chrome/f/oo/bar',
|
||||
'chrome/f/oo/baz',
|
||||
'chrome/f/oo/qux',
|
||||
'chrome.manifest',
|
||||
'chrome/chrome.manifest',
|
||||
'chrome/f/f.manifest',
|
||||
'chrome/f/oo/oo.manifest',
|
||||
])
|
||||
self.assertEqual(registry['omni.foo']['chrome.manifest']
|
||||
.open().read(), 'manifest chrome/chrome.manifest\n')
|
||||
self.assertEqual(registry['omni.foo']['chrome/chrome.manifest']
|
||||
.open().read(), 'manifest f/f.manifest\n')
|
||||
self.assertEqual(registry['omni.foo']['chrome/f/f.manifest']
|
||||
.open().read(), 'manifest oo/oo.manifest\n')
|
||||
self.assertEqual(registry['omni.foo']['chrome/f/oo/oo.manifest']
|
||||
.open().read(), ''.join([
|
||||
'content bar bar\n',
|
||||
'content qux qux\n',
|
||||
]))
|
||||
self.assertTrue(formatter.contains('chrome/f/oo/bar'))
|
||||
self.assertFalse(formatter.contains('chrome/foo/bar'))
|
||||
|
||||
formatter.add_interfaces('components/foo.xpt', foo_xpt)
|
||||
formatter.add_interfaces('components/bar.xpt', bar_xpt)
|
||||
self.assertEqual(registry['omni.foo'].paths(), [
|
||||
'chrome/f/oo/bar',
|
||||
'chrome/f/oo/baz',
|
||||
'chrome/f/oo/qux',
|
||||
'chrome.manifest',
|
||||
'chrome/chrome.manifest',
|
||||
'chrome/f/f.manifest',
|
||||
'chrome/f/oo/oo.manifest',
|
||||
'components/components.manifest',
|
||||
'components/interfaces.xpt',
|
||||
])
|
||||
self.assertEqual(registry['omni.foo']['chrome.manifest']
|
||||
.open().read(), ''.join([
|
||||
'manifest chrome/chrome.manifest\n',
|
||||
'manifest components/components.manifest\n'
|
||||
]))
|
||||
self.assertEqual(registry['omni.foo']
|
||||
['components/components.manifest'].open().read(),
|
||||
'interfaces interfaces.xpt\n')
|
||||
fill_formatter(formatter, CONTENTS)
|
||||
|
||||
registry['omni.foo'][
|
||||
'components/interfaces.xpt'].copy(self.tmppath('interfaces.xpt'))
|
||||
linked = read_interfaces(self.tmppath('interfaces.xpt'))
|
||||
foo = read_interfaces(foo_xpt.open())
|
||||
bar = read_interfaces(bar_xpt.open())
|
||||
self.assertEqual(foo['foo'], linked['foo'])
|
||||
self.assertEqual(bar['bar'], linked['bar'])
|
||||
|
||||
formatter.add('app/chrome/foo/baz', GeneratedFile('foobaz'))
|
||||
formatter.add_manifest(ManifestContent('app/chrome', 'content',
|
||||
'foo/'))
|
||||
self.assertEqual(registry.paths(), ['omni.foo', 'app/omni.foo'])
|
||||
self.assertEqual(registry['app/omni.foo'].paths(), [
|
||||
'chrome/foo/baz',
|
||||
'chrome.manifest',
|
||||
'chrome/chrome.manifest',
|
||||
])
|
||||
self.assertEqual(registry['app/omni.foo']['chrome.manifest']
|
||||
.open().read(), 'manifest chrome/chrome.manifest\n')
|
||||
self.assertEqual(registry['app/omni.foo']['chrome/chrome.manifest']
|
||||
.open().read(), 'content content foo/\n')
|
||||
|
||||
formatter.add_manifest(ManifestBinaryComponent('components', 'foo.so'))
|
||||
formatter.add('components/foo.so', GeneratedFile('foo'))
|
||||
self.assertEqual(registry.paths(), [
|
||||
'omni.foo', 'app/omni.foo', 'chrome.manifest',
|
||||
'components/components.manifest', 'components/foo.so',
|
||||
])
|
||||
self.assertEqual(registry['chrome.manifest'].open().read(),
|
||||
'manifest components/components.manifest\n')
|
||||
self.assertEqual(registry['components/components.manifest']
|
||||
.open().read(), 'binary-component foo.so\n')
|
||||
|
||||
formatter.add_manifest(ManifestBinaryComponent('app/components',
|
||||
'foo.so'))
|
||||
formatter.add('app/components/foo.so', GeneratedFile('foo'))
|
||||
self.assertEqual(registry.paths(), [
|
||||
'omni.foo', 'app/omni.foo', 'chrome.manifest',
|
||||
'components/components.manifest', 'components/foo.so',
|
||||
'app/chrome.manifest', 'app/components/components.manifest',
|
||||
'app/components/foo.so',
|
||||
])
|
||||
self.assertEqual(registry['app/chrome.manifest'].open().read(),
|
||||
'manifest components/components.manifest\n')
|
||||
self.assertEqual(registry['app/components/components.manifest']
|
||||
.open().read(), 'binary-component foo.so\n')
|
||||
|
||||
formatter.add('app/foo', GeneratedFile('foo'))
|
||||
self.assertEqual(registry.paths(), [
|
||||
'omni.foo', 'app/omni.foo', 'chrome.manifest',
|
||||
'components/components.manifest', 'components/foo.so',
|
||||
'app/chrome.manifest', 'app/components/components.manifest',
|
||||
'app/components/foo.so', 'app/foo'
|
||||
])
|
||||
RESULT = {
|
||||
'omni.foo': {
|
||||
'chrome.manifest': [
|
||||
'manifest chrome/chrome.manifest',
|
||||
'manifest components/components.manifest',
|
||||
],
|
||||
'chrome/chrome.manifest': [
|
||||
'manifest f/f.manifest',
|
||||
],
|
||||
'chrome/f/f.manifest': [
|
||||
'content oo oo/',
|
||||
'content bar oo/bar/',
|
||||
'resource foo resource://bar/',
|
||||
],
|
||||
'chrome/f/oo/bar/baz': CONTENTS['chrome/f/oo/bar/baz'],
|
||||
'chrome/f/oo/baz': CONTENTS['chrome/f/oo/baz'],
|
||||
'chrome/f/oo/qux': CONTENTS['chrome/f/oo/qux'],
|
||||
'components/components.manifest': [
|
||||
'interfaces interfaces.xpt',
|
||||
],
|
||||
'components/interfaces.xpt': {
|
||||
'foo': read_interfaces(foo_xpt.open())['foo'],
|
||||
'bar': read_interfaces(bar_xpt.open())['bar'],
|
||||
},
|
||||
},
|
||||
'chrome.manifest': [
|
||||
'manifest components/components.manifest',
|
||||
],
|
||||
'components/components.manifest': [
|
||||
'binary-component foo.so',
|
||||
],
|
||||
'components/foo.so': CONTENTS['components/foo.so'],
|
||||
'foo': CONTENTS['foo'],
|
||||
'app/omni.foo': {
|
||||
'chrome.manifest': [
|
||||
'manifest chrome/chrome.manifest',
|
||||
'manifest components/components.manifest',
|
||||
],
|
||||
'chrome/chrome.manifest': [
|
||||
'content content foo/',
|
||||
],
|
||||
'chrome/foo/foo': CONTENTS['app/chrome/foo/foo'],
|
||||
'components/components.manifest': [
|
||||
'component {foo-id} foo.js',
|
||||
],
|
||||
'components/foo.js': CONTENTS['app/components/foo.js'],
|
||||
},
|
||||
}
|
||||
self.assertEqual(get_contents(registry), RESULT)
|
||||
|
||||
def test_omnijar_is_resource(self):
|
||||
registry = FileRegistry()
|
||||
|
||||
Reference in New Issue
Block a user