587
|
1 |
<?xml version="1.0"?>
|
|
2 |
<!--
|
|
3 |
============================================================================
|
|
4 |
Name : build.xml
|
|
5 |
Part of : Helium AntLib
|
|
6 |
|
|
7 |
Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
8 |
All rights reserved.
|
|
9 |
This component and the accompanying materials are made available
|
|
10 |
under the terms of the License "Eclipse Public License v1.0"
|
|
11 |
which accompanies this distribution, and is available
|
|
12 |
at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
13 |
|
|
14 |
Initial Contributors:
|
|
15 |
Nokia Corporation - initial contribution.
|
|
16 |
|
|
17 |
Contributors:
|
|
18 |
|
|
19 |
Description:
|
|
20 |
|
|
21 |
============================================================================
|
|
22 |
-->
|
|
23 |
<project name="test-macros" xmlns:ac="antlib:net.sf.antcontrib">
|
|
24 |
<import file="../java/common.ant.xml" />
|
|
25 |
<dirname property="python.builder.dir" file="${ant.file.test-macros}" />
|
|
26 |
|
|
27 |
<target name="unittest" depends="pt,pt-coverage"/>
|
|
28 |
|
|
29 |
<target name="pt">
|
|
30 |
<pathconvert pathsep=":" property="python.path">
|
|
31 |
<fileset dir="${python.builder.dir}/lib" includes="**/*.egg" excludes="jython*"/>
|
|
32 |
<fileset dir="${lib.dir}" includes="**/*.egg"/>
|
|
33 |
<dirset dir="${lib.dir}"/>
|
|
34 |
<fileset dir="${module.bin.dir}" includes="**/${ant.project.name}*.egg"/>
|
|
35 |
<dirset dir="${basedir}/lib"/>
|
|
36 |
</pathconvert>
|
|
37 |
<pathconvert pathsep=" " property="python.modules.coverage">
|
|
38 |
<fileset dir="${basedir}" includes="**/*.py"/>
|
|
39 |
</pathconvert>
|
|
40 |
<!---->
|
|
41 |
<mkdir dir="${junit.result.dir}" />
|
|
42 |
<ac:trycatch property="cpython.unittest.error">
|
|
43 |
<try>
|
|
44 |
<exec executable="python" failonerror="true" dir="${lib.dir}">
|
|
45 |
<env key="PYTHONPATH" path="${python.path}" />
|
|
46 |
<arg line="${python.builder.dir}/lib/coverage.py -x ${python.builder.dir}/lib/nosetests-script.py --exe -v --with-xunit --xunit-file=${junit.result.dir}/python.xml"/>
|
|
47 |
<arg line="${nose.args}" />
|
|
48 |
</exec>
|
|
49 |
</try>
|
|
50 |
</ac:trycatch>
|
|
51 |
<ac:trycatch property="jython.unittest.error">
|
|
52 |
<try>
|
|
53 |
<script language="jython" setbeans="false">
|
|
54 |
<![CDATA[
|
|
55 |
import sys
|
|
56 |
import os
|
|
57 |
import shutil
|
|
58 |
for p in project.getProperty('python.path').split(':'):
|
|
59 |
if 'amara' not in p:
|
|
60 |
sys.path.append(p)
|
|
61 |
os.chdir(project.getProperty('lib.dir'))
|
|
62 |
if os.path.exists('build'):
|
|
63 |
shutil.rmtree('build')
|
|
64 |
import nose
|
|
65 |
args = project.getProperty('nose.args')
|
|
66 |
args2 = "--with-xunit --xunit-file=" + project.getProperty('junit.result.dir') + "/jython.xml" + args
|
|
67 |
testdir = os.path.join(project.getProperty('basedir'), 'lib', project.getProperty('ant.project.name'))
|
|
68 |
|
|
69 |
result = True
|
|
70 |
if ' ' in args:
|
|
71 |
result = nose.run(argv=['-v', testdir + 'tests'])
|
|
72 |
elif 'cpython' not in args:
|
|
73 |
result = nose.run(argv=['-v', args2])
|
|
74 |
print >> sys.stderr
|
|
75 |
if not result:
|
|
76 |
raise Exception('Jython unittest failure.')
|
|
77 |
]]>
|
|
78 |
</script>
|
|
79 |
</try>
|
|
80 |
</ac:trycatch>
|
|
81 |
<delete includeemptydirs="true">
|
|
82 |
<fileset dir="${basedir}/lib" includes="*.egg-info/"/>
|
|
83 |
</delete>
|
|
84 |
<ac:if>
|
|
85 |
<isset property="jython.unittest.error" />
|
|
86 |
<then>
|
|
87 |
<fail message="${jython.unittest.error}" />
|
|
88 |
</then>
|
|
89 |
</ac:if>
|
|
90 |
<ac:if>
|
|
91 |
<isset property="cpython.unittest.error" />
|
|
92 |
<then>
|
|
93 |
<fail message="${cpython.unittest.error}" />
|
|
94 |
</then>
|
|
95 |
</ac:if>
|
|
96 |
</target>
|
|
97 |
|
|
98 |
<target name="pt-coverage">
|
|
99 |
<mkdir dir="${lib.dir}/../coverage"/>
|
|
100 |
<exec executable="python" failonerror="true" dir="${lib.dir}">
|
|
101 |
<env key="PYTHONPATH" path="${python.path}" />
|
|
102 |
<arg line="${python.builder.dir}/lib/coverage.py -a -d ${lib.dir}/../coverage ${python.modules.coverage}"/>
|
|
103 |
</exec>
|
|
104 |
|
|
105 |
<mkdir dir="${lib.dir}/../coverage/report"/>
|
|
106 |
<move file="${lib.dir}/../coverage/report/line_coverage.txt" tofile="${lib.dir}/../coverage/report/line_coverage_old.txt" overwrite="true" failonerror="false"/>
|
|
107 |
<record name="${lib.dir}/../coverage/report/line_coverage.txt" action="start"/>
|
|
108 |
<exec executable="python" failonerror="true" dir="${lib.dir}">
|
|
109 |
<env key="PYTHONPATH" path="${python.path}" />
|
|
110 |
<arg line="${python.builder.dir}/lib/coverage.py -r ${python.modules.coverage}"/>
|
|
111 |
</exec>
|
|
112 |
<record name="${lib.dir}/../coverage/report/line_coverage.txt" action="stop"/>
|
|
113 |
|
|
114 |
<script language="jython" setbeans="false">
|
|
115 |
for line in open(project.getProperty('lib.dir') + r'/../coverage/report/line_coverage.txt'):
|
|
116 |
if 'TOTAL' in line and ' 0%' in line:
|
|
117 |
raise Exception('Coverage at 0%')
|
|
118 |
</script>
|
|
119 |
<delete file="${basedir}/.coverage"/>
|
|
120 |
</target>
|
|
121 |
|
|
122 |
</project>
|