Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: tests/test_packagerEdge.py

Issue 29501558: Issue 5383 - Add tests for the Chrome and Firefox packagers (Closed)
Patch Set: Created July 31, 2017, 12:07 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tests/test_packagerEdge.py
diff --git a/tests/test_packagerEdge.py b/tests/test_packagerEdge.py
index 3eedfad5a68a4ae0891d5d126e58f0002971aa57..88a3d50a28c976b7637c0e1c61e0e7ddca3c2d31 100644
--- a/tests/test_packagerEdge.py
+++ b/tests/test_packagerEdge.py
@@ -2,10 +2,6 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-import ConfigParser
-import json
-import os
-import shutil
import xml.etree.ElementTree as ET
import zipfile
@@ -13,53 +9,6 @@ import pytest
from buildtools import packager, packagerEdge
-TEST_DIR = os.path.dirname(__file__)
-TEST_METADATA = os.path.join(TEST_DIR, 'metadata.edge')
-CHARS = b''.join(chr(i % 200 + 30) for i in range(500))
-MESSAGES_EN_US = json.dumps({
- 'name': {'message': 'Adblock Plus'},
- 'name_devbuild': {'message': 'devbuild-marker'},
- 'description': {
- 'message': 'Adblock Plus is the most popular ad blocker ever, '
- 'and also supports websites by not blocking '
- 'unobstrusive ads by default (configurable).'
- },
-})
-
-
-@pytest.fixture
-def metadata():
- """Loaded metadata config."""
- conf_parser = ConfigParser.ConfigParser()
- conf_parser.read(TEST_METADATA)
- return conf_parser
-
-
-@pytest.fixture
-def files():
- """Minimal Files() for testing manifest and blockmap."""
- files = packager.Files(set(), set())
- for size in ['44', '50', '150']:
- files['Assets/logo_{}.png'.format(size)] = CHARS
- files['Extension/_locales/en_US/messages.json'] = MESSAGES_EN_US
- files['Extension/foo.xml'] = CHARS
- files['Extension/bar.png'] = CHARS * 200
- return files
-
-
-@pytest.fixture
-def srcdir(tmpdir):
- """Source directory for building the package."""
- srcdir = tmpdir.mkdir('src')
- shutil.copy(TEST_METADATA, str(srcdir.join('metadata.edge')))
- for size in ['44', '50', '150']:
- path = srcdir.join('chrome', 'icons', 'abp-{}.png'.format(size))
- path.write(size, ensure=True)
- localedir = srcdir.mkdir('_locales')
- en_us_dir = localedir.mkdir('en_US')
- en_us_dir.join('messages.json').write(MESSAGES_EN_US)
- return srcdir
-
def blockmap2dict(xml_data):
"""Convert AppxBlockMap.xml to a dict of dicts easier to inspect."""
@@ -129,7 +78,9 @@ def test_full_content_types_map():
}
-def test_create_appx_manifest(metadata, files):
+@pytest.mark.parametrize('metadata_files', ['metadata.edge'], indirect=True)
+@pytest.mark.usefixtures('metadata_files')
+def test_create_appx_manifest(files, srcdir):
namespaces = {
'ns': 'http://schemas.microsoft.com/'
'appx/manifest/foundation/windows10',
@@ -211,6 +162,8 @@ def test_create_appx_manifest(metadata, files):
'Adblock Plus'),
]
+ metadata = packager.readMetadata(str(srcdir), 'edge')
+
for release_build, pairs in [(False, devbuild), (True, release)]:
manifest = ET.fromstring(packagerEdge.create_appx_manifest(
{'metadata': metadata},
@@ -224,11 +177,11 @@ def test_create_appx_manifest(metadata, files):
assert res == value
-def test_move_files_to_extension():
+def test_move_files_to_extension(chars):
files = packager.Files(set(), set())
- files['foo.xml'] = CHARS
- files['foo/bar.xml'] = CHARS
- files['Extension/foo.xml'] = CHARS
+ files['foo.xml'] = chars
+ files['foo/bar.xml'] = chars
+ files['Extension/foo.xml'] = chars
packagerEdge.move_files_to_extension(files)
assert set(files.keys()) == {
'Extension/foo.xml',
@@ -237,6 +190,8 @@ def test_move_files_to_extension():
}
+@pytest.mark.parametrize('metadata_files', ['metadata.edge'], indirect=True)
+@pytest.mark.usefixtures('metadata_files')
def test_create_build(tmpdir, srcdir):
out_file = str(tmpdir.join('abp.appx'))
packagerEdge.createBuild(str(srcdir), outFile=out_file, releaseBuild=True)
@@ -252,6 +207,8 @@ def test_create_build(tmpdir, srcdir):
assert appx.read('Extension/icons/abp-44.png') == '44'
+@pytest.mark.parametrize('metadata_files', ['metadata.edge'], indirect=True)
+@pytest.mark.usefixtures('metadata_files')
def test_create_devbuild(tmpdir, srcdir):
out_file = str(tmpdir.join('abp.appx'))
packagerEdge.createBuild(str(srcdir), outFile=out_file, releaseBuild=False)

Powered by Google App Engine
This is Rietveld