| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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 json | 5 import json |
| 6 import os | |
| 7 import shutil | |
| 8 | 6 |
| 9 import pytest | 7 import pytest |
| 10 | 8 |
| 11 from buildtools import packager | 9 from buildtools import packager |
| 12 | 10 |
| 13 MESSAGES_EN_US = json.dumps({ | 11 MESSAGES_EN_US = json.dumps({ |
| 14 'name': {'message': 'Adblock Plus'}, | 12 'name': {'message': 'Adblock Plus'}, |
| 15 'name_devbuild': {'message': 'devbuild-marker'}, | 13 'name_devbuild': {'message': 'devbuild-marker'}, |
| 16 'description': { | 14 'description': { |
| 17 'message': 'Adblock Plus is the most popular ad blocker ever, ' | 15 'message': 'Adblock Plus is the most popular ad blocker ever, ' |
| 18 'and also supports websites by not blocking ' | 16 'and also supports websites by not blocking ' |
| 19 'unobstrusive ads by default (configurable).' | 17 'unobstrusive ads by default (configurable).' |
| 20 }, | 18 }, |
| 21 }) | 19 }) |
| 22 | 20 |
| 23 | 21 |
| 24 def metadata_path(filename): | |
| 25 path = os.path.join(os.path.dirname(__file__), filename) | |
| 26 return path | |
| 27 | |
| 28 | |
| 29 @pytest.fixture | |
|
Vasily Kuznetsov
2017/08/03 16:52:28
What's the purpose of this vs. just using `tmpdir`
tlucas
2017/08/03 21:26:00
Iirc the tmpdir fixture would not have allowed me
tlucas
2017/08/04 14:51:56
That actually is the reason, why i implemented 1 f
| |
| 30 def tmp_dir(tmpdir_factory): | |
| 31 t_dir = tmpdir_factory.mktemp('data') | |
| 32 return t_dir | |
| 33 | |
| 34 | |
| 35 @pytest.fixture(scope='module') | 22 @pytest.fixture(scope='module') |
| 36 def chars(): | 23 def str500chars(): |
|
Vasily Kuznetsov
2017/08/03 16:52:28
This name is quite generic. What do you think abou
tlucas
2017/08/03 21:25:59
Acknowledged.
tlucas
2017/08/04 14:51:56
Done.
| |
| 24 """Generates a String of 500 chars to simulate data""" | |
| 37 return b''.join(chr(i % 200 + 30) for i in range(500)) | 25 return b''.join(chr(i % 200 + 30) for i in range(500)) |
| 38 | 26 |
| 39 | 27 |
| 40 @pytest.fixture | 28 @pytest.fixture |
| 41 def metadata_files(tmp_dir, request): | 29 def files(tmpdir, str500chars): |
|
Vasily Kuznetsov
2017/08/10 19:48:27
This name doesn't really tell me much. The docstri
tlucas
2017/08/11 12:17:08
Done.
| |
| 42 """Copy of used metadata file(s)""" | |
| 43 def copy(filename): | |
| 44 path = metadata_path(filename) | |
| 45 destination = str(tmp_dir.join(filename)) | |
| 46 shutil.copy(path, destination) | |
| 47 | |
| 48 if isinstance(request.param, str): | |
| 49 copy(request.param) | |
| 50 else: | |
| 51 for filename in request.param: | |
| 52 copy(filename) | |
| 53 | |
| 54 | |
| 55 @pytest.fixture | |
| 56 def files(tmp_dir, chars): | |
| 57 """Minimal Files() for testing all packagers.""" | 30 """Minimal Files() for testing all packagers.""" |
| 58 files = packager.Files(['lib'], set()) | 31 files = packager.Files(['lib'], set()) |
| 59 for size in ['44', '50', '150']: | 32 for size in ['44', '50', '150']: |
| 60 files['Assets/logo_{}.png'.format(size)] = chars | 33 files['Assets/logo_{}.png'.format(size)] = str500chars |
| 61 files['Extension/_locales/en_US/messages.json'] = MESSAGES_EN_US | 34 files['Extension/_locales/en_US/messages.json'] = MESSAGES_EN_US |
| 62 files['_locales/en_US/messages.json'] = MESSAGES_EN_US | 35 files['_locales/en_US/messages.json'] = MESSAGES_EN_US |
| 63 files['Extension/foo.xml'] = chars | 36 files['Extension/foo.xml'] = str500chars |
| 64 files['Extension/bar.png'] = chars * 200 | 37 files['Extension/bar.png'] = str500chars * 200 |
| 65 files['lib/a.js'] = 'var bar;' | 38 files['lib/a.js'] = 'var bar;' |
| 66 files['lib/b.js'] = 'var foo;' | 39 files['lib/b.js'] = 'var foo;' |
| 67 | 40 |
| 68 lib_dir = tmp_dir.mkdir('lib') | 41 lib_dir = tmpdir.mkdir('lib') |
| 69 | 42 |
| 70 lib_dir.join('a.js').write(files['lib/a.js']) | 43 lib_dir.join('a.js').write(files['lib/a.js']) |
| 71 lib_dir.join('b.js').write(files['lib/b.js']) | 44 lib_dir.join('b.js').write(files['lib/b.js']) |
| 72 return files | 45 return files |
| 73 | 46 |
| 74 | 47 |
| 75 @pytest.fixture | 48 @pytest.fixture |
| 76 def srcdir(tmp_dir): | 49 def srcdir(tmpdir): |
| 77 """Source directory for building the package.""" | 50 """Source directory for building the package.""" |
| 78 for size in ['44', '50', '150']: | 51 for size in ['44', '50', '150']: |
| 79 path = tmp_dir.join('chrome', 'icons', 'abp-{}.png'.format(size)) | 52 path = tmpdir.join('chrome', 'icons', 'abp-{}.png'.format(size)) |
| 80 path.write(size, ensure=True) | 53 path.write(size, ensure=True) |
| 81 | 54 |
| 82 localedir = tmp_dir.mkdir('_locales') | 55 localedir = tmpdir.mkdir('_locales') |
| 83 en_us_dir = localedir.mkdir('en_US') | 56 en_us_dir = localedir.mkdir('en_US') |
| 84 trans_dir = localedir.mkdir('en-US') | 57 trans_dir = localedir.mkdir('en-US') |
| 85 en_us_dir.join('messages.json').write(MESSAGES_EN_US) | 58 en_us_dir.join('messages.json').write(MESSAGES_EN_US) |
| 86 | 59 |
| 87 trans_dir.join('test.properties').write(''.join(( | 60 trans_dir.join('test.properties').write(''.join(( |
| 88 'name=Adblock Plus\n', | 61 'name=Adblock Plus\n', |
| 89 'name_devbuild=devbuild-marker\n', | 62 'name_devbuild=devbuild-marker\n', |
| 90 ))) | 63 ))) |
| 91 return tmp_dir | 64 return tmpdir |
| LEFT | RIGHT |