diff options
29 files changed, 567 insertions, 289 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index f76aa6e..be3e753 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -2,6 +2,15 @@ Change history for Coverage.py
------------------------------
+Version 3.2b3
+-------------
+
+- The table of contents in the HTML report is now sortable. Thanks,
+ `Chris Adams`_.
+
+.. _Chris Adams: http://improbable.org/chris/
+
+
Version 3.2b2, 19 November 2009
-------------------------------
@@ -44,7 +53,8 @@ Version 3.2b1, 10 November 2009 Version 3.1, 4 October 2009
---------------------------
-- Source code can now be read from eggs. Thanks, rozza. Fixes `issue 25`_
+- Source code can now be read from eggs. Thanks, Ross Lawley. Fixes
+ `issue 25`_.
.. _issue 25: http://bitbucket.org/ned/coveragepy/issue/25
@@ -14,6 +14,7 @@ Coverage TODO - Maybe turning off yellow lines should make those lines green?
- A missing branch to leave the function shows an annotation of -1.
- XML report needs to get branch information.
+- Add branch info to "coverage debug data"
* Speed
@@ -88,7 +89,7 @@ x Why can't you specify execute (-x) and report (-r) in the same invocation? - Some way to focus in on red and yellow
- Show only lines near highlights?
- Jump to next highlight?
- - Clickable column headers on the index page.
+ + Clickable column headers on the index page.
+ Syntax coloring in HTML report.
+ Dynamic effects in HTML report.
+ Footer in reports pointing to coverage home page.
@@ -218,6 +219,7 @@ x Tests about the "import __main__" in cmdline.py - $ make pypi
- Visit http://pypi.python.org/pypi?%3Aaction=pkg_edit&name=coverage and show/hide the proper versions.
- Upload kits
+ - Label the source kit with "Use this for either Python 2.x or 3.x "
- Tag the tree
- hg tag -m "Coverage 3.0.1" coverage-3.0.1
- Update nedbatchelder.com
diff --git a/coverage/__init__.py b/coverage/__init__.py index 9f399cb..7deeff5 100644 --- a/coverage/__init__.py +++ b/coverage/__init__.py @@ -5,7 +5,7 @@ http://nedbatchelder.com/code/coverage """ -__version__ = "3.2b2" # see detailed history in CHANGES.txt +__version__ = "3.2b3" # see detailed history in CHANGES.txt __url__ = "http://nedbatchelder.com/code/coverage" diff --git a/coverage/control.py b/coverage/control.py index 23740ca..e041cde 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -319,7 +319,7 @@ class coverage(object): ('cover_prefix', self.cover_prefix), ('pylib_prefix', self.pylib_prefix), ('tracer', self.collector.tracer_name()), - ('data_file', self.data.filename), + ('data_path', self.data.filename), ('python', sys.version.replace('\n', '')), ('platform', platform.platform()), ('cwd', os.getcwd()), diff --git a/coverage/html.py b/coverage/html.py index 8c27472..3877c83 100644 --- a/coverage/html.py +++ b/coverage/html.py @@ -48,14 +48,13 @@ class HtmlReporter(Reporter): self.index_file() # Create the once-per-directory files. - shutil.copyfile( - data_filename("htmlfiles/style.css"), - os.path.join(directory, "style.css") - ) - shutil.copyfile( - data_filename("htmlfiles/jquery-1.3.2.min.js"), - os.path.join(directory, "jquery-1.3.2.min.js") - ) + for static in [ + "style.css", "jquery-1.3.2.min.js", "jquery.tablesorter.min.js" + ]: + shutil.copyfile( + data_filename("htmlfiles/" + static), + os.path.join(directory, static) + ) def html_file(self, cu, analysis): """Generate an HTML file for one source file.""" diff --git a/coverage/htmlfiles/index.html b/coverage/htmlfiles/index.html index 92b8944..faef93b 100644 --- a/coverage/htmlfiles/index.html +++ b/coverage/htmlfiles/index.html @@ -1,67 +1,90 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
-<head>
-<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
-<title>Coverage report</title>
-<link rel='stylesheet' href='style.css' type='text/css'>
-</head>
-<body>
+ <head>
+ <meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
+ <title>Coverage report</title>
+ <link rel='stylesheet' href='style.css' type='text/css'>
+ <script type='text/javascript' src='jquery-1.3.2.min.js'></script>
+ <script type='text/javascript' src='jquery.tablesorter.min.js'></script>
+ </head>
+ <body>
-<div id='header'>
- <div class='content'>
- <h1>Coverage report:
- <span class='pc_cov'>{{totals.pc_covered|format_pct}}%</span>
- </h1>
- </div>
-</div>
+ <div id='header'>
+ <div class='content'>
+ <h1>Coverage report:
+ <span class='pc_cov'>{{totals.pc_covered|format_pct}}%</span>
+ </h1>
+ </div>
+ </div>
-<div id='index'>
-<table class='index'>
-<tr class='tablehead'>
- <th class='name'>Module</th>
- <th>statements</th>
- <th>run</th>
- <th>excluded</th>
- {% if arcs %}
- <th>branches</th>
- <th>br exec</th>
- {% endif %}
- <th>coverage</th>
-</tr>
-{% for file in files %}
-<tr class='file'>
- <td class='name'><a href='{{file.html_filename}}'>{{file.cu.name}}</a></td>
- <td>{{file.nums.n_statements}}</td>
- <td>{{file.nums.n_executed}}</td>
- <td>{{file.nums.n_excluded}}</td>
- {% if arcs %}
- <td>{{file.nums.n_branches}}</td>
- <td>{{file.nums.n_executed_branches}}</td>
- {% endif %}
- <td>{{file.nums.pc_covered|format_pct}}%</td>
-</tr>
-{% endfor %}
-<tr class='total'>
-<td class='name'>Total</td>
-<td>{{totals.n_statements}}</td>
-<td>{{totals.n_executed}}</td>
-<td>{{totals.n_excluded}}</td>
-{% if arcs %}
-<td>{{totals.n_branches}}</td>
-<td>{{totals.n_executed_branches}}</td>
-{% endif %}
-<td>{{totals.pc_covered|format_pct}}%</td>
-</tr>
-</table>
-</div>
+ <div id='index'>
+ <table class='index'>
+ <thead>
+ {# The title='' attr doesn't work in Safari. #}
+ <tr class='tablehead' title='Click to sort'>
+ <th class='name left'>Module</th>
+ <th>statements</th>
+ <th>run</th>
+ <th>excluded</th>
+ {% if arcs %}
+ <th>branches</th>
+ <th>br exec</th>
+ {% endif %}
+ <th class='right'>coverage</th>
+ </tr>
+ </thead>
+ {# HTML syntax requires thead, tfoot, tbody #}
+ <tfoot>
+ <tr class='total'>
+ <td class='name left'>Total</td>
+ <td>{{totals.n_statements}}</td>
+ <td>{{totals.n_executed}}</td>
+ <td>{{totals.n_excluded}}</td>
+ {% if arcs %}
+ <td>{{totals.n_branches}}</td>
+ <td>{{totals.n_executed_branches}}</td>
+ {% endif %}
+ <td class='right'>{{totals.pc_covered|format_pct}}%</td>
+ </tr>
+ </tfoot>
+ <tbody>
+ {% for file in files %}
+ <tr class='file'>
+ <td class='name left'><a href='{{file.html_filename}}'>{{file.cu.name}}</a></td>
+ <td>{{file.nums.n_statements}}</td>
+ <td>{{file.nums.n_executed}}</td>
+ <td>{{file.nums.n_excluded}}</td>
+ {% if arcs %}
+ <td>{{file.nums.n_branches}}</td>
+ <td>{{file.nums.n_executed_branches}}</td>
+ {% endif %}
+ <td class='right'>{{file.nums.pc_covered|format_pct}}%</td>
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+ </div>
-<div id='footer'>
- <div class='content'>
- <p>
- <a class='nav' href='{{__url__}}'>coverage.py v{{__version__}}</a>
- </p>
- </div>
-</div>
+ <div id='footer'>
+ <div class='content'>
+ <p>
+ <a class='nav' href='{{__url__}}'>coverage.py v{{__version__}}</a>
+ </p>
+ </div>
+ </div>
-</body>
+ <script type="text/javascript" charset="utf-8">
+ jQuery(function() {
+ jQuery("table.index").tablesorter({
+ headers: {
+ 0: { sorter:'text' },
+ 1: { sorter:'digit' },
+ 2: { sorter:'digit' },
+ 3: { sorter:'digit' },
+ 4: { sorter:'percent' },
+ }
+ });
+ });
+ </script>
+ </body>
</html>
diff --git a/coverage/htmlfiles/jquery.tablesorter.min.js b/coverage/htmlfiles/jquery.tablesorter.min.js new file mode 100644 index 0000000..64c7007 --- /dev/null +++ b/coverage/htmlfiles/jquery.tablesorter.min.js @@ -0,0 +1,2 @@ + +(function($){$.extend({tablesorter:new function(){var parsers=[],widgets=[];this.defaults={cssHeader:"header",cssAsc:"headerSortUp",cssDesc:"headerSortDown",sortInitialOrder:"asc",sortMultiSortKey:"shiftKey",sortForce:null,sortAppend:null,textExtraction:"simple",parsers:{},widgets:[],widgetZebra:{css:["even","odd"]},headers:{},widthFixed:false,cancelSelection:true,sortList:[],headerList:[],dateFormat:"us",decimal:'.',debug:false};function benchmark(s,d){log(s+","+(new Date().getTime()-d.getTime())+"ms");}this.benchmark=benchmark;function log(s){if(typeof console!="undefined"&&typeof console.debug!="undefined"){console.log(s);}else{alert(s);}}function buildParserCache(table,$headers){if(table.config.debug){var parsersDebug="";}var rows=table.tBodies[0].rows;if(table.tBodies[0].rows[0]){var list=[],cells=rows[0].cells,l=cells.length;for(var i=0;i<l;i++){var p=false;if($.metadata&&($($headers[i]).metadata()&&$($headers[i]).metadata().sorter)){p=getParserById($($headers[i]).metadata().sorter);}else if((table.config.headers[i]&&table.config.headers[i].sorter)){p=getParserById(table.config.headers[i].sorter);}if(!p){p=detectParserForColumn(table,cells[i]);}if(table.config.debug){parsersDebug+="column:"+i+" parser:"+p.id+"\n";}list.push(p);}}if(table.config.debug){log(parsersDebug);}return list;};function detectParserForColumn(table,node){var l=parsers.length;for(var i=1;i<l;i++){if(parsers[i].is($.trim(getElementText(table.config,node)),table,node)){return parsers[i];}}return parsers[0];}function getParserById(name){var l=parsers.length;for(var i=0;i<l;i++){if(parsers[i].id.toLowerCase()==name.toLowerCase()){return parsers[i];}}return false;}function buildCache(table){if(table.config.debug){var cacheTime=new Date();}var totalRows=(table.tBodies[0]&&table.tBodies[0].rows.length)||0,totalCells=(table.tBodies[0].rows[0]&&table.tBodies[0].rows[0].cells.length)||0,parsers=table.config.parsers,cache={row:[],normalized:[]};for(var i=0;i<totalRows;++i){var c=table.tBodies[0].rows[i],cols=[];cache.row.push($(c));for(var j=0;j<totalCells;++j){cols.push(parsers[j].format(getElementText(table.config,c.cells[j]),table,c.cells[j]));}cols.push(i);cache.normalized.push(cols);cols=null;};if(table.config.debug){benchmark("Building cache for "+totalRows+" rows:",cacheTime);}return cache;};function getElementText(config,node){if(!node)return"";var t="";if(config.textExtraction=="simple"){if(node.childNodes[0]&&node.childNodes[0].hasChildNodes()){t=node.childNodes[0].innerHTML;}else{t=node.innerHTML;}}else{if(typeof(config.textExtraction)=="function"){t=config.textExtraction(node);}else{t=$(node).text();}}return t;}function appendToTable(table,cache){if(table.config.debug){var appendTime=new Date()}var c=cache,r=c.row,n=c.normalized,totalRows=n.length,checkCell=(n[0].length-1),tableBody=$(table.tBodies[0]),rows=[];for(var i=0;i<totalRows;i++){rows.push(r[n[i][checkCell]]);if(!table.config.appender){var o=r[n[i][checkCell]];var l=o.length;for(var j=0;j<l;j++){tableBody[0].appendChild(o[j]);}}}if(table.config.appender){table.config.appender(table,rows);}rows=null;if(table.config.debug){benchmark("Rebuilt table:",appendTime);}applyWidget(table);setTimeout(function(){$(table).trigger("sortEnd");},0);};function buildHeaders(table){if(table.config.debug){var time=new Date();}var meta=($.metadata)?true:false,tableHeadersRows=[];for(var i=0;i<table.tHead.rows.length;i++){tableHeadersRows[i]=0;};$tableHeaders=$("thead th",table);$tableHeaders.each(function(index){this.count=0;this.column=index;this.order=formatSortingOrder(table.config.sortInitialOrder);if(checkHeaderMetadata(this)||checkHeaderOptions(table,index))this.sortDisabled=true;if(!this.sortDisabled){$(this).addClass(table.config.cssHeader);}table.config.headerList[index]=this;});if(table.config.debug){benchmark("Built headers:",time);log($tableHeaders);}return $tableHeaders;};function checkCellColSpan(table,rows,row){var arr=[],r=table.tHead.rows,c=r[row].cells;for(var i=0;i<c.length;i++){var cell=c[i];if(cell.colSpan>1){arr=arr.concat(checkCellColSpan(table,headerArr,row++));}else{if(table.tHead.length==1||(cell.rowSpan>1||!r[row+1])){arr.push(cell);}}}return arr;};function checkHeaderMetadata(cell){if(($.metadata)&&($(cell).metadata().sorter===false)){return true;};return false;}function checkHeaderOptions(table,i){if((table.config.headers[i])&&(table.config.headers[i].sorter===false)){return true;};return false;}function applyWidget(table){var c=table.config.widgets;var l=c.length;for(var i=0;i<l;i++){getWidgetById(c[i]).format(table);}}function getWidgetById(name){var l=widgets.length;for(var i=0;i<l;i++){if(widgets[i].id.toLowerCase()==name.toLowerCase()){return widgets[i];}}};function formatSortingOrder(v){if(typeof(v)!="Number"){i=(v.toLowerCase()=="desc")?1:0;}else{i=(v==(0||1))?v:0;}return i;}function isValueInArray(v,a){var l=a.length;for(var i=0;i<l;i++){if(a[i][0]==v){return true;}}return false;}function setHeadersCss(table,$headers,list,css){$headers.removeClass(css[0]).removeClass(css[1]);var h=[];$headers.each(function(offset){if(!this.sortDisabled){h[this.column]=$(this);}});var l=list.length;for(var i=0;i<l;i++){h[list[i][0]].addClass(css[list[i][1]]);}}function fixColumnWidth(table,$headers){var c=table.config;if(c.widthFixed){var colgroup=$('<colgroup>');$("tr:first td",table.tBodies[0]).each(function(){colgroup.append($('<col>').css('width',$(this).width()));});$(table).prepend(colgroup);};}function updateHeaderSortCount(table,sortList){var c=table.config,l=sortList.length;for(var i=0;i<l;i++){var s=sortList[i],o=c.headerList[s[0]];o.count=s[1];o.count++;}}function multisort(table,sortList,cache){if(table.config.debug){var sortTime=new Date();}var dynamicExp="var sortWrapper = function(a,b) {",l=sortList.length;for(var i=0;i<l;i++){var c=sortList[i][0];var order=sortList[i][1];var s=(getCachedSortType(table.config.parsers,c)=="text")?((order==0)?"sortText":"sortTextDesc"):((order==0)?"sortNumeric":"sortNumericDesc");var e="e"+i;dynamicExp+="var "+e+" = "+s+"(a["+c+"],b["+c+"]); ";dynamicExp+="if("+e+") { return "+e+"; } ";dynamicExp+="else { ";}var orgOrderCol=cache.normalized[0].length-1;dynamicExp+="return a["+orgOrderCol+"]-b["+orgOrderCol+"];";for(var i=0;i<l;i++){dynamicExp+="}; ";}dynamicExp+="return 0; ";dynamicExp+="}; ";eval(dynamicExp);cache.normalized.sort(sortWrapper);if(table.config.debug){benchmark("Sorting on "+sortList.toString()+" and dir "+order+" time:",sortTime);}return cache;};function sortText(a,b){return((a<b)?-1:((a>b)?1:0));};function sortTextDesc(a,b){return((b<a)?-1:((b>a)?1:0));};function sortNumeric(a,b){return a-b;};function sortNumericDesc(a,b){return b-a;};function getCachedSortType(parsers,i){return parsers[i].type;};this.construct=function(settings){return this.each(function(){if(!this.tHead||!this.tBodies)return;var $this,$document,$headers,cache,config,shiftDown=0,sortOrder;this.config={};config=$.extend(this.config,$.tablesorter.defaults,settings);$this=$(this);$headers=buildHeaders(this);this.config.parsers=buildParserCache(this,$headers);cache=buildCache(this);var sortCSS=[config.cssDesc,config.cssAsc];fixColumnWidth(this);$headers.click(function(e){$this.trigger("sortStart");var totalRows=($this[0].tBodies[0]&&$this[0].tBodies[0].rows.length)||0;if(!this.sortDisabled&&totalRows>0){var $cell=$(this);var i=this.column;this.order=this.count++%2;if(!e[config.sortMultiSortKey]){config.sortList=[];if(config.sortForce!=null){var a=config.sortForce;for(var j=0;j<a.length;j++){if(a[j][0]!=i){config.sortList.push(a[j]);}}}config.sortList.push([i,this.order]);}else{if(isValueInArray(i,config.sortList)){for(var j=0;j<config.sortList.length;j++){var s=config.sortList[j],o=config.headerList[s[0]];if(s[0]==i){o.count=s[1];o.count++;s[1]=o.count%2;}}}else{config.sortList.push([i,this.order]);}};setTimeout(function(){setHeadersCss($this[0],$headers,config.sortList,sortCSS);appendToTable($this[0],multisort($this[0],config.sortList,cache));},1);return false;}}).mousedown(function(){if(config.cancelSelection){this.onselectstart=function(){return false};return false;}});$this.bind("update",function(){this.config.parsers=buildParserCache(this,$headers);cache=buildCache(this);}).bind("sorton",function(e,list){$(this).trigger("sortStart");config.sortList=list;var sortList=config.sortList;updateHeaderSortCount(this,sortList);setHeadersCss(this,$headers,sortList,sortCSS);appendToTable(this,multisort(this,sortList,cache));}).bind("appendCache",function(){appendToTable(this,cache);}).bind("applyWidgetId",function(e,id){getWidgetById(id).format(this);}).bind("applyWidgets",function(){applyWidget(this);});if($.metadata&&($(this).metadata()&&$(this).metadata().sortlist)){config.sortList=$(this).metadata().sortlist;}if(config.sortList.length>0){$this.trigger("sorton",[config.sortList]);}applyWidget(this);});};this.addParser=function(parser){var l=parsers.length,a=true;for(var i=0;i<l;i++){if(parsers[i].id.toLowerCase()==parser.id.toLowerCase()){a=false;}}if(a){parsers.push(parser);};};this.addWidget=function(widget){widgets.push(widget);};this.formatFloat=function(s){var i=parseFloat(s);return(isNaN(i))?0:i;};this.formatInt=function(s){var i=parseInt(s);return(isNaN(i))?0:i;};this.isDigit=function(s,config){var DECIMAL='\\'+config.decimal;var exp='/(^[+]?0('+DECIMAL+'0+)?$)|(^([-+]?[1-9][0-9]*)$)|(^([-+]?((0?|[1-9][0-9]*)'+DECIMAL+'(0*[1-9][0-9]*)))$)|(^[-+]?[1-9]+[0-9]*'+DECIMAL+'0+$)/';return RegExp(exp).test($.trim(s));};this.clearTableBody=function(table){if($.browser.msie){function empty(){while(this.firstChild)this.removeChild(this.firstChild);}empty.apply(table.tBodies[0]);}else{table.tBodies[0].innerHTML="";}};}});$.fn.extend({tablesorter:$.tablesorter.construct});var ts=$.tablesorter;ts.addParser({id:"text",is:function(s){return true;},format:function(s){return $.trim(s.toLowerCase());},type:"text"});ts.addParser({id:"digit",is:function(s,table){var c=table.config;return $.tablesorter.isDigit(s,c);},format:function(s){return $.tablesorter.formatFloat(s);},type:"numeric"});ts.addParser({id:"currency",is:function(s){return/^[£$€?.]/.test(s);},format:function(s){return $.tablesorter.formatFloat(s.replace(new RegExp(/[^0-9.]/g),""));},type:"numeric"});ts.addParser({id:"ipAddress",is:function(s){return/^\d{2,3}[\.]\d{2,3}[\.]\d{2,3}[\.]\d{2,3}$/.test(s);},format:function(s){var a=s.split("."),r="",l=a.length;for(var i=0;i<l;i++){var item=a[i];if(item.length==2){r+="0"+item;}else{r+=item;}}return $.tablesorter.formatFloat(r);},type:"numeric"});ts.addParser({id:"url",is:function(s){return/^(https?|ftp|file):\/\/$/.test(s);},format:function(s){return jQuery.trim(s.replace(new RegExp(/(https?|ftp|file):\/\//),''));},type:"text"});ts.addParser({id:"isoDate",is:function(s){return/^\d{4}[\/-]\d{1,2}[\/-]\d{1,2}$/.test(s);},format:function(s){return $.tablesorter.formatFloat((s!="")?new Date(s.replace(new RegExp(/-/g),"/")).getTime():"0");},type:"numeric"});ts.addParser({id:"percent",is:function(s){return/\%$/.test($.trim(s));},format:function(s){return $.tablesorter.formatFloat(s.replace(new RegExp(/%/g),""));},type:"numeric"});ts.addParser({id:"usLongDate",is:function(s){return s.match(new RegExp(/^[A-Za-z]{3,10}\.? [0-9]{1,2}, ([0-9]{4}|'?[0-9]{2}) (([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\s(AM|PM)))$/));},format:function(s){return $.tablesorter.formatFloat(new Date(s).getTime());},type:"numeric"});ts.addParser({id:"shortDate",is:function(s){return/\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}/.test(s);},format:function(s,table){var c=table.config;s=s.replace(/\-/g,"/");if(c.dateFormat=="us"){s=s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/,"$3/$1/$2");}else if(c.dateFormat=="uk"){s=s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/,"$3/$2/$1");}else if(c.dateFormat=="dd/mm/yy"||c.dateFormat=="dd-mm-yy"){s=s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{2})/,"$1/$2/$3");}return $.tablesorter.formatFloat(new Date(s).getTime());},type:"numeric"});ts.addParser({id:"time",is:function(s){return/^(([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\s(am|pm)))$/.test(s);},format:function(s){return $.tablesorter.formatFloat(new Date("2000/01/01 "+s).getTime());},type:"numeric"});ts.addParser({id:"metadata",is:function(s){return false;},format:function(s,table,cell){var c=table.config,p=(!c.parserMetadataName)?'sortValue':c.parserMetadataName;return $(cell).metadata()[p];},type:"numeric"});ts.addWidget({id:"zebra",format:function(table){if(table.config.debug){var time=new Date();}$("tr:visible",table.tBodies[0]).filter(':even').removeClass(table.config.widgetZebra.css[1]).addClass(table.config.widgetZebra.css[0]).end().filter(':odd').removeClass(table.config.widgetZebra.css[0]).addClass(table.config.widgetZebra.css[1]);if(table.config.debug){$.tablesorter.benchmark("Applying Zebra widget",time);}}});})(jQuery);
\ No newline at end of file diff --git a/coverage/htmlfiles/style.css b/coverage/htmlfiles/style.css index 65a2790..dd6c991 100644 --- a/coverage/htmlfiles/style.css +++ b/coverage/htmlfiles/style.css @@ -2,14 +2,14 @@ /* Page-wide styles */ html, body, h1, h2, h3, p, td, th { margin: 0; - padding: 0; - border: 0; - outline: 0; - font-weight: inherit; - font-style: inherit; - font-size: 100%; - font-family: inherit; - vertical-align: baseline; + padding: 0; + border: 0; + outline: 0; + font-weight: inherit; + font-style: inherit; + font-size: 100%; + font-family: inherit; + vertical-align: baseline; } /* Set baseline grid to 16 pt. */ @@ -134,16 +134,16 @@ td.text { } .text span.annotate { - font-family: georgia; - font-style: italic; - color: #666; - float: right; - padding-right: .5em; - } + font-family: georgia; + font-style: italic; + color: #666; + float: right; + padding-right: .5em; + } .text p.hide span.annotate { - display: none; - } - + display: none; + } + /* Syntax coloring */ .text .com { color: green; @@ -161,14 +161,28 @@ td.text { /* index styles */ #index td, #index th { text-align: right; - width: 6em; - padding: .25em 0; + width: 5em; + padding: .25em .5em; border-bottom: 1px solid #eee; } #index th { font-style: italic; color: #333; border-bottom: 1px solid #ccc; + cursor: pointer; + } +#index th:hover { + background: #eee; + border-bottom: 1px solid #999; + } +#index td.left, #index th.left { + padding-left: 0; + } +#index td.right, #index th.right { + padding-right: 0; + } +#index th.headerSortDown, #index th.headerSortUp { + border-bottom: 1px solid #000; } #index td.name, #index th.name { text-align: left; @@ -183,13 +197,12 @@ td.text { color: #000; } #index tr.total { - font-weight: bold; } #index tr.total td { - padding: .25em 0; + font-weight: bold; border-top: 1px solid #ccc; border-bottom: none; } #index tr.file:hover { - background: #eeeeee; - } + background: #eeeeee; + } diff --git a/coverage/parser.py b/coverage/parser.py index 01b38af..afe7e57 100644 --- a/coverage/parser.py +++ b/coverage/parser.py @@ -111,7 +111,9 @@ class CodeParser(object): excluding = True elif toktype == token.STRING and prev_toktype == token.INDENT: # Strings that are first on an indented line are docstrings. - # (a trick from trace.py in the stdlib.) + # (a trick from trace.py in the stdlib.) This works for + # 99.9999% of cases. For the rest (!) see: + # http://stackoverflow.com/questions/1769332/x/1769794#1769794 for i in range(slineno, elineno+1): self.docstrings.add(i) elif toktype == token.NEWLINE: @@ -213,13 +215,18 @@ class CodeParser(object): exit_counts = {} for l1, l2 in self.arcs(): if l1 == -1: + # Don't ever report -1 as a line number continue if l1 in excluded_lines: + # Don't report excluded lines as line numbers. + continue + if l2 in excluded_lines: + # Arcs to excluded lines shouldn't count. continue if l1 not in exit_counts: exit_counts[l1] = 0 exit_counts[l1] += 1 - + # Class definitions have one extra exit, so remove one for each: for l in self.classdefs: # Ensure key is there - #pragma: no cover will mean its not diff --git a/coverage/phystokens.py b/coverage/phystokens.py index 2862490..131b362 100644 --- a/coverage/phystokens.py +++ b/coverage/phystokens.py @@ -15,6 +15,7 @@ def phys_tokens(toks): """ last_line = None last_lineno = -1 + last_ttype = None for ttype, ttext, (slineno, scol), (elineno, ecol), ltext in toks: if last_lineno != elineno: if last_line and last_line[-2:] == "\\\n": @@ -34,7 +35,11 @@ def phys_tokens(toks): # so we need to figure out if the backslash is already in the # string token or not. inject_backslash = True - if ttype == token.STRING: + if last_ttype == tokenize.COMMENT: + # Comments like this \ + # should never result in a new token. + inject_backslash = False + elif ttype == token.STRING: if "\n" in ttext and ttext.split('\n', 1)[0][-1] == '\\': # It's a multiline string and the first line ends with # a backslash, so we don't need to inject another. @@ -49,6 +54,7 @@ def phys_tokens(toks): last_line ) last_line = ltext + last_ttype = ttype yield ttype, ttext, (slineno, scol), (elineno, ecol), ltext last_lineno = elineno diff --git a/coverage/templite.py b/coverage/templite.py index f61fbdc..0654f29 100644 --- a/coverage/templite.py +++ b/coverage/templite.py @@ -2,7 +2,7 @@ # Coincidentally named the same as http://code.activestate.com/recipes/496702/ -import re +import re, sys class Templite(object): """A simple template renderer, for a nano-subset of Django syntax. @@ -80,7 +80,7 @@ class Templite(object): ops = ops_stack.pop() assert ops[-1][0] == words[0][3:] else: - raise Exception("Don't understand tag %r" % words) + raise SyntaxError("Don't understand tag %r" % words) else: ops.append(('lit', tok)) @@ -120,7 +120,13 @@ class _TempliteEngine(object): if op == 'lit': self.result += args elif op == 'exp': - self.result += str(self.evaluate(args)) + try: + self.result += str(self.evaluate(args)) + except: + exc_class, exc, _ = sys.exc_info() + new_exc = exc_class("Couldn't evaluate {{ %s }}: %s" + % (args, exc)) + raise new_exc elif op == 'if': expr, body = args if self.evaluate(expr): @@ -132,7 +138,7 @@ class _TempliteEngine(object): self.context[var] = val self.execute(body) else: - raise Exception("TempliteEngine doesn't grok op %r" % op) + raise AssertionError("TempliteEngine doesn't grok op %r" % op) def evaluate(self, expr): """Evaluate an expression. diff --git a/test/coverage_coverage.py b/test/coverage_coverage.py index 1a5cc9c..e1e7674 100644 --- a/test/coverage_coverage.py +++ b/test/coverage_coverage.py @@ -8,7 +8,7 @@ HTML_DIR = "htmlcov" if os.path.exists(HTML_DIR): shutil.rmtree(HTML_DIR) -cov = coverage.coverage() +cov = coverage.coverage(branch=True) # Cheap trick: the coverage code itself is excluded from measurement, but if # we clobber the cover_prefix in the coverage object, we can defeat the # self-detection. @@ -40,5 +40,6 @@ cov.clear_exclude() cov.exclude("#pragma: no cover") cov.exclude("def __repr__") cov.exclude("if __name__ == .__main__.:") +cov.exclude("raise AssertionError") cov.html_report(directory=HTML_DIR, ignore_errors=True) diff --git a/test/coveragetest.py b/test/coveragetest.py index d1631a3..b86794d 100644 --- a/test/coveragetest.py +++ b/test/coveragetest.py @@ -1,6 +1,6 @@ """Base test case class for coverage testing.""" -import imp, os, random, re, shutil, sys, tempfile, textwrap, unittest +import difflib, imp, os, random, re, shutil, sys, tempfile, textwrap, unittest import coverage from coverage.backward import set, sorted, StringIO # pylint: disable-msg=W0622 @@ -280,3 +280,20 @@ class CoverageTest(unittest.TestCase): m = re.search(regex, s) if not m: raise self.failureException("%r doesn't match %r" % (s, regex)) + + def assert_multiline_equal(self, first, second): + """Assert that two multi-line strings are equal. + + If they aren't, show a nice diff. + + """ + # Adapted from Py3.1 unittest. + self.assert_(isinstance(first, str), ( + 'First argument is not a string')) + self.assert_(isinstance(second, str), ( + 'Second argument is not a string')) + + if first != second: + msg = ''.join(difflib.ndiff(first.splitlines(True), + second.splitlines(True))) + self.fail("Multi-line strings are unequal:\n" + msg) diff --git a/test/farm/html/gold_a/a.html b/test/farm/html/gold_a/a.html index b29831b..991dbb6 100644 --- a/test/farm/html/gold_a/a.html +++ b/test/farm/html/gold_a/a.html @@ -1,10 +1,11 @@ -<!doctype html PUBLIC "-//W3C//DTD html 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
+<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<title>Coverage for a</title>
<link rel='stylesheet' href='style.css' type='text/css'>
-<script src='jquery-1.3.2.min.js'></script>
-<script>
+<script type='text/javascript' src='jquery-1.3.2.min.js'></script>
+<script type='text/javascript'>
function toggle_lines(btn, cls) {
var btn = $(btn);
if (btn.hasClass("hide")) {
@@ -29,6 +30,7 @@ function toggle_lines(btn, cls) { <span class='run hide' onclick='toggle_lines(this, "run")'>2 run</span>
<span class='exc' onclick='toggle_lines(this, "exc")'>0 excluded</span>
<span class='mis' onclick='toggle_lines(this, "mis")'>1 missing</span>
+
</h2>
</div>
</div>
@@ -47,13 +49,13 @@ function toggle_lines(btn, cls) { </td>
<td class='text' valign='top'>
-<p class='pln'><span class='com'># A test file for HTML reporting by coverage.</span><span class="strut"> </span></p>
-<p class='pln'><span class="strut"> </span></p>
-<p class='stm run hide'><span class='key'>if</span> <span class='num'>1</span> <span class='op'><</span> <span class='num'>2</span><span class='op'>:</span><span class="strut"> </span></p>
-<p class='pln'> <span class='com'># Needed a < to look at HTML entities.</span><span class="strut"> </span></p>
-<p class='stm run hide'> <span class='nam'>a</span> <span class='op'>=</span> <span class='num'>3</span><span class="strut"> </span></p>
-<p class='pln'><span class='key'>else</span><span class='op'>:</span><span class="strut"> </span></p>
-<p class='stm mis'> <span class='nam'>a</span> <span class='op'>=</span> <span class='num'>4</span><span class="strut"> </span></p>
+<p class='pln'><span class='com'># A test file for HTML reporting by coverage.</span><span class='strut'> </span></p>
+<p class='pln'><span class='strut'> </span></p>
+<p class='stm run hide'><span class='key'>if</span> <span class='num'>1</span> <span class='op'><</span> <span class='num'>2</span><span class='op'>:</span><span class='strut'> </span></p>
+<p class='pln'> <span class='com'># Needed a < to look at HTML entities.</span><span class='strut'> </span></p>
+<p class='stm run hide'> <span class='nam'>a</span> <span class='op'>=</span> <span class='num'>3</span><span class='strut'> </span></p>
+<p class='pln'><span class='key'>else</span><span class='op'>:</span><span class='strut'> </span></p>
+<p class='stm mis'> <span class='nam'>a</span> <span class='op'>=</span> <span class='num'>4</span><span class='strut'> </span></p>
</td>
</tr>
diff --git a/test/farm/html/gold_a/index.html b/test/farm/html/gold_a/index.html index 8810344..15ecf8d 100644 --- a/test/farm/html/gold_a/index.html +++ b/test/farm/html/gold_a/index.html @@ -1,58 +1,81 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
-<head>
-<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
-<title>Coverage report</title>
-<link rel='stylesheet' href='style.css' type='text/css'>
-</head>
-<body>
+ <head>
+ <meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
+ <title>Coverage report</title>
+ <link rel='stylesheet' href='style.css' type='text/css'>
+ <script type='text/javascript' src='jquery-1.3.2.min.js'></script>
+ <script type='text/javascript' src='jquery.tablesorter.min.js'></script>
+ </head>
+ <body>
-<div id='header'>
- <div class='content'>
- <h1>Coverage report:
- <span class='pc_cov'>67%</span>
- </h1>
- </div>
-</div>
+ <div id='header'>
+ <div class='content'>
+ <h1>Coverage report:
+ <span class='pc_cov'>67%</span>
+ </h1>
+ </div>
+ </div>
-<div id='index'>
-<table class='index'>
-<tr class='tablehead'>
- <th class='name'>Module</th>
- <th>statements</th>
- <th>run</th>
- <th>excluded</th>
-
- <th>coverage</th>
-</tr>
+ <div id='index'>
+ <table class='index'>
+ <thead>
+
+ <tr class='tablehead' title='Click to sort'>
+ <th class='name left'>Module</th>
+ <th>statements</th>
+ <th>run</th>
+ <th>excluded</th>
+
+ <th class='right'>coverage</th>
+ </tr>
+ </thead>
+
+ <tfoot>
+ <tr class='total'>
+ <td class='name left'>Total</td>
+ <td>3</td>
+ <td>2</td>
+ <td>0</td>
+
+ <td class='right'>67%</td>
+ </tr>
+ </tfoot>
+ <tbody>
+
+ <tr class='file'>
+ <td class='name left'><a href='a.html'>a</a></td>
+ <td>3</td>
+ <td>2</td>
+ <td>0</td>
+
+ <td class='right'>67%</td>
+ </tr>
+
+ </tbody>
+ </table>
+ </div>
-<tr class='file'>
- <td class='name'><a href='a.html'>a</a></td>
- <td>3</td>
- <td>2</td>
- <td>0</td>
-
- <td>67%</td>
-</tr>
+ <div id='footer'>
+ <div class='content'>
+ <p>
+ <a class='nav' href='http://nedbatchelder.com/code/coverage'>coverage.py v3.2b3</a>
+ </p>
+ </div>
+ </div>
-<tr class='total'>
-<td class='name'>Total</td>
-<td>3</td>
-<td>2</td>
-<td>0</td>
-
-<td>67%</td>
-</tr>
-</table>
-</div>
-
-<div id='footer'>
- <div class='content'>
- <p>
- <a class='nav' href='http://nedbatchelder.com/code/coverage'>coverage.py v3.2a1</a>
- </p>
- </div>
-</div>
-
-</body>
+ <script type="text/javascript" charset="utf-8">
+ jQuery(function() {
+ jQuery("table.index").tablesorter({
+ headers: {
+ 0: { sorter:'text' },
+ 1: { sorter:'digit' },
+ 2: { sorter:'digit' },
+ 3: { sorter:'digit' },
+ 4: { sorter:'percent' },
+ }
+ });
+ });
+ </script>
+ </body>
</html>
diff --git a/test/farm/html/gold_a/jquery.tablesorter.min.js b/test/farm/html/gold_a/jquery.tablesorter.min.js new file mode 100644 index 0000000..64c7007 --- /dev/null +++ b/test/farm/html/gold_a/jquery.tablesorter.min.js @@ -0,0 +1,2 @@ + +(function($){$.extend({tablesorter:new function(){var parsers=[],widgets=[];this.defaults={cssHeader:"header",cssAsc:"headerSortUp",cssDesc:"headerSortDown",sortInitialOrder:"asc",sortMultiSortKey:"shiftKey",sortForce:null,sortAppend:null,textExtraction:"simple",parsers:{},widgets:[],widgetZebra:{css:["even","odd"]},headers:{},widthFixed:false,cancelSelection:true,sortList:[],headerList:[],dateFormat:"us",decimal:'.',debug:false};function benchmark(s,d){log(s+","+(new Date().getTime()-d.getTime())+"ms");}this.benchmark=benchmark;function log(s){if(typeof console!="undefined"&&typeof console.debug!="undefined"){console.log(s);}else{alert(s);}}function buildParserCache(table,$headers){if(table.config.debug){var parsersDebug="";}var rows=table.tBodies[0].rows;if(table.tBodies[0].rows[0]){var list=[],cells=rows[0].cells,l=cells.length;for(var i=0;i<l;i++){var p=false;if($.metadata&&($($headers[i]).metadata()&&$($headers[i]).metadata().sorter)){p=getParserById($($headers[i]).metadata().sorter);}else if((table.config.headers[i]&&table.config.headers[i].sorter)){p=getParserById(table.config.headers[i].sorter);}if(!p){p=detectParserForColumn(table,cells[i]);}if(table.config.debug){parsersDebug+="column:"+i+" parser:"+p.id+"\n";}list.push(p);}}if(table.config.debug){log(parsersDebug);}return list;};function detectParserForColumn(table,node){var l=parsers.length;for(var i=1;i<l;i++){if(parsers[i].is($.trim(getElementText(table.config,node)),table,node)){return parsers[i];}}return parsers[0];}function getParserById(name){var l=parsers.length;for(var i=0;i<l;i++){if(parsers[i].id.toLowerCase()==name.toLowerCase()){return parsers[i];}}return false;}function buildCache(table){if(table.config.debug){var cacheTime=new Date();}var totalRows=(table.tBodies[0]&&table.tBodies[0].rows.length)||0,totalCells=(table.tBodies[0].rows[0]&&table.tBodies[0].rows[0].cells.length)||0,parsers=table.config.parsers,cache={row:[],normalized:[]};for(var i=0;i<totalRows;++i){var c=table.tBodies[0].rows[i],cols=[];cache.row.push($(c));for(var j=0;j<totalCells;++j){cols.push(parsers[j].format(getElementText(table.config,c.cells[j]),table,c.cells[j]));}cols.push(i);cache.normalized.push(cols);cols=null;};if(table.config.debug){benchmark("Building cache for "+totalRows+" rows:",cacheTime);}return cache;};function getElementText(config,node){if(!node)return"";var t="";if(config.textExtraction=="simple"){if(node.childNodes[0]&&node.childNodes[0].hasChildNodes()){t=node.childNodes[0].innerHTML;}else{t=node.innerHTML;}}else{if(typeof(config.textExtraction)=="function"){t=config.textExtraction(node);}else{t=$(node).text();}}return t;}function appendToTable(table,cache){if(table.config.debug){var appendTime=new Date()}var c=cache,r=c.row,n=c.normalized,totalRows=n.length,checkCell=(n[0].length-1),tableBody=$(table.tBodies[0]),rows=[];for(var i=0;i<totalRows;i++){rows.push(r[n[i][checkCell]]);if(!table.config.appender){var o=r[n[i][checkCell]];var l=o.length;for(var j=0;j<l;j++){tableBody[0].appendChild(o[j]);}}}if(table.config.appender){table.config.appender(table,rows);}rows=null;if(table.config.debug){benchmark("Rebuilt table:",appendTime);}applyWidget(table);setTimeout(function(){$(table).trigger("sortEnd");},0);};function buildHeaders(table){if(table.config.debug){var time=new Date();}var meta=($.metadata)?true:false,tableHeadersRows=[];for(var i=0;i<table.tHead.rows.length;i++){tableHeadersRows[i]=0;};$tableHeaders=$("thead th",table);$tableHeaders.each(function(index){this.count=0;this.column=index;this.order=formatSortingOrder(table.config.sortInitialOrder);if(checkHeaderMetadata(this)||checkHeaderOptions(table,index))this.sortDisabled=true;if(!this.sortDisabled){$(this).addClass(table.config.cssHeader);}table.config.headerList[index]=this;});if(table.config.debug){benchmark("Built headers:",time);log($tableHeaders);}return $tableHeaders;};function checkCellColSpan(table,rows,row){var arr=[],r=table.tHead.rows,c=r[row].cells;for(var i=0;i<c.length;i++){var cell=c[i];if(cell.colSpan>1){arr=arr.concat(checkCellColSpan(table,headerArr,row++));}else{if(table.tHead.length==1||(cell.rowSpan>1||!r[row+1])){arr.push(cell);}}}return arr;};function checkHeaderMetadata(cell){if(($.metadata)&&($(cell).metadata().sorter===false)){return true;};return false;}function checkHeaderOptions(table,i){if((table.config.headers[i])&&(table.config.headers[i].sorter===false)){return true;};return false;}function applyWidget(table){var c=table.config.widgets;var l=c.length;for(var i=0;i<l;i++){getWidgetById(c[i]).format(table);}}function getWidgetById(name){var l=widgets.length;for(var i=0;i<l;i++){if(widgets[i].id.toLowerCase()==name.toLowerCase()){return widgets[i];}}};function formatSortingOrder(v){if(typeof(v)!="Number"){i=(v.toLowerCase()=="desc")?1:0;}else{i=(v==(0||1))?v:0;}return i;}function isValueInArray(v,a){var l=a.length;for(var i=0;i<l;i++){if(a[i][0]==v){return true;}}return false;}function setHeadersCss(table,$headers,list,css){$headers.removeClass(css[0]).removeClass(css[1]);var h=[];$headers.each(function(offset){if(!this.sortDisabled){h[this.column]=$(this);}});var l=list.length;for(var i=0;i<l;i++){h[list[i][0]].addClass(css[list[i][1]]);}}function fixColumnWidth(table,$headers){var c=table.config;if(c.widthFixed){var colgroup=$('<colgroup>');$("tr:first td",table.tBodies[0]).each(function(){colgroup.append($('<col>').css('width',$(this).width()));});$(table).prepend(colgroup);};}function updateHeaderSortCount(table,sortList){var c=table.config,l=sortList.length;for(var i=0;i<l;i++){var s=sortList[i],o=c.headerList[s[0]];o.count=s[1];o.count++;}}function multisort(table,sortList,cache){if(table.config.debug){var sortTime=new Date();}var dynamicExp="var sortWrapper = function(a,b) {",l=sortList.length;for(var i=0;i<l;i++){var c=sortList[i][0];var order=sortList[i][1];var s=(getCachedSortType(table.config.parsers,c)=="text")?((order==0)?"sortText":"sortTextDesc"):((order==0)?"sortNumeric":"sortNumericDesc");var e="e"+i;dynamicExp+="var "+e+" = "+s+"(a["+c+"],b["+c+"]); ";dynamicExp+="if("+e+") { return "+e+"; } ";dynamicExp+="else { ";}var orgOrderCol=cache.normalized[0].length-1;dynamicExp+="return a["+orgOrderCol+"]-b["+orgOrderCol+"];";for(var i=0;i<l;i++){dynamicExp+="}; ";}dynamicExp+="return 0; ";dynamicExp+="}; ";eval(dynamicExp);cache.normalized.sort(sortWrapper);if(table.config.debug){benchmark("Sorting on "+sortList.toString()+" and dir "+order+" time:",sortTime);}return cache;};function sortText(a,b){return((a<b)?-1:((a>b)?1:0));};function sortTextDesc(a,b){return((b<a)?-1:((b>a)?1:0));};function sortNumeric(a,b){return a-b;};function sortNumericDesc(a,b){return b-a;};function getCachedSortType(parsers,i){return parsers[i].type;};this.construct=function(settings){return this.each(function(){if(!this.tHead||!this.tBodies)return;var $this,$document,$headers,cache,config,shiftDown=0,sortOrder;this.config={};config=$.extend(this.config,$.tablesorter.defaults,settings);$this=$(this);$headers=buildHeaders(this);this.config.parsers=buildParserCache(this,$headers);cache=buildCache(this);var sortCSS=[config.cssDesc,config.cssAsc];fixColumnWidth(this);$headers.click(function(e){$this.trigger("sortStart");var totalRows=($this[0].tBodies[0]&&$this[0].tBodies[0].rows.length)||0;if(!this.sortDisabled&&totalRows>0){var $cell=$(this);var i=this.column;this.order=this.count++%2;if(!e[config.sortMultiSortKey]){config.sortList=[];if(config.sortForce!=null){var a=config.sortForce;for(var j=0;j<a.length;j++){if(a[j][0]!=i){config.sortList.push(a[j]);}}}config.sortList.push([i,this.order]);}else{if(isValueInArray(i,config.sortList)){for(var j=0;j<config.sortList.length;j++){var s=config.sortList[j],o=config.headerList[s[0]];if(s[0]==i){o.count=s[1];o.count++;s[1]=o.count%2;}}}else{config.sortList.push([i,this.order]);}};setTimeout(function(){setHeadersCss($this[0],$headers,config.sortList,sortCSS);appendToTable($this[0],multisort($this[0],config.sortList,cache));},1);return false;}}).mousedown(function(){if(config.cancelSelection){this.onselectstart=function(){return false};return false;}});$this.bind("update",function(){this.config.parsers=buildParserCache(this,$headers);cache=buildCache(this);}).bind("sorton",function(e,list){$(this).trigger("sortStart");config.sortList=list;var sortList=config.sortList;updateHeaderSortCount(this,sortList);setHeadersCss(this,$headers,sortList,sortCSS);appendToTable(this,multisort(this,sortList,cache));}).bind("appendCache",function(){appendToTable(this,cache);}).bind("applyWidgetId",function(e,id){getWidgetById(id).format(this);}).bind("applyWidgets",function(){applyWidget(this);});if($.metadata&&($(this).metadata()&&$(this).metadata().sortlist)){config.sortList=$(this).metadata().sortlist;}if(config.sortList.length>0){$this.trigger("sorton",[config.sortList]);}applyWidget(this);});};this.addParser=function(parser){var l=parsers.length,a=true;for(var i=0;i<l;i++){if(parsers[i].id.toLowerCase()==parser.id.toLowerCase()){a=false;}}if(a){parsers.push(parser);};};this.addWidget=function(widget){widgets.push(widget);};this.formatFloat=function(s){var i=parseFloat(s);return(isNaN(i))?0:i;};this.formatInt=function(s){var i=parseInt(s);return(isNaN(i))?0:i;};this.isDigit=function(s,config){var DECIMAL='\\'+config.decimal;var exp='/(^[+]?0('+DECIMAL+'0+)?$)|(^([-+]?[1-9][0-9]*)$)|(^([-+]?((0?|[1-9][0-9]*)'+DECIMAL+'(0*[1-9][0-9]*)))$)|(^[-+]?[1-9]+[0-9]*'+DECIMAL+'0+$)/';return RegExp(exp).test($.trim(s));};this.clearTableBody=function(table){if($.browser.msie){function empty(){while(this.firstChild)this.removeChild(this.firstChild);}empty.apply(table.tBodies[0]);}else{table.tBodies[0].innerHTML="";}};}});$.fn.extend({tablesorter:$.tablesorter.construct});var ts=$.tablesorter;ts.addParser({id:"text",is:function(s){return true;},format:function(s){return $.trim(s.toLowerCase());},type:"text"});ts.addParser({id:"digit",is:function(s,table){var c=table.config;return $.tablesorter.isDigit(s,c);},format:function(s){return $.tablesorter.formatFloat(s);},type:"numeric"});ts.addParser({id:"currency",is:function(s){return/^[£$€?.]/.test(s);},format:function(s){return $.tablesorter.formatFloat(s.replace(new RegExp(/[^0-9.]/g),""));},type:"numeric"});ts.addParser({id:"ipAddress",is:function(s){return/^\d{2,3}[\.]\d{2,3}[\.]\d{2,3}[\.]\d{2,3}$/.test(s);},format:function(s){var a=s.split("."),r="",l=a.length;for(var i=0;i<l;i++){var item=a[i];if(item.length==2){r+="0"+item;}else{r+=item;}}return $.tablesorter.formatFloat(r);},type:"numeric"});ts.addParser({id:"url",is:function(s){return/^(https?|ftp|file):\/\/$/.test(s);},format:function(s){return jQuery.trim(s.replace(new RegExp(/(https?|ftp|file):\/\//),''));},type:"text"});ts.addParser({id:"isoDate",is:function(s){return/^\d{4}[\/-]\d{1,2}[\/-]\d{1,2}$/.test(s);},format:function(s){return $.tablesorter.formatFloat((s!="")?new Date(s.replace(new RegExp(/-/g),"/")).getTime():"0");},type:"numeric"});ts.addParser({id:"percent",is:function(s){return/\%$/.test($.trim(s));},format:function(s){return $.tablesorter.formatFloat(s.replace(new RegExp(/%/g),""));},type:"numeric"});ts.addParser({id:"usLongDate",is:function(s){return s.match(new RegExp(/^[A-Za-z]{3,10}\.? [0-9]{1,2}, ([0-9]{4}|'?[0-9]{2}) (([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\s(AM|PM)))$/));},format:function(s){return $.tablesorter.formatFloat(new Date(s).getTime());},type:"numeric"});ts.addParser({id:"shortDate",is:function(s){return/\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}/.test(s);},format:function(s,table){var c=table.config;s=s.replace(/\-/g,"/");if(c.dateFormat=="us"){s=s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/,"$3/$1/$2");}else if(c.dateFormat=="uk"){s=s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/,"$3/$2/$1");}else if(c.dateFormat=="dd/mm/yy"||c.dateFormat=="dd-mm-yy"){s=s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{2})/,"$1/$2/$3");}return $.tablesorter.formatFloat(new Date(s).getTime());},type:"numeric"});ts.addParser({id:"time",is:function(s){return/^(([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\s(am|pm)))$/.test(s);},format:function(s){return $.tablesorter.formatFloat(new Date("2000/01/01 "+s).getTime());},type:"numeric"});ts.addParser({id:"metadata",is:function(s){return false;},format:function(s,table,cell){var c=table.config,p=(!c.parserMetadataName)?'sortValue':c.parserMetadataName;return $(cell).metadata()[p];},type:"numeric"});ts.addWidget({id:"zebra",format:function(table){if(table.config.debug){var time=new Date();}$("tr:visible",table.tBodies[0]).filter(':even').removeClass(table.config.widgetZebra.css[1]).addClass(table.config.widgetZebra.css[0]).end().filter(':odd').removeClass(table.config.widgetZebra.css[0]).addClass(table.config.widgetZebra.css[1]);if(table.config.debug){$.tablesorter.benchmark("Applying Zebra widget",time);}}});})(jQuery);
\ No newline at end of file diff --git a/test/farm/html/gold_a/style.css b/test/farm/html/gold_a/style.css index b55e499..dd6c991 100644 --- a/test/farm/html/gold_a/style.css +++ b/test/farm/html/gold_a/style.css @@ -2,14 +2,14 @@ /* Page-wide styles */ html, body, h1, h2, h3, p, td, th { margin: 0; - padding: 0; - border: 0; - outline: 0; - font-weight: inherit; - font-style: inherit; - font-size: 100%; - font-family: inherit; - vertical-align: baseline; + padding: 0; + border: 0; + outline: 0; + font-weight: inherit; + font-style: inherit; + font-size: 100%; + font-family: inherit; + vertical-align: baseline; } /* Set baseline grid to 16 pt. */ @@ -126,13 +126,24 @@ td.text { border-left: 2px solid #808080; } .text p.par { - background: #ffffdd; - border-left: 2px solid #ffff00; + background: #ffffaa; + border-left: 2px solid #eeee99; } .text p.hide { background: inherit; } +.text span.annotate { + font-family: georgia; + font-style: italic; + color: #666; + float: right; + padding-right: .5em; + } +.text p.hide span.annotate { + display: none; + } + /* Syntax coloring */ .text .com { color: green; @@ -150,19 +161,32 @@ td.text { /* index styles */ #index td, #index th { text-align: right; - width: 6em; - padding: .25em 0; + width: 5em; + padding: .25em .5em; border-bottom: 1px solid #eee; } #index th { font-style: italic; color: #333; border-bottom: 1px solid #ccc; + cursor: pointer; + } +#index th:hover { + background: #eee; + border-bottom: 1px solid #999; + } +#index td.left, #index th.left { + padding-left: 0; + } +#index td.right, #index th.right { + padding-right: 0; + } +#index th.headerSortDown, #index th.headerSortUp { + border-bottom: 1px solid #000; } #index td.name, #index th.name { text-align: left; width: auto; - height: 1.5em; } #index td.name a { text-decoration: none; @@ -173,10 +197,12 @@ td.text { color: #000; } #index tr.total { - font-weight: bold; } #index tr.total td { - padding: .25em 0; + font-weight: bold; border-top: 1px solid #ccc; border-bottom: none; } +#index tr.file:hover { + background: #eeeeee; + } diff --git a/test/farm/html/gold_other/blah_blah_other.html b/test/farm/html/gold_other/blah_blah_other.html index 8f25d25..95bcef4 100644 --- a/test/farm/html/gold_other/blah_blah_other.html +++ b/test/farm/html/gold_other/blah_blah_other.html @@ -1,10 +1,11 @@ -<!doctype html PUBLIC "-//W3C//DTD html 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
+<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<title>Coverage for c:\ned\coverage\trunk\test\farm\html\othersrc\other</title>
<link rel='stylesheet' href='style.css' type='text/css'>
-<script src='jquery-1.3.2.min.js'></script>
-<script>
+<script type='text/javascript' src='jquery-1.3.2.min.js'></script>
+<script type='text/javascript'>
function toggle_lines(btn, cls) {
var btn = $(btn);
if (btn.hasClass("hide")) {
@@ -29,6 +30,7 @@ function toggle_lines(btn, cls) { <span class='run hide' onclick='toggle_lines(this, "run")'>1 run</span>
<span class='exc' onclick='toggle_lines(this, "exc")'>0 excluded</span>
<span class='mis' onclick='toggle_lines(this, "mis")'>0 missing</span>
+
</h2>
</div>
</div>
@@ -44,10 +46,10 @@ function toggle_lines(btn, cls) { </td>
<td class='text' valign='top'>
-<p class='pln'><span class='com'># A file in another directory. We're checking that it ends up in the</span><span class="strut"> </span></p>
-<p class='pln'><span class='com'># HTML report.</span><span class="strut"> </span></p>
-<p class='pln'><span class="strut"> </span></p>
-<p class='stm run hide'><span class='key'>print</span><span class='op'>(</span><span class='str'>"This is the other src!"</span><span class='op'>)</span><span class="strut"> </span></p>
+<p class='pln'><span class='com'># A file in another directory. We're checking that it ends up in the</span><span class='strut'> </span></p>
+<p class='pln'><span class='com'># HTML report.</span><span class='strut'> </span></p>
+<p class='pln'><span class='strut'> </span></p>
+<p class='stm run hide'><span class='key'>print</span><span class='op'>(</span><span class='str'>"This is the other src!"</span><span class='op'>)</span><span class='strut'> </span></p>
</td>
</tr>
diff --git a/test/farm/html/gold_other/here.html b/test/farm/html/gold_other/here.html index a6e70df..0c63829 100644 --- a/test/farm/html/gold_other/here.html +++ b/test/farm/html/gold_other/here.html @@ -1,10 +1,11 @@ -<!doctype html PUBLIC "-//W3C//DTD html 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
+<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<title>Coverage for here</title>
<link rel='stylesheet' href='style.css' type='text/css'>
-<script src='jquery-1.3.2.min.js'></script>
-<script>
+<script type='text/javascript' src='jquery-1.3.2.min.js'></script>
+<script type='text/javascript'>
function toggle_lines(btn, cls) {
var btn = $(btn);
if (btn.hasClass("hide")) {
@@ -29,6 +30,7 @@ function toggle_lines(btn, cls) { <span class='run hide' onclick='toggle_lines(this, "run")'>3 run</span>
<span class='exc' onclick='toggle_lines(this, "exc")'>0 excluded</span>
<span class='mis' onclick='toggle_lines(this, "mis")'>1 missing</span>
+
</h2>
</div>
</div>
@@ -48,14 +50,14 @@ function toggle_lines(btn, cls) { </td>
<td class='text' valign='top'>
-<p class='pln'><span class='com'># A test file for HTML reporting by coverage.</span><span class="strut"> </span></p>
-<p class='pln'><span class="strut"> </span></p>
-<p class='stm run hide'><span class='key'>import</span> <span class='nam'>other</span><span class="strut"> </span></p>
-<p class='pln'><span class="strut"> </span></p>
-<p class='stm run hide'><span class='key'>if</span> <span class='num'>1</span> <span class='op'><</span> <span class='num'>2</span><span class='op'>:</span><span class="strut"> </span></p>
-<p class='stm run hide'> <span class='nam'>h</span> <span class='op'>=</span> <span class='num'>3</span><span class="strut"> </span></p>
-<p class='pln'><span class='key'>else</span><span class='op'>:</span><span class="strut"> </span></p>
-<p class='stm mis'> <span class='nam'>h</span> <span class='op'>=</span> <span class='num'>4</span><span class="strut"> </span></p>
+<p class='pln'><span class='com'># A test file for HTML reporting by coverage.</span><span class='strut'> </span></p>
+<p class='pln'><span class='strut'> </span></p>
+<p class='stm run hide'><span class='key'>import</span> <span class='nam'>other</span><span class='strut'> </span></p>
+<p class='pln'><span class='strut'> </span></p>
+<p class='stm run hide'><span class='key'>if</span> <span class='num'>1</span> <span class='op'><</span> <span class='num'>2</span><span class='op'>:</span><span class='strut'> </span></p>
+<p class='stm run hide'> <span class='nam'>h</span> <span class='op'>=</span> <span class='num'>3</span><span class='strut'> </span></p>
+<p class='pln'><span class='key'>else</span><span class='op'>:</span><span class='strut'> </span></p>
+<p class='stm mis'> <span class='nam'>h</span> <span class='op'>=</span> <span class='num'>4</span><span class='strut'> </span></p>
</td>
</tr>
diff --git a/test/farm/html/gold_other/index.html b/test/farm/html/gold_other/index.html index 3e41afa..cdcf59f 100644 --- a/test/farm/html/gold_other/index.html +++ b/test/farm/html/gold_other/index.html @@ -1,67 +1,90 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
-<head>
-<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
-<title>Coverage report</title>
-<link rel='stylesheet' href='style.css' type='text/css'>
-</head>
-<body>
+ <head>
+ <meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
+ <title>Coverage report</title>
+ <link rel='stylesheet' href='style.css' type='text/css'>
+ <script type='text/javascript' src='jquery-1.3.2.min.js'></script>
+ <script type='text/javascript' src='jquery.tablesorter.min.js'></script>
+ </head>
+ <body>
-<div id='header'>
- <div class='content'>
- <h1>Coverage report:
- <span class='pc_cov'>80%</span>
- </h1>
- </div>
-</div>
+ <div id='header'>
+ <div class='content'>
+ <h1>Coverage report:
+ <span class='pc_cov'>80%</span>
+ </h1>
+ </div>
+ </div>
-<div id='index'>
-<table class='index'>
-<tr class='tablehead'>
- <th class='name'>Module</th>
- <th>statements</th>
- <th>run</th>
- <th>excluded</th>
-
- <th>coverage</th>
-</tr>
+ <div id='index'>
+ <table class='index'>
+ <thead>
+
+ <tr class='tablehead' title='Click to sort'>
+ <th class='name left'>Module</th>
+ <th>statements</th>
+ <th>run</th>
+ <th>excluded</th>
+
+ <th class='right'>coverage</th>
+ </tr>
+ </thead>
+
+ <tfoot>
+ <tr class='total'>
+ <td class='name left'>Total</td>
+ <td>5</td>
+ <td>4</td>
+ <td>0</td>
+
+ <td class='right'>80%</td>
+ </tr>
+ </tfoot>
+ <tbody>
+
+ <tr class='file'>
+ <td class='name left'><a href='_ned_coverage_trunk_test_farm_html_othersrc_other.html'>c:\ned\coverage\trunk\test\farm\html\othersrc\other</a></td>
+ <td>1</td>
+ <td>1</td>
+ <td>0</td>
+
+ <td class='right'>100%</td>
+ </tr>
+
+ <tr class='file'>
+ <td class='name left'><a href='here.html'>here</a></td>
+ <td>4</td>
+ <td>3</td>
+ <td>0</td>
+
+ <td class='right'>75%</td>
+ </tr>
+
+ </tbody>
+ </table>
+ </div>
-<tr class='file'>
- <td class='name'><a href='_ned_coverage_trunk_test_farm_html_othersrc_other.html'>c:\ned\coverage\trunk\test\farm\html\othersrc\other</a></td>
- <td>1</td>
- <td>1</td>
- <td>0</td>
-
- <td>100%</td>
-</tr>
+ <div id='footer'>
+ <div class='content'>
+ <p>
+ <a class='nav' href='http://nedbatchelder.com/code/coverage'>coverage.py v3.2b3</a>
+ </p>
+ </div>
+ </div>
-<tr class='file'>
- <td class='name'><a href='here.html'>here</a></td>
- <td>4</td>
- <td>3</td>
- <td>0</td>
-
- <td>75%</td>
-</tr>
-
-<tr class='total'>
-<td class='name'>Total</td>
-<td>5</td>
-<td>4</td>
-<td>0</td>
-
-<td>80%</td>
-</tr>
-</table>
-</div>
-
-<div id='footer'>
- <div class='content'>
- <p>
- <a class='nav' href='http://nedbatchelder.com/code/coverage'>coverage.py v3.2a1</a>
- </p>
- </div>
-</div>
-
-</body>
+ <script type="text/javascript" charset="utf-8">
+ jQuery(function() {
+ jQuery("table.index").tablesorter({
+ headers: {
+ 0: { sorter:'text' },
+ 1: { sorter:'digit' },
+ 2: { sorter:'digit' },
+ 3: { sorter:'digit' },
+ 4: { sorter:'percent' },
+ }
+ });
+ });
+ </script>
+ </body>
</html>
diff --git a/test/farm/html/gold_other/jquery.tablesorter.min.js b/test/farm/html/gold_other/jquery.tablesorter.min.js new file mode 100644 index 0000000..64c7007 --- /dev/null +++ b/test/farm/html/gold_other/jquery.tablesorter.min.js @@ -0,0 +1,2 @@ + +(function($){$.extend({tablesorter:new function(){var parsers=[],widgets=[];this.defaults={cssHeader:"header",cssAsc:"headerSortUp",cssDesc:"headerSortDown",sortInitialOrder:"asc",sortMultiSortKey:"shiftKey",sortForce:null,sortAppend:null,textExtraction:"simple",parsers:{},widgets:[],widgetZebra:{css:["even","odd"]},headers:{},widthFixed:false,cancelSelection:true,sortList:[],headerList:[],dateFormat:"us",decimal:'.',debug:false};function benchmark(s,d){log(s+","+(new Date().getTime()-d.getTime())+"ms");}this.benchmark=benchmark;function log(s){if(typeof console!="undefined"&&typeof console.debug!="undefined"){console.log(s);}else{alert(s);}}function buildParserCache(table,$headers){if(table.config.debug){var parsersDebug="";}var rows=table.tBodies[0].rows;if(table.tBodies[0].rows[0]){var list=[],cells=rows[0].cells,l=cells.length;for(var i=0;i<l;i++){var p=false;if($.metadata&&($($headers[i]).metadata()&&$($headers[i]).metadata().sorter)){p=getParserById($($headers[i]).metadata().sorter);}else if((table.config.headers[i]&&table.config.headers[i].sorter)){p=getParserById(table.config.headers[i].sorter);}if(!p){p=detectParserForColumn(table,cells[i]);}if(table.config.debug){parsersDebug+="column:"+i+" parser:"+p.id+"\n";}list.push(p);}}if(table.config.debug){log(parsersDebug);}return list;};function detectParserForColumn(table,node){var l=parsers.length;for(var i=1;i<l;i++){if(parsers[i].is($.trim(getElementText(table.config,node)),table,node)){return parsers[i];}}return parsers[0];}function getParserById(name){var l=parsers.length;for(var i=0;i<l;i++){if(parsers[i].id.toLowerCase()==name.toLowerCase()){return parsers[i];}}return false;}function buildCache(table){if(table.config.debug){var cacheTime=new Date();}var totalRows=(table.tBodies[0]&&table.tBodies[0].rows.length)||0,totalCells=(table.tBodies[0].rows[0]&&table.tBodies[0].rows[0].cells.length)||0,parsers=table.config.parsers,cache={row:[],normalized:[]};for(var i=0;i<totalRows;++i){var c=table.tBodies[0].rows[i],cols=[];cache.row.push($(c));for(var j=0;j<totalCells;++j){cols.push(parsers[j].format(getElementText(table.config,c.cells[j]),table,c.cells[j]));}cols.push(i);cache.normalized.push(cols);cols=null;};if(table.config.debug){benchmark("Building cache for "+totalRows+" rows:",cacheTime);}return cache;};function getElementText(config,node){if(!node)return"";var t="";if(config.textExtraction=="simple"){if(node.childNodes[0]&&node.childNodes[0].hasChildNodes()){t=node.childNodes[0].innerHTML;}else{t=node.innerHTML;}}else{if(typeof(config.textExtraction)=="function"){t=config.textExtraction(node);}else{t=$(node).text();}}return t;}function appendToTable(table,cache){if(table.config.debug){var appendTime=new Date()}var c=cache,r=c.row,n=c.normalized,totalRows=n.length,checkCell=(n[0].length-1),tableBody=$(table.tBodies[0]),rows=[];for(var i=0;i<totalRows;i++){rows.push(r[n[i][checkCell]]);if(!table.config.appender){var o=r[n[i][checkCell]];var l=o.length;for(var j=0;j<l;j++){tableBody[0].appendChild(o[j]);}}}if(table.config.appender){table.config.appender(table,rows);}rows=null;if(table.config.debug){benchmark("Rebuilt table:",appendTime);}applyWidget(table);setTimeout(function(){$(table).trigger("sortEnd");},0);};function buildHeaders(table){if(table.config.debug){var time=new Date();}var meta=($.metadata)?true:false,tableHeadersRows=[];for(var i=0;i<table.tHead.rows.length;i++){tableHeadersRows[i]=0;};$tableHeaders=$("thead th",table);$tableHeaders.each(function(index){this.count=0;this.column=index;this.order=formatSortingOrder(table.config.sortInitialOrder);if(checkHeaderMetadata(this)||checkHeaderOptions(table,index))this.sortDisabled=true;if(!this.sortDisabled){$(this).addClass(table.config.cssHeader);}table.config.headerList[index]=this;});if(table.config.debug){benchmark("Built headers:",time);log($tableHeaders);}return $tableHeaders;};function checkCellColSpan(table,rows,row){var arr=[],r=table.tHead.rows,c=r[row].cells;for(var i=0;i<c.length;i++){var cell=c[i];if(cell.colSpan>1){arr=arr.concat(checkCellColSpan(table,headerArr,row++));}else{if(table.tHead.length==1||(cell.rowSpan>1||!r[row+1])){arr.push(cell);}}}return arr;};function checkHeaderMetadata(cell){if(($.metadata)&&($(cell).metadata().sorter===false)){return true;};return false;}function checkHeaderOptions(table,i){if((table.config.headers[i])&&(table.config.headers[i].sorter===false)){return true;};return false;}function applyWidget(table){var c=table.config.widgets;var l=c.length;for(var i=0;i<l;i++){getWidgetById(c[i]).format(table);}}function getWidgetById(name){var l=widgets.length;for(var i=0;i<l;i++){if(widgets[i].id.toLowerCase()==name.toLowerCase()){return widgets[i];}}};function formatSortingOrder(v){if(typeof(v)!="Number"){i=(v.toLowerCase()=="desc")?1:0;}else{i=(v==(0||1))?v:0;}return i;}function isValueInArray(v,a){var l=a.length;for(var i=0;i<l;i++){if(a[i][0]==v){return true;}}return false;}function setHeadersCss(table,$headers,list,css){$headers.removeClass(css[0]).removeClass(css[1]);var h=[];$headers.each(function(offset){if(!this.sortDisabled){h[this.column]=$(this);}});var l=list.length;for(var i=0;i<l;i++){h[list[i][0]].addClass(css[list[i][1]]);}}function fixColumnWidth(table,$headers){var c=table.config;if(c.widthFixed){var colgroup=$('<colgroup>');$("tr:first td",table.tBodies[0]).each(function(){colgroup.append($('<col>').css('width',$(this).width()));});$(table).prepend(colgroup);};}function updateHeaderSortCount(table,sortList){var c=table.config,l=sortList.length;for(var i=0;i<l;i++){var s=sortList[i],o=c.headerList[s[0]];o.count=s[1];o.count++;}}function multisort(table,sortList,cache){if(table.config.debug){var sortTime=new Date();}var dynamicExp="var sortWrapper = function(a,b) {",l=sortList.length;for(var i=0;i<l;i++){var c=sortList[i][0];var order=sortList[i][1];var s=(getCachedSortType(table.config.parsers,c)=="text")?((order==0)?"sortText":"sortTextDesc"):((order==0)?"sortNumeric":"sortNumericDesc");var e="e"+i;dynamicExp+="var "+e+" = "+s+"(a["+c+"],b["+c+"]); ";dynamicExp+="if("+e+") { return "+e+"; } ";dynamicExp+="else { ";}var orgOrderCol=cache.normalized[0].length-1;dynamicExp+="return a["+orgOrderCol+"]-b["+orgOrderCol+"];";for(var i=0;i<l;i++){dynamicExp+="}; ";}dynamicExp+="return 0; ";dynamicExp+="}; ";eval(dynamicExp);cache.normalized.sort(sortWrapper);if(table.config.debug){benchmark("Sorting on "+sortList.toString()+" and dir "+order+" time:",sortTime);}return cache;};function sortText(a,b){return((a<b)?-1:((a>b)?1:0));};function sortTextDesc(a,b){return((b<a)?-1:((b>a)?1:0));};function sortNumeric(a,b){return a-b;};function sortNumericDesc(a,b){return b-a;};function getCachedSortType(parsers,i){return parsers[i].type;};this.construct=function(settings){return this.each(function(){if(!this.tHead||!this.tBodies)return;var $this,$document,$headers,cache,config,shiftDown=0,sortOrder;this.config={};config=$.extend(this.config,$.tablesorter.defaults,settings);$this=$(this);$headers=buildHeaders(this);this.config.parsers=buildParserCache(this,$headers);cache=buildCache(this);var sortCSS=[config.cssDesc,config.cssAsc];fixColumnWidth(this);$headers.click(function(e){$this.trigger("sortStart");var totalRows=($this[0].tBodies[0]&&$this[0].tBodies[0].rows.length)||0;if(!this.sortDisabled&&totalRows>0){var $cell=$(this);var i=this.column;this.order=this.count++%2;if(!e[config.sortMultiSortKey]){config.sortList=[];if(config.sortForce!=null){var a=config.sortForce;for(var j=0;j<a.length;j++){if(a[j][0]!=i){config.sortList.push(a[j]);}}}config.sortList.push([i,this.order]);}else{if(isValueInArray(i,config.sortList)){for(var j=0;j<config.sortList.length;j++){var s=config.sortList[j],o=config.headerList[s[0]];if(s[0]==i){o.count=s[1];o.count++;s[1]=o.count%2;}}}else{config.sortList.push([i,this.order]);}};setTimeout(function(){setHeadersCss($this[0],$headers,config.sortList,sortCSS);appendToTable($this[0],multisort($this[0],config.sortList,cache));},1);return false;}}).mousedown(function(){if(config.cancelSelection){this.onselectstart=function(){return false};return false;}});$this.bind("update",function(){this.config.parsers=buildParserCache(this,$headers);cache=buildCache(this);}).bind("sorton",function(e,list){$(this).trigger("sortStart");config.sortList=list;var sortList=config.sortList;updateHeaderSortCount(this,sortList);setHeadersCss(this,$headers,sortList,sortCSS);appendToTable(this,multisort(this,sortList,cache));}).bind("appendCache",function(){appendToTable(this,cache);}).bind("applyWidgetId",function(e,id){getWidgetById(id).format(this);}).bind("applyWidgets",function(){applyWidget(this);});if($.metadata&&($(this).metadata()&&$(this).metadata().sortlist)){config.sortList=$(this).metadata().sortlist;}if(config.sortList.length>0){$this.trigger("sorton",[config.sortList]);}applyWidget(this);});};this.addParser=function(parser){var l=parsers.length,a=true;for(var i=0;i<l;i++){if(parsers[i].id.toLowerCase()==parser.id.toLowerCase()){a=false;}}if(a){parsers.push(parser);};};this.addWidget=function(widget){widgets.push(widget);};this.formatFloat=function(s){var i=parseFloat(s);return(isNaN(i))?0:i;};this.formatInt=function(s){var i=parseInt(s);return(isNaN(i))?0:i;};this.isDigit=function(s,config){var DECIMAL='\\'+config.decimal;var exp='/(^[+]?0('+DECIMAL+'0+)?$)|(^([-+]?[1-9][0-9]*)$)|(^([-+]?((0?|[1-9][0-9]*)'+DECIMAL+'(0*[1-9][0-9]*)))$)|(^[-+]?[1-9]+[0-9]*'+DECIMAL+'0+$)/';return RegExp(exp).test($.trim(s));};this.clearTableBody=function(table){if($.browser.msie){function empty(){while(this.firstChild)this.removeChild(this.firstChild);}empty.apply(table.tBodies[0]);}else{table.tBodies[0].innerHTML="";}};}});$.fn.extend({tablesorter:$.tablesorter.construct});var ts=$.tablesorter;ts.addParser({id:"text",is:function(s){return true;},format:function(s){return $.trim(s.toLowerCase());},type:"text"});ts.addParser({id:"digit",is:function(s,table){var c=table.config;return $.tablesorter.isDigit(s,c);},format:function(s){return $.tablesorter.formatFloat(s);},type:"numeric"});ts.addParser({id:"currency",is:function(s){return/^[£$€?.]/.test(s);},format:function(s){return $.tablesorter.formatFloat(s.replace(new RegExp(/[^0-9.]/g),""));},type:"numeric"});ts.addParser({id:"ipAddress",is:function(s){return/^\d{2,3}[\.]\d{2,3}[\.]\d{2,3}[\.]\d{2,3}$/.test(s);},format:function(s){var a=s.split("."),r="",l=a.length;for(var i=0;i<l;i++){var item=a[i];if(item.length==2){r+="0"+item;}else{r+=item;}}return $.tablesorter.formatFloat(r);},type:"numeric"});ts.addParser({id:"url",is:function(s){return/^(https?|ftp|file):\/\/$/.test(s);},format:function(s){return jQuery.trim(s.replace(new RegExp(/(https?|ftp|file):\/\//),''));},type:"text"});ts.addParser({id:"isoDate",is:function(s){return/^\d{4}[\/-]\d{1,2}[\/-]\d{1,2}$/.test(s);},format:function(s){return $.tablesorter.formatFloat((s!="")?new Date(s.replace(new RegExp(/-/g),"/")).getTime():"0");},type:"numeric"});ts.addParser({id:"percent",is:function(s){return/\%$/.test($.trim(s));},format:function(s){return $.tablesorter.formatFloat(s.replace(new RegExp(/%/g),""));},type:"numeric"});ts.addParser({id:"usLongDate",is:function(s){return s.match(new RegExp(/^[A-Za-z]{3,10}\.? [0-9]{1,2}, ([0-9]{4}|'?[0-9]{2}) (([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\s(AM|PM)))$/));},format:function(s){return $.tablesorter.formatFloat(new Date(s).getTime());},type:"numeric"});ts.addParser({id:"shortDate",is:function(s){return/\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}/.test(s);},format:function(s,table){var c=table.config;s=s.replace(/\-/g,"/");if(c.dateFormat=="us"){s=s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/,"$3/$1/$2");}else if(c.dateFormat=="uk"){s=s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/,"$3/$2/$1");}else if(c.dateFormat=="dd/mm/yy"||c.dateFormat=="dd-mm-yy"){s=s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{2})/,"$1/$2/$3");}return $.tablesorter.formatFloat(new Date(s).getTime());},type:"numeric"});ts.addParser({id:"time",is:function(s){return/^(([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\s(am|pm)))$/.test(s);},format:function(s){return $.tablesorter.formatFloat(new Date("2000/01/01 "+s).getTime());},type:"numeric"});ts.addParser({id:"metadata",is:function(s){return false;},format:function(s,table,cell){var c=table.config,p=(!c.parserMetadataName)?'sortValue':c.parserMetadataName;return $(cell).metadata()[p];},type:"numeric"});ts.addWidget({id:"zebra",format:function(table){if(table.config.debug){var time=new Date();}$("tr:visible",table.tBodies[0]).filter(':even').removeClass(table.config.widgetZebra.css[1]).addClass(table.config.widgetZebra.css[0]).end().filter(':odd').removeClass(table.config.widgetZebra.css[0]).addClass(table.config.widgetZebra.css[1]);if(table.config.debug){$.tablesorter.benchmark("Applying Zebra widget",time);}}});})(jQuery);
\ No newline at end of file diff --git a/test/farm/html/gold_other/style.css b/test/farm/html/gold_other/style.css index 65a2790..dd6c991 100644 --- a/test/farm/html/gold_other/style.css +++ b/test/farm/html/gold_other/style.css @@ -2,14 +2,14 @@ /* Page-wide styles */ html, body, h1, h2, h3, p, td, th { margin: 0; - padding: 0; - border: 0; - outline: 0; - font-weight: inherit; - font-style: inherit; - font-size: 100%; - font-family: inherit; - vertical-align: baseline; + padding: 0; + border: 0; + outline: 0; + font-weight: inherit; + font-style: inherit; + font-size: 100%; + font-family: inherit; + vertical-align: baseline; } /* Set baseline grid to 16 pt. */ @@ -134,16 +134,16 @@ td.text { } .text span.annotate { - font-family: georgia; - font-style: italic; - color: #666; - float: right; - padding-right: .5em; - } + font-family: georgia; + font-style: italic; + color: #666; + float: right; + padding-right: .5em; + } .text p.hide span.annotate { - display: none; - } - + display: none; + } + /* Syntax coloring */ .text .com { color: green; @@ -161,14 +161,28 @@ td.text { /* index styles */ #index td, #index th { text-align: right; - width: 6em; - padding: .25em 0; + width: 5em; + padding: .25em .5em; border-bottom: 1px solid #eee; } #index th { font-style: italic; color: #333; border-bottom: 1px solid #ccc; + cursor: pointer; + } +#index th:hover { + background: #eee; + border-bottom: 1px solid #999; + } +#index td.left, #index th.left { + padding-left: 0; + } +#index td.right, #index th.right { + padding-right: 0; + } +#index th.headerSortDown, #index th.headerSortUp { + border-bottom: 1px solid #000; } #index td.name, #index th.name { text-align: left; @@ -183,13 +197,12 @@ td.text { color: #000; } #index tr.total { - font-weight: bold; } #index tr.total td { - padding: .25em 0; + font-weight: bold; border-top: 1px solid #ccc; border-bottom: none; } #index tr.file:hover { - background: #eeeeee; - } + background: #eeeeee; + } diff --git a/test/stress_phystoken.txt b/test/stress_phystoken.txt index bd6a453..7e2f285 100644 --- a/test/stress_phystoken.txt +++ b/test/stress_phystoken.txt @@ -19,6 +19,17 @@ fake_back = """\ ouch """ +# Lots of difficulty happens with code like: +# +# fake_back = """\ +# ouch +# """ +# +# Ugh, the edge cases... + +# What about a comment like this\ +"what's this string doing here?" + class C(object): def there(): this = 5 + \ @@ -29,6 +40,11 @@ class C(object): cont1 = "one line of text" + \ "another line of text" +a_long_string = + "part 1" \ + "2" \ + "3 is longer" + def hello(): print("Hello world!") diff --git a/test/test_arcs.py b/test/test_arcs.py index dea3700..9b2c386 100644 --- a/test/test_arcs.py +++ b/test/test_arcs.py @@ -113,6 +113,29 @@ class SimpleArcTest(CoverageTest): arcz=".1 16 67 7. .2 23 24 3. 45 5.", arcz_missing="" ) + def XXX_dont_confuse_exit_and_else(self): + self.check_coverage("""\ + def foo(): + if foo: + a = 3 + else: + a = 5 + return a + assert foo() == 3 + """, + arcz=".1 17 7. .2 23 36 25 56 6.", arcz_missing="25 56" + ) + self.check_coverage("""\ + def foo(): + if foo: + a = 3 + else: + a = 5 + foo() + """, + arcz=".1 16 6. .2 23 3. 25 5.", arcz_missing="25 5." + ) + class LoopArcTest(CoverageTest): """Arc-measuring tests involving loops.""" diff --git a/test/test_farm.py b/test/test_farm.py index bc1d7a3..78b9354 100644 --- a/test/test_farm.py +++ b/test/test_farm.py @@ -226,7 +226,10 @@ class FarmTestCase(object): # print "%d %d" % (big, little) # print "Left: ---\n%s\n-----\n%s" % (left, right) wrong_size.append(f) - assert not wrong_size, "File sizes differ: %s" % wrong_size + assert not wrong_size, ( + "File sizes differ between %s and %s: %s" % ( + dir1, dir2, wrong_size + )) else: # filecmp only compares in binary mode, but we want text mode. So # look through the list of different files, and compare them diff --git a/test/test_parser.py b/test/test_parser.py index 3d5726d..201d532 100644 --- a/test/test_parser.py +++ b/test/test_parser.py @@ -16,7 +16,7 @@ class ParserTest(CoverageTest): def parse_source(self, text): """Parse `text` as source, and return the `CodeParser` used.""" text = textwrap.dedent(text) - cp = CodeParser(text) + cp = CodeParser(text, exclude="nocover") cp.parse_source() return cp @@ -52,4 +52,45 @@ class ParserTest(CoverageTest): self.assertEqual(cp.exit_counts(), { 1: 1, 2:1, 3:1, 4:1, 5:1, 6:1, 7:1, 8:1, 9:1 }) -
\ No newline at end of file + + def test_excluded_classes(self): + cp = self.parse_source("""\ + class Foo: + def __init__(self): + pass + + if 0: # nocover + class Bar: + pass + """) + self.assertEqual(cp.exit_counts(), { + 1:1, 2:1, 3:1 + }) + + def XXX_missing_branch_to_excluded_code(self): + cp = self.parse_source("""\ + if fooey: + a = 2 + else: # nocover + a = 4 + b = 5 + """) + self.assertEqual(cp.exit_counts(), { 1:1, 2:1, 5:1 }) + cp = self.parse_source("""\ + def foo(): + if fooey: + a = 3 + else: + a = 5 + b = 6 + """) + self.assertEqual(cp.exit_counts(), { 1:1, 2:2, 3:1, 5:1, 6:1 }) + cp = self.parse_source("""\ + def foo(): + if fooey: + a = 3 + else: # nocover + a = 5 + b = 6 + """) + self.assertEqual(cp.exit_counts(), { 1:13, 2:1, 6:1 }) diff --git a/test/test_phystokens.py b/test/test_phystokens.py index fa0fa04..fb0b553 100644 --- a/test/test_phystokens.py +++ b/test/test_phystokens.py @@ -38,10 +38,7 @@ class PhysTokensTest(CoverageTest): # before comparing. source = re.sub("(?m)[ \t]+$", "", source) tokenized = re.sub("(?m)[ \t]+$", "", tokenized) - #if source != tokenized: - # open("0.py", "w").write(source) - # open("1.py", "w").write(tokenized) - self.assertEqual(source, tokenized) + self.assert_multiline_equal(source, tokenized) def check_file_tokenization(self, fname): """Use the contents of `fname` for `check_tokenization`.""" diff --git a/test/test_templite.py b/test/test_templite.py index 8cb2586..35c1df5 100644 --- a/test/test_templite.py +++ b/test/test_templite.py @@ -191,6 +191,18 @@ class TempliteTest(unittest.TestCase): "@a0b0c0a1b1c1a2b2c2!" ) - + def test_exception_during_evaluation(self): + # TypeError: Couldn't evaluate {{ foo.bar.baz }}: + # 'NoneType' object is unsubscriptable + self.assertRaises(TypeError, self.try_render, + "Hey {{foo.bar.baz}} there", {'foo': None}, "Hey ??? there" + ) + + def test_bogus_tag_syntax(self): + self.assertRaises(SyntaxError, self.try_render, + "Huh: {% bogus %}!!{% endbogus %}??", {}, "" + ) + + if __name__ == '__main__': unittest.main() diff --git a/test/test_testing.py b/test/test_testing.py index 1e22202..5d1ac0b 100644 --- a/test/test_testing.py +++ b/test/test_testing.py @@ -28,3 +28,8 @@ class TestingTest(CoverageTest): "hello there", "^hello$" ) + def test_assert_multiline_equal(self): + self.assert_multiline_equal("hello", "hello") + self.assertRaises(AssertionError, self.assert_matches, + "hello there", "Hello there" + ) |
