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: Addressing pep8 error from last review Created Aug. 11, 2017, 12:12 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 }
33 for file in ET.fromstring(xml_data) 30 for file in ET.fromstring(xml_data)
34 } 31 }
35 32
36 33
37 def test_create_appx_blockmap(base_files): 34 def test_create_appx_blockmap(files):
38 blockmap = blockmap2dict(packagerEdge.create_appx_blockmap(base_files)) 35 blockmap = blockmap2dict(packagerEdge.create_appx_blockmap(files))
39 assert blockmap['Extension\\foo.xml'] == { 36 assert blockmap['Extension\\foo.xml'] == {
40 'size': '500', 37 'size': '500',
41 'lfhsize': '47', 38 'lfhsize': '47',
42 'blocks': ['Vhwfmzss1Ney+j/ssR2QVISvFyMNBQeS2P+UjeE/di0='] 39 'blocks': ['Vhwfmzss1Ney+j/ssR2QVISvFyMNBQeS2P+UjeE/di0=']
43 } 40 }
44 assert blockmap['Extension\\bar.png'] == { 41 assert blockmap['Extension\\bar.png'] == {
45 'size': '100000', 42 'size': '100000',
46 'lfhsize': '47', 43 'lfhsize': '47',
47 'blocks': [ 44 'blocks': [
48 'KPW2SxeEikUEGhoKmKxruUSexKun0bGXMppOqUFrX5E=', 45 'KPW2SxeEikUEGhoKmKxruUSexKun0bGXMppOqUFrX5E=',
(...skipping 32 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(base_files, srcdir, release_build,
95 edge_metadata):
96 manifest = ET.fromstring(packagerEdge.create_appx_manifest(
97 {'metadata': edge_metadata},
98 base_files,
99 release_build=release_build))
100
101 xmlpath = os.path.join(
102 os.path.dirname(__file__),
103 'expecteddata',
104 'manifest_edge_{}.xml'.format(release_build)
105 )
106
107 with io.open(xmlpath, 'r') as fp:
108 expected = ET.fromstring(fp.read())
109
110 from buildtools.tests.tools import get_leafs_string
111 assert set(get_leafs_string(expected)) == set(get_leafs_string(manifest))
112
113
114 def test_move_files_to_extension(str500chars):
115 files = packager.Files(set(), set())
116 files['foo.xml'] = str500chars
117 files['foo/bar.xml'] = str500chars
118 files['Extension/foo.xml'] = str500chars
119 packagerEdge.move_files_to_extension(files)
120 assert set(files.keys()) == {
121 'Extension/foo.xml',
122 'Extension/foo/bar.xml',
123 'Extension/Extension/foo.xml'
124 }
125
126
127 @pytest.mark.usefixtures('edge_metadata')
128 def test_create_build(tmpdir, srcdir):
129 out_file = str(tmpdir.join('abp.appx'))
130 packagerEdge.createBuild(str(srcdir), outFile=out_file, releaseBuild=True)
131 appx = zipfile.ZipFile(out_file)
132
133 names = set(appx.namelist())
134 assert 'AppxManifest.xml' in names
135 assert 'AppxBlockMap.xml' in names
136 assert '[Content_Types].xml' in names
137
138 assert 'devbuild-marker' not in appx.read('AppxManifest.xml')
139 assert appx.read('Assets/logo_44.png') == '44'
140 assert appx.read('Extension/icons/abp-44.png') == '44'
141
142
143 @pytest.mark.usefixtures('edge_metadata')
144 def test_create_devbuild(tmpdir, srcdir):
145 out_file = str(tmpdir.join('abp.appx'))
146 packagerEdge.createBuild(str(srcdir), outFile=out_file, releaseBuild=False)
147 appx = zipfile.ZipFile(out_file)
148 assert 'devbuild-marker' in appx.read('AppxManifest.xml')
LEFTRIGHT

Powered by Google App Engine
This is Rietveld