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

Delta Between Two Patch Sets: tests/test_packagerEdge.py

Issue 29501558: Issue 5383 - Add tests for the Chrome and Firefox packagers (Closed)
Left Patch Set: Created Aug. 4, 2017, 3:06 p.m.
Right Patch Set: Addressing Vasily's comments Created Oct. 22, 2017, 11:11 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « tests/metadata.gecko ('k') | tests/test_packagerWebExt.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # This Source Code Form is subject to the terms of the Mozilla Public 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 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/. 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 4
5 import os
6 import io
7
8 import xml.etree.ElementTree as ET 5 import xml.etree.ElementTree as ET
9 import zipfile
10 6
11 import pytest 7 import pytest
12 8
13 from buildtools import packager, packagerEdge 9 from buildtools import packager, packagerEdge
14 from buildtools.tests.tools import copy_metadata
15 10
16 11
17 @pytest.fixture 12 @pytest.fixture
18 def edge_metadata(tmpdir): 13 def files():
19 filename = 'metadata.edge' 14 """Minimal Files() for testing blockmap."""
20 copy_metadata(filename, tmpdir) 15 str500 = b''.join(chr(i % 200 + 30) for i in range(500))
21 16 files = packager.Files(set(), set())
22 return packager.readMetadata(str(tmpdir), 'edge') 17 files['Extension/foo.xml'] = str500
18 files['Extension/bar.png'] = str500 * 200
19 return files
23 20
24 21
25 def blockmap2dict(xml_data): 22 def blockmap2dict(xml_data):
26 """Convert AppxBlockMap.xml to a dict of dicts easier to inspect.""" 23 """Convert AppxBlockMap.xml to a dict of dicts easier to inspect."""
27 return { 24 return {
28 file.get('Name'): { 25 file.get('Name'): {
29 'size': file.get('Size'), 26 'size': file.get('Size'),
30 'lfhsize': file.get('LfhSize'), 27 'lfhsize': file.get('LfhSize'),
31 'blocks': [b.get('Hash') for b in file] 28 'blocks': [b.get('Hash') for b in file]
32 } 29 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 'js': 'application/javascript', 78 'js': 'application/javascript',
82 'json': 'application/json', 79 'json': 'application/json',
83 'otf': 'application/octet-stream', 80 'otf': 'application/octet-stream',
84 'png': 'image/png', 81 'png': 'image/png',
85 'xml': 'application/xml' 82 'xml': 'application/xml'
86 } 83 }
87 assert ctm_dict['overrides'] == { 84 assert ctm_dict['overrides'] == {
88 '/AppxBlockMap.xml': 'application/vnd.ms-appx.blockmap+xml', 85 '/AppxBlockMap.xml': 'application/vnd.ms-appx.blockmap+xml',
89 '/AppxManifest.xml': 'application/vnd.ms-appx.manifest+xml' 86 '/AppxManifest.xml': 'application/vnd.ms-appx.manifest+xml'
90 } 87 }
91
92
93 @pytest.mark.parametrize('release_build', [True, False])
94 def test_create_appx_manifest(files, srcdir, release_build, edge_metadata):
95 manifest = ET.fromstring(packagerEdge.create_appx_manifest(
96 {'metadata': edge_metadata},
97 files,
98 release_build=release_build))
99
100 xmlpath = os.path.join(
101 os.path.dirname(__file__),
102 'expecteddata',
103 'manifest_edge_{}.xml'.format(release_build)
104 )
105
106 with io.open(xmlpath, 'r') as fp:
107 expected = ET.fromstring(fp.read())
108
109 from buildtools.tests.tools import get_leafs_string
110 assert set(get_leafs_string(expected)) == set(get_leafs_string(manifest))
111
112
113 def test_move_files_to_extension(str500chars):
114 files = packager.Files(set(), set())
115 files['foo.xml'] = str500chars
116 files['foo/bar.xml'] = str500chars
117 files['Extension/foo.xml'] = str500chars
118 packagerEdge.move_files_to_extension(files)
119 assert set(files.keys()) == {
120 'Extension/foo.xml',
121 'Extension/foo/bar.xml',
122 'Extension/Extension/foo.xml'
123 }
124
125
126 @pytest.mark.usefixtures('edge_metadata')
127 def test_create_build(tmpdir, srcdir):
128 out_file = str(tmpdir.join('abp.appx'))
129 packagerEdge.createBuild(str(srcdir), outFile=out_file, releaseBuild=True)
130 appx = zipfile.ZipFile(out_file)
131
132 names = set(appx.namelist())
133 assert 'AppxManifest.xml' in names
134 assert 'AppxBlockMap.xml' in names
135 assert '[Content_Types].xml' in names
136
137 assert 'devbuild-marker' not in appx.read('AppxManifest.xml')
138 assert appx.read('Assets/logo_44.png') == '44'
139 assert appx.read('Extension/icons/abp-44.png') == '44'
140
141
142 @pytest.mark.usefixtures('edge_metadata')
143 def test_create_devbuild(tmpdir, srcdir):
144 out_file = str(tmpdir.join('abp.appx'))
145 packagerEdge.createBuild(str(srcdir), outFile=out_file, releaseBuild=False)
146 appx = zipfile.ZipFile(out_file)
147 assert 'devbuild-marker' in appx.read('AppxManifest.xml')
LEFTRIGHT

Powered by Google App Engine
This is Rietveld