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

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

Issue 29940559: Issue 7112 - Add centralised conftest (Closed)
Patch Set: Addressed comments from Patch Set #1 Created Nov. 14, 2018, 4:08 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-present 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
20 import subprocess
21
22 import pytest
23 import py
24
25
26 @pytest.fixture(scope='session')
27 def tests_dir():
28 """Directory that contains this tests and the data files it uses."""
29 return py.path.local(__file__).dirpath()
30
31
32 @pytest.fixture(scope='session')
33 def data_dir(tests_dir):
34 return tests_dir.join('data')
35
36
37 @pytest.fixture(scope='session')
38 def diff_dir(data_dir):
39 return data_dir.join('diff')
40
41
42 @pytest.fixture(scope='session')
43 def keys_dir(tmpdir_factory, tests_dir):
44 keys_dir = tmpdir_factory.mktemp('keys')
45 key_filename = 'adblockplussafari.pem'
46 tests_dir.join(key_filename).copy(keys_dir.join(key_filename))
47 return keys_dir
48
49
50 def call_hg(cwd, *params):
51 return subprocess.check_call(['hg'] + list(params), cwd=str(cwd))
52
53
54 def hg_import(repo_dir, diff_dir):
55 call_hg(repo_dir, 'import', diff_dir.strpath, '--exact')
56
57
58 @pytest.fixture(scope='session')
59 def hg_dir(tmpdir_factory, data_dir, diff_dir):
60 """Directory that contains the repository mocks."""
61 hg_dir = tmpdir_factory.mktemp('hg')
62
63 # Mock repositories from diff and bookmarks.
64 for diff in diff_dir.visit():
65 repo_name = diff.purebasename.split('.')[0]
66 repo_dir = hg_dir.mkdir(repo_name)
67 call_hg(repo_dir, 'init')
68 bookmark_file = data_dir.join('bookmarks', repo_name + '.bookmarks')
69 if bookmark_file.exists():
70 destination = repo_dir.join('.hg').join('bookmarks')
71 bookmark_file.copy(destination)
72 hg_import(repo_dir, diff)
73
74 return hg_dir
75
76
77 @pytest.fixture()
78 def config_ini(tests_dir, tmpdir, hg_dir, keys_dir):
79 """Sitescripts configuration."""
80 template = tests_dir.join('sitescripts.ini.template').read()
81 conf = template.format(hg_dir=hg_dir, out_dir=tmpdir, keys_dir=keys_dir)
82 config_ini = tmpdir.join('sitescripts.ini')
83 config_ini.write(conf)
84 return config_ini
OLDNEW

Powered by Google App Engine
This is Rietveld