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

Side by Side Diff: sitescripts/extensions/test/conftest.py

Issue 29358368: Issue 4540 - Add Platform Specific Branch Support to createNightlies.py (Closed)
Patch Set: Adressing comments adds single unit test Created Oct. 24, 2016, 5:24 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
OLDNEW
(Empty)
1 # This file is part of the Adblock Plus web scripts,
2 # Copyright (C) 2006-2016 Eyeo GmbH
3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation.
7 #
8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
15
16 """
17 Contains fixtures that are useful across test scripts for the extensions module
18 """
19
Jon Sonesen 2016/10/24 17:32:32 Broke these fixtures out of Vasily's test script a
kzar 2016/10/25 08:13:01 Perhaps Vasily disagrees with me but I don't think
Jon Sonesen 2016/10/25 09:15:18 Acknowledged in main message. I will add a commen
20 import subprocess
21
22 import pytest
23 import py
24
25 REPOS = {
26 'adblockplus': ('metadata.gecko', '2.7.3'),
27 'adblockplusie': ('README.txt', '1.33.7'),
28 'adblockpluschrome': ('metadata.safari', '1.12.3'),
29 'adblockplusandroid': ('AndroidManifest.xml', '1.3'),
30 'adblockplusnightly': ('nightlies', '0.0')
31 }
32
33
34 @pytest.fixture(scope='session')
35 def tests_dir():
36 """Directory that contains this tests and the data files it uses."""
37 return py.path.local(__file__).dirpath()
38
39
40 @pytest.fixture(scope='session')
41 def oracle(tests_dir):
42 """Function that returns expected content of generated files."""
43 def expected_value_of(what):
44 return tests_dir.join('oracle').join(what).read().strip()
45 return expected_value_of
46
47
48 @pytest.fixture(scope='session')
49 def data_dir(tests_dir):
50 return tests_dir.join('data')
51
52
53 @pytest.fixture()
54 def keys_dir(tmpdir, tests_dir):
55 keys_dir = tmpdir.mkdir('keys')
56 key_filename = 'adblockplussafari.pem'
57 tests_dir.join(key_filename).copy(keys_dir.join(key_filename))
58 return keys_dir
59
60
61 def call_hg(cwd, *params):
62 return subprocess.check_call(['hg'] + list(params), cwd=str(cwd))
63
64
65 @pytest.fixture()
66 def hg_dir(tmpdir, data_dir):
67 """Directory that contains the repository mocks."""
68 hg_dir = tmpdir.mkdir('hg')
69
70 # Mock plugin repositories.
71 for repo, config in REPOS.items():
72 filename, tag = config
73 repo_dir = hg_dir.mkdir(repo)
74 call_hg(repo_dir, 'init')
75 data_dir.join(filename).copy(repo_dir.join(filename))
76 call_hg(repo_dir, 'add', filename)
77 call_hg(repo_dir, 'commit', '-m', '1')
78 call_hg(repo_dir, 'tag', tag)
79
80 call_hg(hg_dir.join('adblockplusnightly'), 'bookmark', 'foo')
81
82 # Mock the downloads repository.
83 downloads_list = data_dir.join('downloads.list').read().splitlines()
84 downloads_dir = hg_dir.mkdir('downloads')
85 call_hg(downloads_dir, 'init')
86 for item in downloads_list:
87 downloads_dir.join(item).write('')
88 call_hg(downloads_dir, 'add', *downloads_list)
89 call_hg(downloads_dir, 'commit', '-m', 'ok')
90
91 return hg_dir
92
93
94 @pytest.fixture()
95 def config_ini(tests_dir, tmpdir, hg_dir, keys_dir):
96 """Sitescripts configuration."""
97 template = tests_dir.join('sitescripts.ini.template').read()
98 conf = template.format(hg_dir=hg_dir, out_dir=tmpdir, keys_dir=keys_dir)
99 config_ini = tmpdir.join('sitescripts.ini')
100 config_ini.write(conf)
101 return config_ini
OLDNEW

Powered by Google App Engine
This is Rietveld