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

Side by Side Diff: tests/test_packagerEdge.py

Issue 29825555: Issue 6291 - add ManifoldJS packaging for Edge (Closed) Base URL: https://hg.adblockplus.org/buildtools/file/9a56d76cd951
Patch Set: Final patch set Created Aug. 9, 2018, 7:08 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/metadata.edge ('k') | tests/test_packagerWebExt.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5 import xml.etree.ElementTree as ET
6
7 import pytest
8
9 from buildtools import packager, packagerEdge
10
11
12 @pytest.fixture
13 def files():
14 """Minimal Files() for testing blockmap."""
15 str500 = b''.join(chr(i % 200 + 30) for i in range(500))
16 files = packager.Files(set(), set())
17 files['Extension/foo.xml'] = str500
18 files['Extension/bar.png'] = str500 * 200
19 return files
20
21
22 def blockmap2dict(xml_data):
23 """Convert AppxBlockMap.xml to a dict of dicts easier to inspect."""
24 return {
25 file.get('Name'): {
26 'size': file.get('Size'),
27 'lfhsize': file.get('LfhSize'),
28 'blocks': [b.get('Hash') for b in file],
29 }
30 for file in ET.fromstring(xml_data)
31 }
32
33
34 def test_create_appx_blockmap(files):
35 blockmap = blockmap2dict(packagerEdge.create_appx_blockmap(files))
36 assert blockmap['Extension\\foo.xml'] == {
37 'size': '500',
38 'lfhsize': '47',
39 'blocks': ['Vhwfmzss1Ney+j/ssR2QVISvFyMNBQeS2P+UjeE/di0='],
40 }
41 assert blockmap['Extension\\bar.png'] == {
42 'size': '100000',
43 'lfhsize': '47',
44 'blocks': [
45 'KPW2SxeEikUEGhoKmKxruUSexKun0bGXMppOqUFrX5E=',
46 'KQHnov1SZ1z34ttdDUjX2leYtpIIGndUVoUteieS2cw=',
47 ],
48 }
49
50
51 def ctm2dict(content_types_map):
52 """Convert content type map to a dict."""
53 ret = {'defaults': {}, 'overrides': {}}
54 for node in ET.fromstring(content_types_map):
55 ct = node.get('ContentType')
56 if node.tag.endswith('Default'):
57 ret['defaults'][node.get('Extension')] = ct
58 elif node.tag.endswith('Override'):
59 ret['overrides'][node.get('PartName')] = ct
60 else:
61 raise ValueError('Unrecognised tag in content map: ' + node.tag)
62 return ret
63
64
65 def test_empty_content_types_map():
66 ctm_dict = ctm2dict(packagerEdge.create_content_types_map([]))
67 assert ctm_dict['defaults'] == {}
68 assert ctm_dict['overrides'] == {}
69
70
71 def test_full_content_types_map():
72 filenames = ['no-extension', packagerEdge.MANIFEST, packagerEdge.BLOCKMAP]
73 filenames += ['file.' + x for x in 'json html js png css git otf'.split()]
74 ctm_dict = ctm2dict(packagerEdge.create_content_types_map(filenames))
75 assert ctm_dict['defaults'] == {
76 'css': 'text/css',
77 'html': 'text/html',
78 'js': 'application/javascript',
79 'json': 'application/json',
80 'otf': 'application/octet-stream',
81 'png': 'image/png',
82 'xml': 'application/xml',
83 }
84 assert ctm_dict['overrides'] == {
85 '/AppxBlockMap.xml': 'application/vnd.ms-appx.blockmap+xml',
86 '/AppxManifest.xml': 'application/vnd.ms-appx.manifest+xml',
87 }
OLDNEW
« no previous file with comments | « tests/metadata.edge ('k') | tests/test_packagerWebExt.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld