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

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

Issue 29358368: Issue 4540 - Add Platform Specific Branch Support to createNightlies.py (Closed)
Left Patch Set: adds fixture to generate place holder nightlies file, removes nightlies file from repo Created Oct. 25, 2016, 10:29 a.m.
Right Patch Set: Created Oct. 26, 2016, 5:53 p.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 | « sitescripts/extensions/bin/createNightlies.py ('k') | sitescripts/extensions/test/test_createNightlies.py » ('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 = { 25 REPOS = {
26 'adblockplus': ('metadata.gecko', '2.7.3'), 26 'adblockplus': ('metadata.gecko', '2.7.3'),
27 'adblockplusie': ('README.txt', '1.33.7'), 27 'adblockplusie': ('README.txt', '1.33.7'),
28 'adblockpluschrome': ('metadata.safari', '1.12.3'), 28 'adblockpluschrome': ('metadata.safari', '1.12.3'),
29 'adblockplusandroid': ('AndroidManifest.xml', '1.3'), 29 'adblockplusandroid': ('AndroidManifest.xml', '1.3'),
30 'adblockplusnightly': ('nightlies', '0.0') 30 'adblockplusnightly': ('README.txt', '0.0')
31 } 31 }
32 32
33 33
34 @pytest.fixture(scope='session') 34 @pytest.fixture(scope='session')
35 def tests_dir(): 35 def tests_dir():
36 """Directory that contains this tests and the data files it uses.""" 36 """Directory that contains this tests and the data files it uses."""
37 return py.path.local(__file__).dirpath() 37 return py.path.local(__file__).dirpath()
38 38
39 39
40 @pytest.fixture(scope='session') 40 @pytest.fixture(scope='session')
Vasily Kuznetsov 2016/10/25 16:04:33 This fixture is only used by `test_updateManifests
Jon Sonesen 2016/10/25 16:42:59 Acknowledged
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): 41 def data_dir(tests_dir):
50 return tests_dir.join('data') 42 return tests_dir.join('data')
51
52
53 @pytest.fixture(scope='session')
Vasily Kuznetsov 2016/10/25 16:04:33 The `nightlies` file that we create here and then
Jon Sonesen 2016/10/25 16:23:49 Im not sure what you mean by this. The nightlies f
Vasily Kuznetsov 2016/10/25 16:39:22 I don't think it's required for the test that we h
Jon Sonesen 2016/10/25 16:42:59 Okay, I will update that thank you.
54 def tmp_nightly(data_dir):
55 subprocess.check_call(['touch', str(data_dir.join('nightlies'))])
56 yield
57 subprocess.check_call(['rm', str(data_dir.join('nightlies'))])
58 43
59 44
60 # Fixtures using the built in tmpdir fixture must be function scoped which 45 # Fixtures using the built in tmpdir fixture must be function scoped which
61 # causes about a 30% slow down. It would be faster to use tmpdir_factory 46 # causes about a 30% slow down. It would be faster to use tmpdir_factory
62 # which is session scoped but for no it is not important. 47 # which is session scoped but for no it is not important.
63 @pytest.fixture() 48 @pytest.fixture()
64 def keys_dir(tmpdir, tests_dir): 49 def keys_dir(tmpdir, tests_dir):
65 keys_dir = tmpdir.mkdir('keys') 50 keys_dir = tmpdir.mkdir('keys')
66 key_filename = 'adblockplussafari.pem' 51 key_filename = 'adblockplussafari.pem'
67 tests_dir.join(key_filename).copy(keys_dir.join(key_filename)) 52 tests_dir.join(key_filename).copy(keys_dir.join(key_filename))
68 return keys_dir 53 return keys_dir
69 54
70 55
71 def call_hg(cwd, *params): 56 def call_hg(cwd, *params):
72 return subprocess.check_call(['hg'] + list(params), cwd=str(cwd)) 57 return subprocess.check_call(['hg'] + list(params), cwd=str(cwd))
73 58
74 59
75 @pytest.fixture() 60 @pytest.fixture()
76 def hg_dir(tmp_nightly, tmpdir, data_dir): 61 def hg_dir(tmpdir, data_dir):
77 """Directory that contains the repository mocks.""" 62 """Directory that contains the repository mocks."""
78 hg_dir = tmpdir.mkdir('hg') 63 hg_dir = tmpdir.mkdir('hg')
79 64
80 # Mock plugin repositories. 65 # Mock plugin repositories.
81 for repo, config in REPOS.items(): 66 for repo, config in REPOS.items():
82 filename, tag = config 67 filename, tag = config
83 repo_dir = hg_dir.mkdir(repo) 68 repo_dir = hg_dir.mkdir(repo)
84 call_hg(repo_dir, 'init') 69 call_hg(repo_dir, 'init')
85 data_dir.join(filename).copy(repo_dir.join(filename)) 70 data_dir.join(filename).copy(repo_dir.join(filename))
86 call_hg(repo_dir, 'add', filename) 71 call_hg(repo_dir, 'add', filename)
(...skipping 15 matching lines...) Expand all
102 87
103 88
104 @pytest.fixture() 89 @pytest.fixture()
105 def config_ini(tests_dir, tmpdir, hg_dir, keys_dir): 90 def config_ini(tests_dir, tmpdir, hg_dir, keys_dir):
106 """Sitescripts configuration.""" 91 """Sitescripts configuration."""
107 template = tests_dir.join('sitescripts.ini.template').read() 92 template = tests_dir.join('sitescripts.ini.template').read()
108 conf = template.format(hg_dir=hg_dir, out_dir=tmpdir, keys_dir=keys_dir) 93 conf = template.format(hg_dir=hg_dir, out_dir=tmpdir, keys_dir=keys_dir)
109 config_ini = tmpdir.join('sitescripts.ini') 94 config_ini = tmpdir.join('sitescripts.ini')
110 config_ini.write(conf) 95 config_ini.write(conf)
111 return config_ini 96 return config_ini
LEFTRIGHT

Powered by Google App Engine
This is Rietveld