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

Side by Side Diff: tests/test_packagerEdge.py

Issue 29756673: Noissue - Adapt best practices for trailing commas (buildtools) (Closed)
Patch Set: Created April 19, 2018, 12:58 p.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 | « releaseAutomation.py ('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
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 xml.etree.ElementTree as ET 5 import xml.etree.ElementTree as ET
6 6
7 import pytest 7 import pytest
8 8
9 from buildtools import packager, packagerEdge 9 from buildtools import packager, packagerEdge
10 10
11 11
12 @pytest.fixture 12 @pytest.fixture
13 def files(): 13 def files():
14 """Minimal Files() for testing blockmap.""" 14 """Minimal Files() for testing blockmap."""
15 str500 = b''.join(chr(i % 200 + 30) for i in range(500)) 15 str500 = b''.join(chr(i % 200 + 30) for i in range(500))
16 files = packager.Files(set(), set()) 16 files = packager.Files(set(), set())
17 files['Extension/foo.xml'] = str500 17 files['Extension/foo.xml'] = str500
18 files['Extension/bar.png'] = str500 * 200 18 files['Extension/bar.png'] = str500 * 200
19 return files 19 return files
20 20
21 21
22 def blockmap2dict(xml_data): 22 def blockmap2dict(xml_data):
23 """Convert AppxBlockMap.xml to a dict of dicts easier to inspect.""" 23 """Convert AppxBlockMap.xml to a dict of dicts easier to inspect."""
24 return { 24 return {
25 file.get('Name'): { 25 file.get('Name'): {
26 'size': file.get('Size'), 26 'size': file.get('Size'),
27 'lfhsize': file.get('LfhSize'), 27 'lfhsize': file.get('LfhSize'),
28 'blocks': [b.get('Hash') for b in file] 28 'blocks': [b.get('Hash') for b in file],
29 } 29 }
30 for file in ET.fromstring(xml_data) 30 for file in ET.fromstring(xml_data)
31 } 31 }
32 32
33 33
34 def test_create_appx_blockmap(files): 34 def test_create_appx_blockmap(files):
35 blockmap = blockmap2dict(packagerEdge.create_appx_blockmap(files)) 35 blockmap = blockmap2dict(packagerEdge.create_appx_blockmap(files))
36 assert blockmap['Extension\\foo.xml'] == { 36 assert blockmap['Extension\\foo.xml'] == {
37 'size': '500', 37 'size': '500',
38 'lfhsize': '47', 38 'lfhsize': '47',
39 'blocks': ['Vhwfmzss1Ney+j/ssR2QVISvFyMNBQeS2P+UjeE/di0='] 39 'blocks': ['Vhwfmzss1Ney+j/ssR2QVISvFyMNBQeS2P+UjeE/di0='],
40 } 40 }
41 assert blockmap['Extension\\bar.png'] == { 41 assert blockmap['Extension\\bar.png'] == {
42 'size': '100000', 42 'size': '100000',
43 'lfhsize': '47', 43 'lfhsize': '47',
44 'blocks': [ 44 'blocks': [
45 'KPW2SxeEikUEGhoKmKxruUSexKun0bGXMppOqUFrX5E=', 45 'KPW2SxeEikUEGhoKmKxruUSexKun0bGXMppOqUFrX5E=',
46 'KQHnov1SZ1z34ttdDUjX2leYtpIIGndUVoUteieS2cw=', 46 'KQHnov1SZ1z34ttdDUjX2leYtpIIGndUVoUteieS2cw=',
47 ] 47 ],
48 } 48 }
49 49
50 50
51 def ctm2dict(content_types_map): 51 def ctm2dict(content_types_map):
52 """Convert content type map to a dict.""" 52 """Convert content type map to a dict."""
53 ret = {'defaults': {}, 'overrides': {}} 53 ret = {'defaults': {}, 'overrides': {}}
54 for node in ET.fromstring(content_types_map): 54 for node in ET.fromstring(content_types_map):
55 ct = node.get('ContentType') 55 ct = node.get('ContentType')
56 if node.tag.endswith('Default'): 56 if node.tag.endswith('Default'):
57 ret['defaults'][node.get('Extension')] = ct 57 ret['defaults'][node.get('Extension')] = ct
(...skipping 14 matching lines...) Expand all
72 filenames = ['no-extension', packagerEdge.MANIFEST, packagerEdge.BLOCKMAP] 72 filenames = ['no-extension', packagerEdge.MANIFEST, packagerEdge.BLOCKMAP]
73 filenames += ['file.' + x for x in 'json html js png css git otf'.split()] 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)) 74 ctm_dict = ctm2dict(packagerEdge.create_content_types_map(filenames))
75 assert ctm_dict['defaults'] == { 75 assert ctm_dict['defaults'] == {
76 'css': 'text/css', 76 'css': 'text/css',
77 'html': 'text/html', 77 'html': 'text/html',
78 'js': 'application/javascript', 78 'js': 'application/javascript',
79 'json': 'application/json', 79 'json': 'application/json',
80 'otf': 'application/octet-stream', 80 'otf': 'application/octet-stream',
81 'png': 'image/png', 81 'png': 'image/png',
82 'xml': 'application/xml' 82 'xml': 'application/xml',
83 } 83 }
84 assert ctm_dict['overrides'] == { 84 assert ctm_dict['overrides'] == {
85 '/AppxBlockMap.xml': 'application/vnd.ms-appx.blockmap+xml', 85 '/AppxBlockMap.xml': 'application/vnd.ms-appx.blockmap+xml',
86 '/AppxManifest.xml': 'application/vnd.ms-appx.manifest+xml' 86 '/AppxManifest.xml': 'application/vnd.ms-appx.manifest+xml',
87 } 87 }
OLDNEW
« no previous file with comments | « releaseAutomation.py ('k') | tests/test_packagerWebExt.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld