| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 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': ('README.txt', '0.0') | |
| 31 } | 30 } |
| 32 | 31 |
| 33 | 32 |
| 34 @pytest.fixture(scope='session') | 33 @pytest.fixture(scope='session') |
| 35 def tests_dir(): | 34 def tests_dir(): |
| 36 """Directory that contains this tests and the data files it uses.""" | 35 """Directory that contains this tests and the data files it uses.""" |
| 37 return py.path.local(__file__).dirpath() | 36 return py.path.local(__file__).dirpath() |
| 38 | 37 |
| 39 | 38 |
| 40 @pytest.fixture(scope='session') | 39 @pytest.fixture(scope='session') |
| 41 def data_dir(tests_dir): | 40 def data_dir(tests_dir): |
| 42 return tests_dir.join('data') | 41 return tests_dir.join('data') |
| 43 | 42 |
| 44 | 43 |
| 44 @pytest.fixture(scope='session') | |
| 45 def diff_dir(data_dir): | |
| 46 return data_dir.join('diff') | |
| 47 | |
| 48 | |
| 45 # Fixtures using the built in tmpdir fixture must be function scoped which | 49 # Fixtures using the built in tmpdir fixture must be function scoped which |
| 46 # causes about a 30% slow down. It would be faster to use tmpdir_factory | 50 # causes about a 30% slow down. It would be faster to use tmpdir_factory |
| 47 # which is session scoped but for no it is not important. | 51 # which is session scoped but for no it is not important. |
| 48 @pytest.fixture() | 52 @pytest.fixture(scope='session') |
| 49 def keys_dir(tmpdir, tests_dir): | 53 def keys_dir(tmpdir_factory, tests_dir): |
| 50 keys_dir = tmpdir.mkdir('keys') | 54 keys_dir = tmpdir_factory.mktemp('keys') |
| 51 key_filename = 'adblockplussafari.pem' | 55 key_filename = 'adblockplussafari.pem' |
| 52 tests_dir.join(key_filename).copy(keys_dir.join(key_filename)) | 56 tests_dir.join(key_filename).copy(keys_dir.join(key_filename)) |
| 53 return keys_dir | 57 return keys_dir |
| 54 | 58 |
| 55 | 59 |
| 56 def call_hg(cwd, *params): | 60 def call_hg(cwd, *params): |
| 57 return subprocess.check_call(['hg'] + list(params), cwd=str(cwd)) | 61 return subprocess.check_call(['hg'] + list(params), cwd=str(cwd)) |
| 58 | 62 |
| 59 | 63 |
| 60 @pytest.fixture() | 64 def hg_import(repo_dir, diff_dir, repo): |
| 61 def hg_dir(tmpdir, data_dir): | 65 call_hg(repo_dir, 'import', str(diff_dir.join('{}0.diff'.format(repo))), |
|
Vasily Kuznetsov
2016/11/14 19:42:38
Couldn't we have both commits in the same file? If
Jon Sonesen
2016/11/15 15:40:25
Done.
| |
| 66 str(diff_dir.join('{}1.diff'.format(repo))), '--exact') | |
| 67 | |
| 68 | |
| 69 @pytest.fixture(scope='session') | |
| 70 def hg_dir(tmpdir_factory, data_dir, diff_dir): | |
| 62 """Directory that contains the repository mocks.""" | 71 """Directory that contains the repository mocks.""" |
| 63 hg_dir = tmpdir.mkdir('hg') | 72 hg_dir = tmpdir_factory.mktemp('hg') |
| 73 nightlydir = hg_dir.mkdir('adblockplusnightly') | |
| 64 | 74 |
| 65 # Mock plugin repositories. | 75 # Mock plugin repositories. |
| 66 for repo, config in REPOS.items(): | 76 for repo, config in REPOS.items(): |
| 67 filename, tag = config | 77 filename, tag = config |
|
Vasily Kuznetsov
2016/11/14 19:42:38
We're not using `filename` and `tag` anymore, sinc
Jon Sonesen
2016/11/15 11:18:46
Agreed, this is a good method. Will use.
| |
| 68 repo_dir = hg_dir.mkdir(repo) | 78 repo_dir = hg_dir.mkdir(repo) |
| 69 call_hg(repo_dir, 'init') | 79 call_hg(repo_dir, 'init') |
| 70 data_dir.join(filename).copy(repo_dir.join(filename)) | 80 hg_import(repo_dir, diff_dir, repo) |
| 71 call_hg(repo_dir, 'add', filename) | |
| 72 call_hg(repo_dir, 'commit', '-m', '1') | |
| 73 call_hg(repo_dir, 'tag', tag) | |
| 74 | 81 |
| 75 call_hg(hg_dir.join('adblockplusnightly'), 'bookmark', 'safari') | 82 call_hg(nightlydir, 'init') |
| 83 call_hg(nightlydir, 'bookmark', 'master') | |
|
Vasily Kuznetsov
2016/11/14 19:42:38
Bookmarks can also be in a file (called `<repo-nam
Jon Sonesen
2016/11/15 11:18:46
nice! Will do.
| |
| 84 call_hg(nightlydir, 'bookmark', 'safari') | |
| 85 hg_import(nightlydir, diff_dir, 'adblockplusnightly') | |
| 76 | 86 |
| 77 # Mock the downloads repository. | 87 # Mock the downloads repository. |
| 78 downloads_list = data_dir.join('downloads.list').read().splitlines() | 88 downloads_list = data_dir.join('downloads.list').read().splitlines() |
|
Vasily Kuznetsov
2016/11/14 19:42:38
The downloads repo could also be imported from the
Jon Sonesen
2016/11/15 11:18:46
Ack.
| |
| 79 downloads_dir = hg_dir.mkdir('downloads') | 89 downloads_dir = hg_dir.mkdir('downloads') |
| 80 call_hg(downloads_dir, 'init') | 90 call_hg(downloads_dir, 'init') |
| 91 | |
| 81 for item in downloads_list: | 92 for item in downloads_list: |
| 82 downloads_dir.join(item).write('') | 93 downloads_dir.join(item).write('') |
| 83 call_hg(downloads_dir, 'add', *downloads_list) | 94 call_hg(downloads_dir, 'add', *downloads_list) |
| 84 call_hg(downloads_dir, 'commit', '-m', 'ok') | 95 call_hg(downloads_dir, 'commit', '-m', 'ok') |
| 85 | 96 |
| 86 return hg_dir | 97 return hg_dir |
| 87 | 98 |
| 88 | 99 |
| 100 @pytest.fixture(scope='session') | |
|
Vasily Kuznetsov
2016/11/14 19:42:38
This fixture is only used by `test_createNightlies
Jon Sonesen
2016/11/15 11:18:46
Agreed.
| |
| 101 def nightlydir(hg_dir): | |
| 102 return hg_dir.join('adblockplusnightly') | |
| 103 | |
| 104 | |
| 89 @pytest.fixture() | 105 @pytest.fixture() |
| 90 def config_ini(tests_dir, tmpdir, hg_dir, keys_dir): | 106 def config_ini(tests_dir, tmpdir, hg_dir, keys_dir): |
| 91 """Sitescripts configuration.""" | 107 """Sitescripts configuration.""" |
| 92 template = tests_dir.join('sitescripts.ini.template').read() | 108 template = tests_dir.join('sitescripts.ini.template').read() |
| 93 conf = template.format(hg_dir=hg_dir, out_dir=tmpdir, keys_dir=keys_dir) | 109 conf = template.format(hg_dir=hg_dir, out_dir=tmpdir, keys_dir=keys_dir) |
| 94 config_ini = tmpdir.join('sitescripts.ini') | 110 config_ini = tmpdir.join('sitescripts.ini') |
| 95 config_ini.write(conf) | 111 config_ini.write(conf) |
| 96 return config_ini | 112 return config_ini |
| OLD | NEW |