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

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

Issue 29361729: Issue 4574 - Adds Tests to createNightlies platform specific revisions (Closed)
Patch Set: Created Nov. 4, 2016, 2:37 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
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
(...skipping 27 matching lines...) Expand all
38 38
39 39
40 @pytest.fixture(scope='session') 40 @pytest.fixture(scope='session')
41 def data_dir(tests_dir): 41 def data_dir(tests_dir):
42 return tests_dir.join('data') 42 return tests_dir.join('data')
43 43
44 44
45 # 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
46 # 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
47 # which is session scoped but for no it is not important. 47 # which is session scoped but for no it is not important.
48 @pytest.fixture() 48 @pytest.fixture(scope='session')
49 def keys_dir(tmpdir, tests_dir): 49 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.mkdir('keys') 50 keys_dir = tmpdir_factory.mktemp('keys')
51 key_filename = 'adblockplussafari.pem' 51 key_filename = 'adblockplussafari.pem'
52 tests_dir.join(key_filename).copy(keys_dir.join(key_filename)) 52 tests_dir.join(key_filename).copy(keys_dir.join(key_filename))
53 return keys_dir 53 return keys_dir
54 54
55 55
56 def call_hg(cwd, *params): 56 def call_hg(cwd, *params):
57 return subprocess.check_call(['hg'] + list(params), cwd=str(cwd)) 57 return subprocess.check_call(['hg'] + list(params), cwd=str(cwd))
58 58
59 59
60 @pytest.fixture() 60 @pytest.fixture(scope='session')
61 def hg_dir(tmpdir, data_dir): 61 def hg_dir(tmpdir_factory, data_dir):
62 """Directory that contains the repository mocks.""" 62 """Directory that contains the repository mocks."""
63 hg_dir = tmpdir.mkdir('hg') 63 hg_dir = tmpdir_factory.mktemp('hg')
64 64
65 # Mock plugin repositories. 65 # Mock plugin repositories.
66 for repo, config in REPOS.items(): 66 for repo, config in REPOS.items():
67 filename, tag = config 67 filename, tag = config
68 repo_dir = hg_dir.mkdir(repo) 68 repo_dir = hg_dir.mkdir(repo)
69 call_hg(repo_dir, 'init') 69 call_hg(repo_dir, 'init')
70 data_dir.join(filename).copy(repo_dir.join(filename)) 70 data_dir.join(filename).copy(repo_dir.join(filename))
71 call_hg(repo_dir, 'add', filename) 71 call_hg(repo_dir, 'add', filename)
72 call_hg(repo_dir, 'commit', '-m', '1') 72 call_hg(repo_dir, 'commit', '-m', '1')
73 call_hg(repo_dir, 'tag', tag) 73 call_hg(repo_dir, 'tag', tag)
74 74
75 call_hg(hg_dir.join('adblockplusnightly'), 'bookmark', 'master')
75 call_hg(hg_dir.join('adblockplusnightly'), 'bookmark', 'safari') 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.
76 81
77 # Mock the downloads repository. 82 # Mock the downloads repository.
78 downloads_list = data_dir.join('downloads.list').read().splitlines() 83 downloads_list = data_dir.join('downloads.list').read().splitlines()
79 downloads_dir = hg_dir.mkdir('downloads') 84 downloads_dir = hg_dir.mkdir('downloads')
80 call_hg(downloads_dir, 'init') 85 call_hg(downloads_dir, 'init')
81 for item in downloads_list: 86 for item in downloads_list:
82 downloads_dir.join(item).write('') 87 downloads_dir.join(item).write('')
83 call_hg(downloads_dir, 'add', *downloads_list) 88 call_hg(downloads_dir, 'add', *downloads_list)
84 call_hg(downloads_dir, 'commit', '-m', 'ok') 89 call_hg(downloads_dir, 'commit', '-m', 'ok')
85 90
86 return hg_dir 91 return hg_dir
87 92
88 93
94 @pytest.fixture(scope='session')
95 def nightly_dir(hg_dir):
96 return hg_dir.join('adblockplusnightly')
97
98
89 @pytest.fixture() 99 @pytest.fixture()
90 def config_ini(tests_dir, tmpdir, hg_dir, keys_dir): 100 def config_ini(tests_dir, tmpdir, hg_dir, keys_dir):
91 """Sitescripts configuration.""" 101 """Sitescripts configuration."""
92 template = tests_dir.join('sitescripts.ini.template').read() 102 template = tests_dir.join('sitescripts.ini.template').read()
93 conf = template.format(hg_dir=hg_dir, out_dir=tmpdir, keys_dir=keys_dir) 103 conf = template.format(hg_dir=hg_dir, out_dir=tmpdir, keys_dir=keys_dir)
94 config_ini = tmpdir.join('sitescripts.ini') 104 config_ini = tmpdir.join('sitescripts.ini')
95 config_ini.write(conf) 105 config_ini.write(conf)
96 return config_ini 106 return config_ini
OLDNEW

Powered by Google App Engine
This is Rietveld