-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.py
149 lines (117 loc) · 4.49 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import logging
import os
import subprocess
import quibble
from quibble.gitchangedinhead import GitChangedInHead
def run_composer_test(mwdir):
log = logging.getLogger('test.run_composer_test')
files = []
changed = GitChangedInHead([], cwd=mwdir).changedFiles()
if 'composer.json' in changed or '.phpcs.xml' in changed:
log.info(
'composer.json or .phpcs.xml changed: linting "."')
# '.' is passed to composer lint which then pass it
# to parallel-lint and phpcs
files = ['.']
else:
files = GitChangedInHead(
['php', 'php5', 'inc', 'sample'],
cwd=mwdir
).changedFiles()
if not files:
log.info('Skipping composer test (unneeded)')
else:
log.info("Running composer test")
env = {'COMPOSER_PROCESS_TIMEOUT': '900'}
env.update(os.environ)
composer_test_cmd = ['composer', 'test']
composer_test_cmd.extend(files)
subprocess.check_call(composer_test_cmd, cwd=mwdir, env=env)
def run_npm_test(mwdir):
log = logging.getLogger('test.run_npm_test')
log.info("Running npm test")
subprocess.check_call(['npm', 'test'], cwd=mwdir, env=os.environ)
def run_qunit(mwdir, port=9412):
karma_env = {
'CHROME_BIN': '/usr/bin/chromium',
'MW_SERVER': 'http://127.0.0.1:%s' % port,
'MW_SCRIPT_PATH': '/',
'FORCE_COLOR': '1', # for 'supports-color'
}
karma_env.update(os.environ)
karma_env.update({'CHROMIUM_FLAGS': quibble.chromium_flags()})
subprocess.check_call(
['./node_modules/.bin/grunt', 'qunit'],
cwd=mwdir,
env=karma_env,
)
def run_extskin(directory, composer=True, npm=True):
log = logging.getLogger('test.run_extskin')
project_name = os.path.basename(directory)
if composer:
if not os.path.exists(os.path.join(directory, 'composer.json')):
log.warning("%s lacks a composer.json" % project_name)
else:
log.info('Running "composer test" for %s' % project_name)
cmds = [
['composer', '--ansi', 'validate', '--no-check-publish'],
['composer', '--ansi', 'install', '--no-progress',
'--prefer-dist', '--profile', '-v'],
['composer', '--ansi', 'test'],
]
for cmd in cmds:
subprocess.check_call(cmd, cwd=directory, env=os.environ)
if npm:
# XXX copy paste is terrible
if not os.path.exists(os.path.join(directory, 'package.json')):
log.warning("%s lacks a package.json" % project_name)
else:
log.info('Running "npm test" for %s' % project_name)
cmds = [
['npm', 'prune'],
['npm', 'install', '--no-progress'],
['npm', 'test'],
]
for cmd in cmds:
subprocess.check_call(cmd, cwd=directory, env=os.environ)
log.info('%s: git clean -xqdf' % project_name)
subprocess.check_call(['git', 'clean', '-xqdf'], cwd=directory)
def run_phpunit(mwdir, group=[], exclude_group=[], testsuite=None,
junit_file=None):
log = logging.getLogger('test.run_phpunit')
always_excluded = ['Broken', 'ParserFuzz', 'Stub']
cmd = ['php', 'tests/phpunit/phpunit.php', '--debug-tests']
if testsuite:
cmd.extend(['--testsuite', testsuite])
if group:
cmd.extend(['--group', ','.join(group)])
cmd.extend(['--exclude-group',
','.join(always_excluded + exclude_group)])
if junit_file:
cmd.extend('--log-junit', junit_file)
log.info(' '.join(cmd))
phpunit_env = {}
phpunit_env.update(os.environ)
phpunit_env.update({'LANG': 'C.UTF-8'})
subprocess.check_call(cmd, cwd=mwdir, env=phpunit_env)
def run_phpunit_database(*args, **kwargs):
kwargs['group'] = ['Database']
run_phpunit(*args, **kwargs)
def run_phpunit_databaseless(*args, **kwargs):
kwargs['exclude_group'] = ['Database']
run_phpunit(*args, **kwargs)
def run_webdriver(mwdir, display, port=9412):
webdriver_env = {}
webdriver_env.update(os.environ)
webdriver_env.update({
'MW_SERVER': 'http://127.0.0.1:%s' % port,
'MW_SCRIPT_PATH': '/',
'FORCE_COLOR': '1', # for 'supports-color'
'MEDIAWIKI_USER': 'WikiAdmin',
'MEDIAWIKI_PASSWORD': 'testpass',
'DISPLAY': display,
})
subprocess.check_call([
'npm', 'run', 'selenium-test'],
cwd=mwdir,
env=webdriver_env)