Revision control

1
import io
2
import json
3
import os
4
import time
5
6
from mozdownload import DirectScraper, FactoryScraper
7
from mozprofile import Profile
8
import mozinstall
9
import mozversion
10
import pytest
11
import requests
12
13
from .tps import TPS
14
from .xcodebuild import XCodeBuild
15
16
here = os.path.dirname(__file__)
17
18
19
@pytest.fixture(scope='session')
20
def firefox(pytestconfig, tmpdir_factory):
21
binary = os.getenv('MOZREGRESSION_BINARY',
22
pytestconfig.getoption('firefox'))
23
if binary is None:
24
cache_dir = str(pytestconfig.cache.makedir('firefox'))
25
scraper = FactoryScraper('daily', destination=cache_dir)
26
build_path = scraper.download()
27
install_path = str(tmpdir_factory.mktemp('firefox'))
28
install_dir = mozinstall.install(src=build_path, dest=install_path)
29
binary = mozinstall.get_binary(install_dir, 'firefox')
30
version = mozversion.get_version(binary)
31
if hasattr(pytestconfig, '_metadata'):
32
pytestconfig._metadata.update(version)
33
return binary
34
35
36
@pytest.fixture
37
def firefox_log(pytestconfig, tmpdir):
38
firefox_log = str(tmpdir.join('firefox.log'))
39
pytestconfig._firefox_log = firefox_log
40
yield firefox_log
41
42
43
@pytest.fixture(scope='session')
44
def tps_addon(pytestconfig, tmpdir_factory):
45
path = pytestconfig.getoption('tps')
46
if path is not None:
47
return path
49
'gecko.v2.mozilla-central.latest.firefox.addons.tps'
50
task_id = requests.get(task_url).json().get('taskId')
51
cache_dir = str(pytestconfig.cache.makedir('tps-{}'.format(task_id)))
53
'{}/artifacts/public/tps.xpi'.format(task_id)
54
scraper = DirectScraper(addon_url, destination=cache_dir)
55
return scraper.download()
56
57
58
@pytest.fixture
59
def tps_config(fxa_account):
60
yield {'fx_account': {
61
'username': fxa_account.email,
62
'password': fxa_account.password}}
63
64
65
@pytest.fixture
66
def tps_log(pytestconfig, tmpdir):
67
tps_log = str(tmpdir.join('tps.log'))
68
pytestconfig._tps_log = tps_log
69
yield tps_log
70
71
72
@pytest.fixture
73
def tps_profile(pytestconfig, tps_addon, tps_config, tps_log, fxa_urls):
74
preferences = {
75
'app.update.enabled': False,
76
'browser.dom.window.dump.enabled': True,
77
'browser.onboarding.enabled': False,
78
'browser.sessionstore.resume_from_crash': False,
79
'browser.shell.checkDefaultBrowser': False,
80
'browser.startup.homepage_override.mstone': 'ignore',
81
'browser.startup.page': 0,
82
'browser.tabs.warnOnClose': False,
83
'browser.warnOnQuit': False,
84
'datareporting.policy.dataSubmissionEnabled': False,
85
# 'devtools.chrome.enabled': True,
86
# 'devtools.debugger.remote-enabled': True,
87
'engine.bookmarks.repair.enabled': False,
88
'extensions.autoDisableScopes': 10,
89
'extensions.legacy.enabled': True,
90
'extensions.update.enabled': False,
91
'extensions.update.notifyUser': False,
92
'identity.fxaccounts.autoconfig.uri': fxa_urls['content'],
93
'testing.tps.skipPingValidation': True,
94
'services.sync.firstSync': 'notReady',
95
'services.sync.lastversion': '1.0',
96
'services.sync.log.appender.console': 'Trace',
97
'services.sync.log.appender.dump': 'Trace',
98
'services.sync.log.appender.file.level': 'Trace',
99
'services.sync.log.appender.file.logOnSuccess': True,
100
'services.sync.log.logger': 'Trace',
101
'services.sync.log.logger.engine': 'Trace',
102
'services.sync.testing.tps': True,
103
'testing.tps.logFile': tps_log,
104
'toolkit.startup.max_resumed_crashes': -1,
105
'tps.config': json.dumps(tps_config),
106
'tps.seconds_since_epoch': int(time.time()),
107
'xpinstall.signatures.required': False
108
}
109
profile = Profile(addons=[tps_addon], preferences=preferences)
110
pytestconfig._profile = profile.profile
111
yield profile
112
113
114
@pytest.fixture
115
def tps(firefox, firefox_log, monkeypatch, pytestconfig, tps_log, tps_profile):
116
yield TPS(firefox, firefox_log, tps_log, tps_profile)
117
118
119
@pytest.fixture
120
def xcodebuild_log(pytestconfig, tmpdir):
121
xcodebuild_log = str(tmpdir.join('xcodebuild.log'))
122
pytestconfig._xcodebuild_log = xcodebuild_log
123
yield xcodebuild_log
124
125
126
@pytest.fixture
127
def xcodebuild(fxa_account, monkeypatch, xcodebuild_log):
128
monkeypatch.setenv('FXA_EMAIL', fxa_account.email)
129
monkeypatch.setenv('FXA_PASSWORD', fxa_account.password)
130
yield XCodeBuild(xcodebuild_log)
131
132
133
def pytest_addoption(parser):
134
parser.addoption('--firefox', help='path to firefox binary (defaults to '
135
'downloading latest nightly build)')
136
parser.addoption('--tps', help='path to tps add-on (defaults to '
137
'downloading latest nightly build)')
138
139
140
@pytest.mark.hookwrapper
141
def pytest_runtest_makereport(item, call):
142
outcome = yield
143
report = outcome.get_result()
144
extra = getattr(report, 'extra', [])
145
pytest_html = item.config.pluginmanager.getplugin('html')
146
profile = getattr(item.config, '_profile', None)
147
if profile is not None and os.path.exists(profile):
148
# add sync logs to HTML report
149
for root, _, files in os.walk(os.path.join(profile, 'weave', 'logs')):
150
for f in files:
151
path = os.path.join(root, f)
152
if pytest_html is not None:
153
with io.open(path, 'r', encoding='utf8') as f:
154
extra.append(pytest_html.extras.text(f.read(), 'Sync'))
155
report.sections.append(('Sync', 'Log: {}'.format(path)))
156
for log in ('Firefox', 'TPS', 'XCodeBuild'):
157
attr = '_{}_log'.format(log.lower())
158
path = getattr(item.config, attr, None)
159
if path is not None and os.path.exists(path):
160
if pytest_html is not None:
161
with io.open(path, 'r', encoding='utf8') as f:
162
extra.append(pytest_html.extras.text(f.read(), log))
163
report.sections.append((log, 'Log: {}'.format(path)))
164
report.extra = extra