Left: | ||
Right: |
OLD | NEW |
---|---|
(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 json | |
6 import os | |
7 import shutil | |
8 | |
9 import pytest | |
10 | |
11 from buildtools import packager | |
12 | |
13 MESSAGES_EN_US = json.dumps({ | |
14 'name': {'message': 'Adblock Plus'}, | |
15 'name_devbuild': {'message': 'devbuild-marker'}, | |
16 'description': { | |
17 'message': 'Adblock Plus is the most popular ad blocker ever, ' | |
18 'and also supports websites by not blocking ' | |
19 'unobstrusive ads by default (configurable).' | |
20 }, | |
21 }) | |
22 | |
23 | |
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') | |
36 def chars(): | |
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.
| |
37 return b''.join(chr(i % 200 + 30) for i in range(500)) | |
38 | |
39 | |
40 @pytest.fixture | |
41 def metadata_files(tmp_dir, request): | |
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.""" | |
58 files = packager.Files(['lib'], set()) | |
59 for size in ['44', '50', '150']: | |
60 files['Assets/logo_{}.png'.format(size)] = chars | |
61 files['Extension/_locales/en_US/messages.json'] = MESSAGES_EN_US | |
62 files['_locales/en_US/messages.json'] = MESSAGES_EN_US | |
63 files['Extension/foo.xml'] = chars | |
64 files['Extension/bar.png'] = chars * 200 | |
65 files['lib/a.js'] = 'var bar;' | |
66 files['lib/b.js'] = 'var foo;' | |
67 | |
68 lib_dir = tmp_dir.mkdir('lib') | |
69 | |
70 lib_dir.join('a.js').write(files['lib/a.js']) | |
71 lib_dir.join('b.js').write(files['lib/b.js']) | |
72 return files | |
73 | |
74 | |
75 @pytest.fixture | |
76 def srcdir(tmp_dir): | |
77 """Source directory for building the package.""" | |
78 for size in ['44', '50', '150']: | |
79 path = tmp_dir.join('chrome', 'icons', 'abp-{}.png'.format(size)) | |
80 path.write(size, ensure=True) | |
81 | |
82 localedir = tmp_dir.mkdir('_locales') | |
83 en_us_dir = localedir.mkdir('en_US') | |
84 trans_dir = localedir.mkdir('en-US') | |
85 en_us_dir.join('messages.json').write(MESSAGES_EN_US) | |
86 | |
87 trans_dir.join('test.properties').write(''.join(( | |
88 'name=Adblock Plus\n', | |
89 'name_devbuild=devbuild-marker\n', | |
90 ))) | |
91 return tmp_dir | |
OLD | NEW |