buildframework/helium/tools/common/testing.ant.xml
changeset 640 ac0bbc1e5d79
parent 628 7c4a911dc066
child 645 b8d81fa19e7d
equal deleted inserted replaced
639:0e65f93be3cb 640:ac0bbc1e5d79
    25     <description>
    25     <description>
    26         Targets to test Helium itself.
    26         Targets to test Helium itself.
    27     </description>
    27     </description>
    28     
    28     
    29     <!-- Runs all the unit testing targets. -->
    29     <!-- Runs all the unit testing targets. -->
    30     <target name="unittest" depends="ant-unittest,py-unittest"/>
    30     <target name="unittest" depends="ant-unittest"/>
    31     
       
    32     <!-- Unit testing -->
       
    33 
       
    34     <!-- Setup environment for Python unit tests. -->
       
    35     <target name="setup-py-unittest">
       
    36         <!-- Autogenerate test data for ArchivePreBuilderTest based on ANT properties -->
       
    37         <if>
       
    38             <available file="${helium.dir}/tests/data/archive_test.cfg.xml"/>
       
    39             <then>
       
    40                 <delete file="${helium.dir}/tests/data/archive_test.cfg.xml"/>
       
    41             </then>
       
    42         </if>
       
    43         <copy file="${helium.dir}/tests/data/archive_test_input.cfg.xml" tofile="${helium.dir}/tests/data/archive_test.cfg.xml" overwrite="true">
       
    44             <filterchain>
       
    45                 <expandproperties/>
       
    46             </filterchain>
       
    47         </copy>
       
    48     </target>
       
    49 
       
    50     <!-- Do Python tests. -->
       
    51     <target name="do-py-unittest" depends="setup-py-unittest">
       
    52         <property name="nose.args" value="nokiacpythontest scripttests"/>
       
    53         <exec executable="python" failonerror="true">
       
    54             <env key="TEST_DATA" value="${helium.dir}/tests"/>
       
    55             <arg line="${python.tools}/coverage.py -x ${python.tools}/nosetests-script.py -v ${nose.args}"/>
       
    56         </exec>
       
    57         <script language="jython" setbeans="false">
       
    58 import sys
       
    59 import os
       
    60 os.putenv('TEST_DATA', os.path.join(os.environ['HELIUM_HOME'], 'tests'))
       
    61 sys.path.append(os.path.join(os.environ['HELIUM_HOME'], 'external/python/lib/common/nose-0.11.1-py2.6.egg'))
       
    62 sys.path.append(os.path.join(os.environ['HELIUM_HOME'], 'external/python/lib/common/mocker-0.10.1-py2.5.egg'))
       
    63 import nose
       
    64 args = project.getProperty('nose.args')
       
    65 if ' ' in args:
       
    66     nose.run(argv=['-v', 'scripttests'])
       
    67 elif 'cpython' not in args:
       
    68     nose.run(argv=['-v', args])
       
    69 print >> sys.stderr
       
    70         </script>
       
    71     </target>
       
    72     
       
    73     <!-- Shortcut for Python unit tests. -->
       
    74     <target name="pt" depends="do-py-unittest"/>
       
    75     
       
    76         
    31         
    77     <!-- Create Python code coverage statistics. -->
       
    78     <target name="py-unittest-coverage">
       
    79         <mkdir dir="${helium.build.dir}/coverage"/>
       
    80         <pathconvert pathsep=" " property="python.modules.coverage">
       
    81             <fileset dir="${helium.dir}">
       
    82                 <include name="tools/**/*.py"/>
       
    83                 <include name="extensions/nokia/tools/**/*.py"/>
       
    84                 <exclude name="tools/startup/bootstrap/site.py"/>
       
    85             </fileset>
       
    86         </pathconvert>
       
    87         <exec executable="python" failonerror="true">
       
    88             <arg line="${python.tools}/coverage.py -a -d ${helium.build.dir}/coverage ${python.modules.coverage}"/>
       
    89         </exec>
       
    90                         
       
    91         <!-- backup the old line coverage report and create the new one -->
       
    92         <mkdir dir="${helium.build.dir}/coverage/report"/>        
       
    93         <if>
       
    94             <available file="${helium.build.dir}/coverage/report/line_coverage.txt"/>
       
    95             <then>
       
    96                 <copy file="${helium.build.dir}/coverage/report/line_coverage.txt" tofile="${helium.build.dir}/coverage/report/line_coverage_old.txt" overwrite="true"/>
       
    97             </then>    
       
    98         </if>        
       
    99         <hlm:record name="${helium.build.dir}/coverage/report/line_coverage.txt" action="start"/>        
       
   100         <exec executable="python" failonerror="true">
       
   101             <arg line="${python.tools}/coverage.py -r ${python.modules.coverage}"/>
       
   102         </exec>
       
   103         <hlm:record name="${helium.build.dir}/coverage/report/line_coverage.txt" action="stop"/>
       
   104         <replace file="${helium.build.dir}/coverage/report/line_coverage.txt">
       
   105             <replacetoken><![CDATA[[exec]]]></replacetoken>
       
   106             <replacevalue><![CDATA[]]></replacevalue>
       
   107         </replace>
       
   108         <hlm:python>
       
   109 for line in open(r'${helium.build.dir}/coverage/report/line_coverage.txt'):
       
   110     if 'TOTAL' in line and ' 0%' in line:
       
   111         raise Exception('Coverage at 0%')
       
   112         </hlm:python>
       
   113         <delete file="${helium.dir}/.coverage"/>
       
   114     </target>
       
   115     
       
   116     
       
   117     <!-- Run Python unit test cases. -->
       
   118     <target name="py-unittest" depends="do-py-unittest,py-unittest-coverage"/>
       
   119         
       
   120     
       
   121     <!-- Run Ant unit tests. -->
    32     <!-- Run Ant unit tests. -->
   122     <target name="ant-unittest">
    33     <target name="ant-unittest">
   123         <mkdir dir="${helium.build.dir}/temp"/>
    34         <mkdir dir="${helium.build.dir}/temp"/>
   124         <mkdir dir="${helium.build.dir}/report/antunit"/>
    35         <mkdir dir="${helium.build.dir}/report/antunit"/>
   125         <au:antunit>
    36         <au:antunit>
   126             <propertyset>
    37             <propertyset>
   127                 <propertyref name="cache.dir"/>
    38                 <propertyref name="cache.dir"/>
   128                 <propertyref name="synergy71.enabled"/>
    39                 <propertyref name="synergy71.enabled"/>
   129             </propertyset>
    40             </propertyset>
   130             <fileset dir="${helium.dir}" includes="tools/**/test_*.ant.xml"/> 
    41             <fileset dir="${helium.dir}" includes="tools/**/test_*.ant.xml"/> 
   131             <fileset dir="${helium.dir}" includes="extensions/nokia/tools/**/test_*.ant.xml"/> 
    42             <fileset dir="${helium.dir}" includes="extensions/*/tools/**/test_*.ant.xml"/>  
   132             <au:plainlistener/>
    43             <au:plainlistener/>
   133             <hlm:antcoveragelistener outputfile="${helium.build.dir}/report/antunit/ant_coverage.txt"/>
    44             <hlm:antcoveragelistener outputfile="${helium.build.dir}/report/antunit/ant_coverage.txt"/>
   134             <au:xmllistener toDir="${helium.build.dir}/report/antunit" logLevel="info" />
    45             <au:xmllistener toDir="${helium.build.dir}/report/antunit" logLevel="info" />
   135         </au:antunit>
    46         </au:antunit>
   136     </target>
    47     </target>