Revision: 5a22f4e91eb6
Author: Pekka Klärck
Date: Wed Nov 30 14:45:46 2011
Log: Tests for writing statistics into log/report correctly.
http://code.google.com/p/robotframework/source/detail?r=5a22f4e91eb6
Added:
/atest/robot/output/html_output_stats.py
/atest/robot/output/statistics_in_log_and_report.txt
=======================================
--- /dev/null
+++ /atest/robot/output/html_output_stats.py Wed Nov 30 14:45:46 2011
@@ -0,0 +1,37 @@
+from robot.api import logger
+
+
+def get_total_stats(path):
+ return get_all_stats(path)[0]
+
+def get_tag_stats(path):
+ return get_all_stats(path)[1]
+
+def get_suite_stats(path):
+ return get_all_stats(path)[2]
+
+def get_all_stats(path):
+ logger.info('Getting stats from <a href="file://%s">%s</a>' % (path,
path),
+ html=True)
+ stats_line = _get_stats_line(path)
+ logger.debug('Stats line: %s' % stats_line)
+ total, tags, suite = eval(stats_line)
+ return total, tags, suite
+
+def _get_stats_line(path):
+ prefix = 'window.output["stats"] = '
+ with open(path) as file:
+ for line in file:
+ if line.startswith(prefix):
+ return line[len(prefix):-2]
+
+def verify_stat(stat, *attrs):
+ expected = dict(_get_expected_stat(attrs))
+ if stat != expected:
+ raise AssertionError('Wrong stat!\nGot: %s\nExpected: %s'
+ % (stat, expected))
+
+def _get_expected_stat(attrs):
+ for key, value in (a.split(':', 1) for a in attrs):
+ value = int(value) if value.isdigit() else str(value)
+ yield str(key), value
=======================================
--- /dev/null
+++ /atest/robot/output/statistics_in_log_and_report.txt Wed Nov 30
14:45:46 2011
@@ -0,0 +1,81 @@
+*** Settings ***
+Documentation Verify that stat information is written correctly to
log/report
+Force Tags regression pybot jybot
+Resource atest_resource.txt
+Library html_output_stats.py
+Suite Setup Run tests with stat related options
+
+*** Test Cases ***
+
+Log contains total stats
+ Verify total stats log.html
+
+Report contains total stats
+ Verify total stats report.html
+
+Log contains tag stats
+ Verify tag stats log.html
+
+Report contains tag stats
+ Verify tag stats report.html
+
+Log contains suite stats
+ Verify suite stats log.html
+
+Report contains suite stats
+ Verify suite stats report.html
+
+
+*** Keywords ***
+
+Run tests with stat related options
+ ${opts} = Catenate
+ ... --Critical t1
+ ... --NonCritical t2
+ ... --SuiteStatLevel 2
+ ... --TagStatInclude t?
+ ... --TagStatInclude d1
+ ... --TagStatCombine f1ANDt1
+ ... --TagDoc t1:the_doc
+ ... --TagStatLink t?:http://t/%1:T%1
+ ... --log log.html
+ ... --report report.html
+ Run tests ${opts} misc/suites
+
+Verify total stats
+ [Arguments] ${file}
+ ${critical} ${all} = Get Total Stats ${OUTDIR}${/}${file}
+ Verify stat ${critical} label:Critical Tests pass:5 fail:1
+ Verify stat ${all} label:All Tests pass:9 fail:1
+
+Verify tag stats
+ [Arguments] ${file}
+ ${stats} = Get Tag Stats ${OUTDIR}${/}${file}
+ Length Should Be ${stats} 4
+ Verify stat ${stats[0]} label:t1 pass:5 fail:1
+ ... info:critical links:T1:http://t/1 doc:the doc combined:
+ Verify stat ${stats[1]} label:t2 pass:2 fail:0
+ ... info:non-critical links:T2:http://t/2 doc: combined:
+ Verify stat ${stats[2]} label:f1 & t1 pass:5 fail:1
+ ... info:combined links: doc: combined:f1 & t1
+ Verify stat ${stats[3]} label:d1 pass:1 fail:0
+ ... info: links: doc: combined:
+
+Verify suite stats
+ [Arguments] ${file}
+ ${stats} = Get Suite Stats ${OUTDIR}${/}${file}
+ Length Should Be ${stats} 7
+ Verify stat ${stats[0]} label:Suites name:Suites
+ ... id:s1 pass:9 fail:1
+ Verify stat ${stats[1]} label:Suites.Fourth name:Fourth
+ ... id:s1-s1 pass:0 fail:1
+ Verify stat ${stats[2]} label:Suites.Subsuites name:Subsuites
+ ... id:s1-s2 pass:2 fail:0
+ Verify stat ${stats[3]} label:Suites.Subsuites2
name:Subsuites2
+ ... id:s1-s3 pass:2 fail:0
+ Verify stat ${stats[4]} label:Suites.Tsuite1 name:Tsuite1
+ ... id:s1-s4 pass:3 fail:0
+ Verify stat ${stats[5]} label:Suites.Tsuite2 name:Tsuite2
+ ... id:s1-s5 pass:1 fail:0
+ Verify stat ${stats[6]} label:Suites.Tsuite3 name:Tsuite3
+ ... id:s1-s6 pass:1 fail:0