forked from 4teamwork/ftw-buildouts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-base.cfg
441 lines (355 loc) · 13 KB
/
test-base.cfg
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
# A buildout base configuration providing zope testrunner setup.
# The buildout basically provides two scripts, usable in test-setup as well
# as in development:
#
# bin/test : Runs the tests of the package (using collective.xmltestreport)
# bin/test-coverage : Runs the tests of the package, generates and opens
# a coverage report.
#
# Usage example:
# [buildout]
# extends =
# https://raw.github.com/4teamwork/ftw-buildouts/master/test-base.cfg
# package-name = my.package
[buildout]
# =====================================================================
# Configuration variables:
package-name =
test-egg = ${buildout:package-name} [tests]
package-directory =
package-namespace = ${buildout:package-name}
# =====================================================================
parts =
test
test-coverage
package-directory
coverage
qunit-runner
qunit
pep8-cfg
pep8
pyflakes
pylint
pylint-rc
zptlint
i18ndude
check-translations
dependencychecker
omelette
# We assume that the buildout directory is the package root (repository root)
# of the package we are testing.
develop = .
results-dir = ${buildout:directory}/parts/testresults
extensions =
buildout.dumppickedversions
lovely.buildouthttp
find-links = http://pypi.4teamwork.ch/
index = http://pypi.4teamwork.ch/simple/
versions = versions
allow-hosts =
pypi.python.org
*.pypi.python.org
*.4teamwork.ch
effbot.org
code.google.com
*.googlecode.com
# bin/test : A script running the tests of the configured package.
[test]
recipe = zc.recipe.egg
eggs =
collective.xmltestreport
${buildout:test-egg}
entry-points = test=collective.xmltestreport.runner:run_internal
arguments = ['-s', '${buildout:package-namespace}', '--exit-with-status', '--auto-color', '--auto-progress', '--xml', '--test-path', '${buildout:directory}']
initialization =
import os
sys.argv[0] = os.path.abspath(sys.argv[0])
test_directory = '${buildout:directory}/parts/test'
if not os.path.exists(test_directory): os.makedirs(test_directory)
os.chdir(test_directory)
# collective.xmltestreport currently returns bad exit codes when installed as it
# is intended. Therefore we manually install it and use run_internal instead of run.
# See https://github.com/collective/collective.xmltestreport/issues/3
#
# recipe = collective.xmltestreport
# eggs = ${buildout:test-egg}
# script = test
# defaults =
# ['-s', '${buildout:package-name}', '--exit-with-status', '--auto-color', '--auto-progress', '--xml']
# bin/coverage : A helper script generating a coverage report.
[coverage]
recipe = zc.recipe.egg
eggs = coverage
initialization =
import os
os.environ['COVERAGE_FILE'] = "${buildout:results-dir}/coverage.data"
# XXX HACK: let coverage exit with a propper exit code.
# See: https://bugs.launchpad.net/zc.buildout/+bug/164629
import coverage
if __name__ == '__main__': sys.exit(coverage.main())
# bin/test-coverage : A script for running the tests with coverage and
# opening the coverage report in the browser.
[test-coverage]
recipe = collective.recipe.template
input = inline:
#!/bin/sh
mkdir -p ${buildout:results-dir}
pkgdir=`${buildout:directory}/bin/package-directory`
bin/coverage erase
if [[ "$1" == "xml" ]]; then
shift
bin/coverage run --branch --source=$pkgdir bin/test $@
result=$?
bin/coverage xml -i --omit="*tests/*.py,*testing.py,*interfaces.py" -o ${buildout:results-dir}/coverage.xml
else
bin/coverage run --branch --source=$pkgdir bin/test $@
result=$?
bin/coverage html -i --omit="*tests/*.py,*testing.py,*interfaces.py" -d ${buildout:results-dir}/coverage/ && open ${buildout:results-dir}/coverage/index.html
fi
exit $result
output = ${buildout:directory}/bin/test-coverage
mode = 755
# bin/package-directory : A script returning the path to the source
# directory. It guesses the package namespace from the package name by
# replacing dots with slashes.
# For packages which use a different namespace as guessable by the package
# name, the path can be set using the ${buildout:package-directory}
# variable (path relative to buildout directory). Example::
# [buildout]
# package-name = MyPackage
# package-directory = scr/my/package/core
[package-directory]
recipe = collective.recipe.template
input = inline:
#!/bin/sh
pkgdir="${buildout:package-directory}"
pkgname="${buildout:package-namespace}"
namepath=`echo $pkgname | sed "s:\.:/:g"`
base="${buildout:directory}"
paths=$(echo "$pkgdir" "$namepath" "src/$namepath" "src/$pkgname/$namepath")
for path in $paths; do
if [ -d "$base/$path" ]; then
if [[ "$1" == "relative" ]]; then
echo "$path"
else
echo "$base/$path"
fi
exit 0
fi
done
exit 1
output = ${buildout:directory}/bin/package-directory
mode = 755
# Downloads a custom qunit runner js for use in PhantomJS generating
# xml test results.
[qunit-runner]
recipe = collective.recipe.shelloutput
source = https://raw.github.com/4teamwork/ftw-buildouts/master/run-qunit.js
target = ${buildout:directory}/parts/qunit/run-qunit.js
commands =
cmd1 = mkdir -p `dirname ${qunit-runner:target}`
cmd2 = curl "${qunit-runner:source}" > "${qunit-runner:target}"
# bin/qunit: runs qunit if PhantomJS is installed
# http://phantomjs.org/
[qunit]
recipe = collective.recipe.template
output = ${buildout:directory}/bin/qunit
mode = 755
input = inline:
#!/bin/sh
buildoutdir="${buildout:directory}"
pkgdir=`$buildoutdir/bin/package-directory`
script=$buildoutdir/parts/qunit/run-qunit.js
reportdir=$buildoutdir/parts/test/testreports
if [[ -z `find $pkgdir -path '*tests/qunit/test*.html'` ]]; then
echo "No qunit tests detected with *tests/qunit/test*.html"
exit 0
fi
if [[ -x $PHANTOMJS ]]; then
browser=$PHANTOMJS
elif [[ `which phantomjs` ]]; then
browser=`which phantomjs`
else
echo "ERROR: phantom js not found in $PHANTOMJS."
echo "http://phantomjs.org/"
exit 0
fi
mkdir -p $reportdir
for path in `find $pkgdir -path '*tests/qunit/test*.html'`; do
echo $path
if [[ "$1" == "xml" ]]; then
reportname=`echo $path | sed -e "s:$buildoutdir/::" -e "s:/:.:g" -e "s:html$::"`
report="$reportdir/$report.xml"
$browser $script $path xml $reportname > $report
else
$browser $script $path text $reportname
fi
echo ""
done
# Downloads the default pep8.cfg.
[pep8-cfg]
recipe = collective.recipe.shelloutput
cfgfile = ${buildout:directory}/parts/pep8/pep8.cfg
cfgurl = https://raw.github.com/4teamwork/ftw-buildouts/master/pep8.cfg
commands =
cmd1 = mkdir -p `dirname ${pep8-cfg:cfgfile}`
cmd2 = curl "${pep8-cfg:cfgurl}" > "${pep8-cfg:cfgfile}"
# bin/pep8 : PEP8 validation of the packages source.
[pep8]
recipe = zc.recipe.egg
eggs = pep8
args = ['--exclude=tests', '--config=${pep8-cfg:cfgfile}']
initialization =
import os
import subprocess
os.chdir("${buildout:directory}")
pkgdir = subprocess.Popen(
'${buildout:directory}/bin/package-directory relative',
shell=True, stdout=subprocess.PIPE).stdout.read().strip()
if '--absolute' in sys.argv: pkgdir = os.path.abspath(pkgdir) ; sys.argv.remove('--absolute')
if len(sys.argv) < 2: sys.argv.extend([pkgdir])
sys.argv.extend(${pep8:args})
# bin/pyflakes : Pyflakes validation of the packages source.
[pyflakes]
recipe = zc.recipe.egg
eggs = pyflakes
entry-points = pyflakes=pyflakes.scripts.pyflakes:main
initialization =
import os
import subprocess
os.chdir("${buildout:directory}")
pkgdir = subprocess.Popen(
'${buildout:directory}/bin/package-directory relative',
shell=True, stdout=subprocess.PIPE).stdout.read().strip()
if len(sys.argv) == 1: sys.argv.extend([pkgdir])
# bin/pylint : Pylint validation of the packages source.
[pylint]
recipe = zc.recipe.egg
eggs =
pylint
${test:eggs}
entry-points = pylint=pylint.lint:Run
initialization =
import os
import subprocess
os.chdir("${buildout:directory}")
pkgdir = subprocess.Popen(
'${buildout:directory}/bin/package-directory relative',
shell=True, stdout=subprocess.PIPE).stdout.read().strip()
arguments = ['--rcfile=${pylint-rc:rcfile}', '--ignore=tests', pkgdir] + sys.argv[1:]
# Downloads the default pylintrc.
[pylint-rc]
recipe = collective.recipe.shelloutput
rcfile = ${buildout:directory}/parts/pylint/pylintrc
rcurl = https://raw.github.com/4teamwork/ftw-buildouts/master/pylintrc
commands =
cmd1 = mkdir -p `dirname ${pylint-rc:rcfile}`
cmd2 = curl "${pylint-rc:rcurl}" > "${pylint-rc:rcfile}"
# bin/ptlint : Zope page tempalte validation.
[zptlint]
recipe = zc.recipe.egg
eggs = zptlint
initialization =
import subprocess
pkgdir = subprocess.Popen(
'${buildout:directory}/bin/package-directory relative',
shell=True, stdout=subprocess.PIPE).stdout.read().strip()
ptfiles = subprocess.Popen(
'find %s -name "*.pt"' % pkgdir,
shell=True, stdout=subprocess.PIPE).stdout.read().strip()
sys.argv.extend(ptfiles and ptfiles.split('\n') or [])
if len(sys.argv) == 1: sys.exit(0)
# bin/i18ndude : Translation tools for ZPT and python scripts.
[i18ndude]
recipe = zc.recipe.egg
eggs = i18ndude
# bin/check-translations : Validates translatable strings and
# provides translation statistics.
[check-translations]
recipe = collective.recipe.template
input = inline:
#!/bin/sh
buildoutdir="${buildout:directory}"
pkgdir=`$buildoutdir/bin/package-directory`
pkgname="${buildout:package-namespace}"
echo ""
echo "===================================================="
echo " Not translatable strings in package templates"
echo "===================================================="
echo ""
$buildoutdir/bin/i18ndude find-untranslated $pkgdir | sed -e '/^Processing/ { N; s/\n//; D; }' -e '/^-*$/ {s/^.*$//;}' -e '/^===/d'
echo ""
echo ""
echo "===================================================="
echo " Translation statistics"
echo "===================================================="
echo ""
tmpdir=$buildoutdir/parts/test-i18n
mkdir -p $tmpdir
domains=`find $pkgdir -name '*.pot' | grep -v '\-manual\.pot' | sed -e 's/.*\/\(.*\).pot$/\1/'`
if [[ "$domains" == "" ]]; then
echo "There are no .pot files."
fi
for domain in $domains; do
rm -f $tmpdir/*
if [[ "$domain" == "$pkgname" ]]; then
echo "i18n domain: $domain (primary)"
# Rebuilding pot file from source since this seems to be the
# primary package domain.
buildargs="--pot $tmpdir/$domain.pot --create $domain"
manualfile=`find $pkgdir -name "$domain-manual.pot"`
if [[ "$manualfile" != "" ]]; then
buildargs="$buildargs --merge $manualfile"
fi
$buildoutdir/bin/i18ndude rebuild-pot $buildargs $pkgdir
else
echo "i18n domain: $domain"
find $pkgdir -name "$domain.pot" -exec cp {} $tmpdir/$domain.pot \;
manualfile=`find $pkgdir -name "$domain-manual.pot"`
if [[ "$manualfile" != "" ]]; then
$buildoutdir/bin/i18ndude merge --pot $tmpdir/$domain.pot --merge $manualfile &> /dev/null
fi
fi
language_pattern="\(en\)"
for pofile in $(find $pkgdir -name "$domain.po"); do
if [[ $pofile =~ /LC_MESSAGES/ ]]; then
lang=`echo $pofile | sed -e 's/.*\/\(.*\)\/LC_MESSAGES.*/\1/'`
tmppofile=$tmpdir/$domain-$lang.po
cp $pofile $tmppofile
language_pattern="$language_pattern|\($lang\)"
if [[ `grep -r '"Language-Code:' $tmppofile` == "" ]]; then
sed -i -e "1,/^$/ { s/^$/\"Language-Code: $lang\\\\n\"/; }" $tmppofile
fi
else
echo "Ignoring file $pofile since LC_MESSAGES could not be found."
fi
done
(cd $tmpdir && $buildoutdir/bin/i18ndude list --products $domain | egrep $language_pattern)
echo ""
done
output = ${buildout:directory}/bin/check-translations
mode = 755
# bin/dependencychecker : checks dependencies
[dependencychecker]
recipe = zc.recipe.egg
eggs =
z3c.dependencychecker
${test:eggs}
initialization =
import os
import subprocess
os.chdir("${buildout:directory}")
pkgdir = subprocess.Popen(
'${buildout:directory}/bin/package-directory relative',
shell=True, stdout=subprocess.PIPE).stdout.read().strip()
sys.argv.extend([pkgdir])
# parts/omlette
[omelette]
recipe = collective.recipe.omelette
eggs =
${test:eggs}
[versions]
# collective.xmltestreport: pinned down because of the z3c.recipe.scripts which results in version conflicts with the zope versions configuration.
collective.xmltestreport = 1.2.6
# selenium 2.26.0 distribute is broken at the moment
selenium = 2.25.0