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

Unified Diff: tests/conftest.py

Issue 29501558: Issue 5383 - Add tests for the Chrome and Firefox packagers (Closed)
Patch Set: Created July 31, 2017, 12:07 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/metadata.chrome » ('j') | tests/test_packagerChrome.py » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/conftest.py
diff --git a/tests/conftest.py b/tests/conftest.py
new file mode 100644
index 0000000000000000000000000000000000000000..eb499932281b8e32553d4f18b9cea318abee3391
--- /dev/null
+++ b/tests/conftest.py
@@ -0,0 +1,91 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import json
+import os
+import shutil
+
+import pytest
+
+from buildtools import packager
+
+MESSAGES_EN_US = json.dumps({
+ 'name': {'message': 'Adblock Plus'},
+ 'name_devbuild': {'message': 'devbuild-marker'},
+ 'description': {
+ 'message': 'Adblock Plus is the most popular ad blocker ever, '
+ 'and also supports websites by not blocking '
+ 'unobstrusive ads by default (configurable).'
+ },
+})
+
+
+def metadata_path(filename):
+ path = os.path.join(os.path.dirname(__file__), filename)
+ return path
+
+
+@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
+def tmp_dir(tmpdir_factory):
+ t_dir = tmpdir_factory.mktemp('data')
+ return t_dir
+
+
+@pytest.fixture(scope='module')
+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.
+ return b''.join(chr(i % 200 + 30) for i in range(500))
+
+
+@pytest.fixture
+def metadata_files(tmp_dir, request):
+ """Copy of used metadata file(s)"""
+ def copy(filename):
+ path = metadata_path(filename)
+ destination = str(tmp_dir.join(filename))
+ shutil.copy(path, destination)
+
+ if isinstance(request.param, str):
+ copy(request.param)
+ else:
+ for filename in request.param:
+ copy(filename)
+
+
+@pytest.fixture
+def files(tmp_dir, chars):
+ """Minimal Files() for testing all packagers."""
+ files = packager.Files(['lib'], set())
+ for size in ['44', '50', '150']:
+ files['Assets/logo_{}.png'.format(size)] = chars
+ files['Extension/_locales/en_US/messages.json'] = MESSAGES_EN_US
+ files['_locales/en_US/messages.json'] = MESSAGES_EN_US
+ files['Extension/foo.xml'] = chars
+ files['Extension/bar.png'] = chars * 200
+ files['lib/a.js'] = 'var bar;'
+ files['lib/b.js'] = 'var foo;'
+
+ lib_dir = tmp_dir.mkdir('lib')
+
+ lib_dir.join('a.js').write(files['lib/a.js'])
+ lib_dir.join('b.js').write(files['lib/b.js'])
+ return files
+
+
+@pytest.fixture
+def srcdir(tmp_dir):
+ """Source directory for building the package."""
+ for size in ['44', '50', '150']:
+ path = tmp_dir.join('chrome', 'icons', 'abp-{}.png'.format(size))
+ path.write(size, ensure=True)
+
+ localedir = tmp_dir.mkdir('_locales')
+ en_us_dir = localedir.mkdir('en_US')
+ trans_dir = localedir.mkdir('en-US')
+ en_us_dir.join('messages.json').write(MESSAGES_EN_US)
+
+ trans_dir.join('test.properties').write(''.join((
+ 'name=Adblock Plus\n',
+ 'name_devbuild=devbuild-marker\n',
+ )))
+ return tmp_dir
« no previous file with comments | « no previous file | tests/metadata.chrome » ('j') | tests/test_packagerChrome.py » ('J')

Powered by Google App Engine
This is Rietveld