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

Delta Between Two Patch Sets: sitescripts/extensions/test/conftest.py

Issue 29361729: Issue 4574 - Adds Tests to createNightlies platform specific revisions (Closed)
Left Patch Set: Created Nov. 4, 2016, 2:37 p.m.
Right Patch Set: add bookmark files so that all repos have master bookmark, add white space below license Created Nov. 25, 2016, 10:15 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | sitescripts/extensions/test/data/bookmarks/adblockplus.bookmarks » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # This file is part of the Adblock Plus web scripts, 1 # This file is part of the Adblock Plus web scripts,
2 # Copyright (C) 2006-2016 Eyeo GmbH 2 # Copyright (C) 2006-2016 Eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 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 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details. 11 # GNU General Public License for more details.
12 # 12 #
13 # You should have received a copy of the GNU General Public License 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/>. 14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
15 15
16 """ 16 """
17 Contains fixtures that are useful across test scripts for the extensions module 17 Contains fixtures that are useful across test scripts for the extensions module
18 """ 18 """
19 19
20 import subprocess 20 import subprocess
21 21
22 import pytest 22 import pytest
23 import py 23 import py
24 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': ('README.txt', '0.0')
31 }
32
33 25
34 @pytest.fixture(scope='session') 26 @pytest.fixture(scope='session')
35 def tests_dir(): 27 def tests_dir():
36 """Directory that contains this tests and the data files it uses.""" 28 """Directory that contains this tests and the data files it uses."""
37 return py.path.local(__file__).dirpath() 29 return py.path.local(__file__).dirpath()
38 30
39 31
40 @pytest.fixture(scope='session') 32 @pytest.fixture(scope='session')
41 def data_dir(tests_dir): 33 def data_dir(tests_dir):
42 return tests_dir.join('data') 34 return tests_dir.join('data')
43 35
44 36
45 # Fixtures using the built in tmpdir fixture must be function scoped which 37 @pytest.fixture(scope='session')
46 # causes about a 30% slow down. It would be faster to use tmpdir_factory 38 def diff_dir(data_dir):
47 # which is session scoped but for no it is not important. 39 return data_dir.join('diff')
40
41
48 @pytest.fixture(scope='session') 42 @pytest.fixture(scope='session')
49 def keys_dir(tmpdir_factory, tests_dir): 43 def keys_dir(tmpdir_factory, tests_dir):
Jon Sonesen 2016/11/04 15:11:55 Went ahead and optimized this to be session scoped
Vasily Kuznetsov 2016/11/07 14:53:21 :thumbsup:
50 keys_dir = tmpdir_factory.mktemp('keys') 44 keys_dir = tmpdir_factory.mktemp('keys')
51 key_filename = 'adblockplussafari.pem' 45 key_filename = 'adblockplussafari.pem'
52 tests_dir.join(key_filename).copy(keys_dir.join(key_filename)) 46 tests_dir.join(key_filename).copy(keys_dir.join(key_filename))
53 return keys_dir 47 return keys_dir
54 48
55 49
56 def call_hg(cwd, *params): 50 def call_hg(cwd, *params):
57 return subprocess.check_call(['hg'] + list(params), cwd=str(cwd)) 51 return subprocess.check_call(['hg'] + list(params), cwd=str(cwd))
58 52
59 53
54 def hg_import(repo_dir, diff_dir):
55 call_hg(repo_dir, 'import', diff_dir.strpath, '--exact')
56
57
60 @pytest.fixture(scope='session') 58 @pytest.fixture(scope='session')
61 def hg_dir(tmpdir_factory, data_dir): 59 def hg_dir(tmpdir_factory, data_dir, diff_dir):
62 """Directory that contains the repository mocks.""" 60 """Directory that contains the repository mocks."""
63 hg_dir = tmpdir_factory.mktemp('hg') 61 hg_dir = tmpdir_factory.mktemp('hg')
64 62
65 # Mock plugin repositories. 63 # Mock repositories from diff and bookmarks.
66 for repo, config in REPOS.items(): 64 for diff in diff_dir.visit():
67 filename, tag = config 65 repo_name = diff.purebasename.split('.')[0]
68 repo_dir = hg_dir.mkdir(repo) 66 repo_dir = hg_dir.mkdir(repo_name)
69 call_hg(repo_dir, 'init') 67 call_hg(repo_dir, 'init')
70 data_dir.join(filename).copy(repo_dir.join(filename)) 68 bookmark_file = data_dir.join('bookmarks', repo_name + '.bookmarks')
71 call_hg(repo_dir, 'add', filename) 69 if bookmark_file.exists():
72 call_hg(repo_dir, 'commit', '-m', '1') 70 destination = repo_dir.join('.hg').join('bookmarks')
73 call_hg(repo_dir, 'tag', tag) 71 bookmark_file.copy(destination)
74 72 hg_import(repo_dir, diff)
75 call_hg(hg_dir.join('adblockplusnightly'), 'bookmark', 'master')
76 call_hg(hg_dir.join('adblockplusnightly'), 'bookmark', 'safari')
77 command = ['touch', str(hg_dir.join('adblockplusnightly', 'foo'))]
78 subprocess.check_output(command)
79 call_hg(hg_dir.join('adblockplusnightly'), 'add', 'foo')
80 call_hg(hg_dir.join('adblockplusnightly'), 'commit', '-m', 'foo')
Jon Sonesen 2016/11/04 15:11:55 This could all be moved into a separate fixture wh
Vasily Kuznetsov 2016/11/07 14:53:21 I'm thinking that it might actually be better to s
Jon Sonesen 2016/11/08 17:29:45 Great, I will do this.
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 73
91 return hg_dir 74 return hg_dir
92
93
94 @pytest.fixture(scope='session')
95 def nightly_dir(hg_dir):
96 return hg_dir.join('adblockplusnightly')
97 75
98 76
99 @pytest.fixture() 77 @pytest.fixture()
100 def config_ini(tests_dir, tmpdir, hg_dir, keys_dir): 78 def config_ini(tests_dir, tmpdir, hg_dir, keys_dir):
101 """Sitescripts configuration.""" 79 """Sitescripts configuration."""
102 template = tests_dir.join('sitescripts.ini.template').read() 80 template = tests_dir.join('sitescripts.ini.template').read()
103 conf = template.format(hg_dir=hg_dir, out_dir=tmpdir, keys_dir=keys_dir) 81 conf = template.format(hg_dir=hg_dir, out_dir=tmpdir, keys_dir=keys_dir)
104 config_ini = tmpdir.join('sitescripts.ini') 82 config_ini = tmpdir.join('sitescripts.ini')
105 config_ini.write(conf) 83 config_ini.write(conf)
106 return config_ini 84 return config_ini
LEFTRIGHT

Powered by Google App Engine
This is Rietveld