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

Side by Side Diff: tests/test_packagerWebExt.py

Issue 29756673: Noissue - Adapt best practices for trailing commas (buildtools) (Closed)
Patch Set: Re-run script on Python 2, added flake8-commas extension Created April 19, 2018, 2:09 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 | « tests/test_packagerEdge.py ('k') | tox.ini » ('j') | tox.ini » ('J')
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 difflib 5 import difflib
6 import json 6 import json
7 import os 7 import os
8 import re 8 import re
9 import shutil 9 import shutil
10 import zipfile 10 import zipfile
11 from xml.etree import ElementTree 11 from xml.etree import ElementTree
12 from struct import unpack 12 from struct import unpack
13 13
14 import pytest 14 import pytest
15 from Crypto.Signature import PKCS1_v1_5 15 from Crypto.Signature import PKCS1_v1_5
16 from Crypto.PublicKey import RSA 16 from Crypto.PublicKey import RSA
17 from Crypto.Hash import SHA 17 from Crypto.Hash import SHA
18 18
19 from buildtools import packager 19 from buildtools import packager
20 from buildtools.packagerChrome import defaultLocale 20 from buildtools.packagerChrome import defaultLocale
21 from buildtools.build import process_args 21 from buildtools.build import process_args
22 22
23 LOCALES_MODULE = { 23 LOCALES_MODULE = {
24 'test.Foobar': { 24 'test.Foobar': {
25 'message': 'Ensuring dict-copy from modules for $domain$', 25 'message': 'Ensuring dict-copy from modules for $domain$',
26 'description': 'test description', 26 'description': 'test description',
27 'placeholders': {'content': '$1', 'example': 'www.adblockplus.org'} 27 'placeholders': {'content': '$1', 'example': 'www.adblockplus.org'},
28 } 28 },
29 } 29 }
30 30
31 ALL_LANGUAGES = ['en_US', 'de', 'it'] 31 ALL_LANGUAGES = ['en_US', 'de', 'it']
32 32
33 MESSAGES_EN_US = json.dumps({ 33 MESSAGES_EN_US = json.dumps({
34 'name': {'message': 'Adblock Plus'}, 34 'name': {'message': 'Adblock Plus'},
35 'name_devbuild': {'message': 'devbuild-marker'}, 35 'name_devbuild': {'message': 'devbuild-marker'},
36 'description': { 36 'description': {
37 'message': 'Adblock Plus is the most popular ad blocker ever, ' 37 'message': 'Adblock Plus is the most popular ad blocker ever, '
38 'and also supports websites by not blocking ' 38 'and also supports websites by not blocking '
39 'unobstrusive ads by default (configurable).' 39 'unobstrusive ads by default (configurable).',
40 }, 40 },
41 }) 41 })
42 42
43 43
44 class Content(object): 44 class Content(object):
45 """Base class for a unified ZipFile / Directory interface. 45 """Base class for a unified ZipFile / Directory interface.
46 46
47 Base class for providing a unified context manager interface for 47 Base class for providing a unified context manager interface for
48 accessing files. This class is subclassed by ZipContent and DirContent, 48 accessing files. This class is subclassed by ZipContent and DirContent,
49 which provide the additional methods "namelist()" and "read(path)". 49 which provide the additional methods "namelist()" and "read(path)".
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 files['qunit/tests/some_test.js'] = 'var passed = true;' 235 files['qunit/tests/some_test.js'] = 'var passed = true;'
236 236
237 tmpdir.mkdir('lib').join('b.js').write(files['lib/b.js']) 237 tmpdir.mkdir('lib').join('b.js').write(files['lib/b.js'])
238 ext_dir = tmpdir.mkdir('ext') 238 ext_dir = tmpdir.mkdir('ext')
239 ext_dir.join('a.js').write(files['ext/a.js']) 239 ext_dir.join('a.js').write(files['ext/a.js'])
240 ext_dir.join('c.js').write(files['ext/c.js']) 240 ext_dir.join('c.js').write(files['ext/c.js'])
241 qunit_dir = tmpdir.mkdir('qunit') 241 qunit_dir = tmpdir.mkdir('qunit')
242 qunit_dir.join('common.js').write(files['qunit/common.js']) 242 qunit_dir.join('common.js').write(files['qunit/common.js'])
243 qunit_tests_dir = qunit_dir.mkdir('tests') 243 qunit_tests_dir = qunit_dir.mkdir('tests')
244 qunit_tests_dir.join('some_test.js').write( 244 qunit_tests_dir.join('some_test.js').write(
245 files['qunit/tests/some_test.js'] 245 files['qunit/tests/some_test.js'],
246 ) 246 )
247 return files 247 return files
248 248
249 249
250 def comparable_json(json_data): 250 def comparable_json(json_data):
251 """Create a nonambiguous representation of the given JSON data.""" 251 """Create a nonambiguous representation of the given JSON data."""
252 if isinstance(json_data, basestring): 252 if isinstance(json_data, basestring):
253 json_data = json.loads(json_data) 253 json_data = json.loads(json_data)
254 return json.dumps( 254 return json.dumps(
255 json_data, sort_keys=True, indent=0 255 json_data, sort_keys=True, indent=0,
256 ).split('\n') 256 ).split('\n')
257 257
258 258
259 def comparable_xml(xml): 259 def comparable_xml(xml):
260 """Create a nonambiguous representation of a given XML tree.""" 260 """Create a nonambiguous representation of a given XML tree."""
261 def strip(s): 261 def strip(s):
262 if s is None: 262 if s is None:
263 return '' 263 return ''
264 return s.strip() 264 return s.strip()
265 265
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 assert (os.path.join(prefix, 'devenvVersion__') in filenames) == devenv 317 assert (os.path.join(prefix, 'devenvVersion__') in filenames) == devenv
318 assert (os.path.join(prefix, 'qunit/tests.js') in filenames) == devenv 318 assert (os.path.join(prefix, 'qunit/tests.js') in filenames) == devenv
319 assert (os.path.join(prefix, 'qunit/tests.js.map') in filenames) == devenv 319 assert (os.path.join(prefix, 'qunit/tests.js.map') in filenames) == devenv
320 320
321 if devenv: 321 if devenv:
322 quint_index = package.read(os.path.join(prefix, 'qunit/index.html')) 322 quint_index = package.read(os.path.join(prefix, 'qunit/index.html'))
323 assert '../ext/common.js' in quint_index 323 assert '../ext/common.js' in quint_index
324 assert '../ext/background.js' in quint_index 324 assert '../ext/background.js' in quint_index
325 325
326 assert set(manifest['background']['scripts']) == set( 326 assert set(manifest['background']['scripts']) == set(
327 scripts + ['devenvPoller__.js'] 327 scripts + ['devenvPoller__.js'],
328 ) 328 )
329 else: 329 else:
330 assert set(manifest['background']['scripts']) == set(scripts) 330 assert set(manifest['background']['scripts']) == set(scripts)
331 331
332 332
333 def assert_base_files(package, platform, prefix): 333 def assert_base_files(package, platform, prefix):
334 filenames = set(package.namelist()) 334 filenames = set(package.namelist())
335 335
336 if platform == 'edge': 336 if platform == 'edge':
337 assert 'AppxManifest.xml' in filenames 337 assert 'AppxManifest.xml' in filenames
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 manifests = { 414 manifests = {
415 'gecko': [('', 'manifest', 'json')], 415 'gecko': [('', 'manifest', 'json')],
416 'chrome': [('', 'manifest', 'json')], 416 'chrome': [('', 'manifest', 'json')],
417 'edge': [('', 'AppxManifest', 'xml'), 417 'edge': [('', 'AppxManifest', 'xml'),
418 ('Extension', 'manifest', 'json')], 418 ('Extension', 'manifest', 'json')],
419 } 419 }
420 420
421 filenames = { 421 filenames = {
422 'gecko': 'adblockplusfirefox-1.2.3{}.xpi', 422 'gecko': 'adblockplusfirefox-1.2.3{}.xpi',
423 'chrome': 'adblockpluschrome-1.2.3{{}}.{}'.format( 423 'chrome': 'adblockpluschrome-1.2.3{{}}.{}'.format(
424 {True: 'crx', False: 'zip'}[release] 424 {True: 'crx', False: 'zip'}[release],
425 ), 425 ),
426 'edge': 'adblockplusedge-1.2.3{}.appx', 426 'edge': 'adblockplusedge-1.2.3{}.appx',
427 } 427 }
428 428
429 if platform == 'edge': 429 if platform == 'edge':
430 prefix = 'Extension' 430 prefix = 'Extension'
431 else: 431 else:
432 prefix = '' 432 prefix = ''
433 433
434 run_webext_build(platform, command, srcdir, keyfile=key) 434 run_webext_build(platform, command, srcdir, keyfile=key)
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 expected = os.path.join( 474 expected = os.path.join(
475 os.path.dirname(__file__), 475 os.path.dirname(__file__),
476 'expecteddata', 476 'expecteddata',
477 filename.format(name, ext), 477 filename.format(name, ext),
478 ) 478 )
479 479
480 assert_manifest_content( 480 assert_manifest_content(
481 package.read(os.path.join(folder, '{}.{}'.format(name, ext))), 481 package.read(os.path.join(folder, '{}.{}'.format(name, ext))),
482 expected, 482 expected,
483 ) 483 )
OLDNEW
« no previous file with comments | « tests/test_packagerEdge.py ('k') | tox.ini » ('j') | tox.ini » ('J')

Powered by Google App Engine
This is Rietveld