Commits

Ned Batchelder committed 4f9bbbf

A little explanation of the partial branch annotations in the HTML report.

  • Participants
  • Parent commits 7e62995

Comments (0)

Files changed (5)

File coverage/html.py

             lineno += 1     # 1-based line numbers.
             # Figure out how to mark this line.
             line_class = ""
-            annotate = ""
+            annotate_html = ""
+            annotate_title = ""
             if lineno in analysis.statements:
                 line_class += " stm"
             if lineno in analysis.excluded:
                         annlines.append("exit")
                     else:
                         annlines.append(str(b))
-                annotate = " ".join(annlines)
+                annotate_html = "   ".join(annlines)
+                if len(annlines) > 1:
+                    annotate_title = "no jumps to these line numbers"
+                elif len(annlines) == 1:
+                    annotate_title = "no jump to this line number"
             elif lineno in analysis.statements:
                 line_class += c_run
             
                 'html': html,
                 'number': lineno,
                 'class': line_class.strip() or "pln",
-                'annotate': annotate,
+                'annotate': annotate_html,
+                'annotate_title': annotate_title,
             })
 
         # Write the HTML page for this file.

File coverage/htmlfiles/pyfile.html

 </td>
 <td class='text' valign='top'>
     {% for line in lines %}
-    <p class='{{line.class}}'>{% if line.annotate %}<span class='annotate'>{{line.annotate}}</span>{% endif %}{{line.html}}<span class='strut'>&nbsp;</span></p>
+    <p class='{{line.class}}'>{% if line.annotate %}<span class='annotate' title='{{line.annotate_title}}'>{{line.annotate}}</span>{% endif %}{{line.html}}<span class='strut'>&nbsp;</span></p>
     {% endfor %}
 </td>
 </tr>

File test/farm/html/gold_b_branch/b.html

 <div id='header'>
     <div class='content'>
         <h1>Coverage for <b>b</b> :
-            <span class='pc_cov'>77%</span>
+            <span class='pc_cov'>76%</span>
         </h1>
         <h2 class='stats'>
-            9 statements
-            <span class='run hide_run' onclick='toggle_lines(this, "run")'>8 run</span>
+            16 statements
+            <span class='run hide_run' onclick='toggle_lines(this, "run")'>14 run</span>
             <span class='exc' onclick='toggle_lines(this, "exc")'>0 excluded</span>
-            <span class='mis' onclick='toggle_lines(this, "mis")'>1 missing</span>
+            <span class='mis' onclick='toggle_lines(this, "mis")'>2 missing</span>
             
-                <span class='par run hide_run' onclick='toggle_lines(this, "par")'>2 partial</span>
+                <span class='par run hide_run' onclick='toggle_lines(this, "par")'>3 partial</span>
             
         </h2>
     </div>
 <p class='pln'>1</p>
 <p class='pln'>2</p>
 <p class='stm run hide_run'>3</p>
-<p class='stm par run hide_run'>4</p>
-<p class='pln'>5</p>
+<p class='pln'>4</p>
+<p class='stm par run hide_run'>5</p>
 <p class='stm run hide_run'>6</p>
 <p class='pln'>7</p>
 <p class='stm mis'>8</p>
 <p class='stm run hide_run'>10</p>
 <p class='pln'>11</p>
 <p class='stm run hide_run'>12</p>
-<p class='stm par run hide_run'>13</p>
-<p class='stm run hide_run'>14</p>
-<p class='pln'>15</p>
-<p class='stm run hide_run'>16</p>
+<p class='pln'>13</p>
+<p class='stm par run hide_run'>14</p>
+<p class='stm run hide_run'>15</p>
+<p class='pln'>16</p>
+<p class='stm run hide_run'>17</p>
+<p class='pln'>18</p>
+<p class='stm run hide_run'>19</p>
+<p class='pln'>20</p>
+<p class='stm par run hide_run'>21</p>
+<p class='stm run hide_run'>22</p>
+<p class='stm run hide_run'>23</p>
+<p class='pln'>24</p>
+<p class='stm mis'>25</p>
+<p class='stm run hide_run'>26</p>
+<p class='pln'>27</p>
+<p class='stm run hide_run'>28</p>
     
 </td>
 <td class='text' valign='top'>
 <p class='pln'><span class='com'># A test file for HTML reporting by coverage.</span><span class='strut'>&nbsp;</span></p>
 <p class='pln'><span class='strut'>&nbsp;</span></p>
 <p class='stm run hide_run'><span class='key'>def</span> <span class='nam'>one</span><span class='op'>(</span><span class='nam'>x</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
-<p class='stm par run hide_run'><span class='annotate'>8</span>&nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>x</span> <span class='op'>&lt;</span> <span class='num'>2</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
-<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Needed a &lt; to look at HTML entities.</span><span class='strut'>&nbsp;</span></p>
+<p class='pln'>&nbsp; &nbsp; <span class='com'># This will be a branch that misses the else.</span><span class='strut'>&nbsp;</span></p>
+<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>8</span>&nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>x</span> <span class='op'>&lt;</span> <span class='num'>2</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
 <p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>a</span> <span class='op'>=</span> <span class='num'>3</span><span class='strut'>&nbsp;</span></p>
 <p class='pln'>&nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
 <p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>a</span> <span class='op'>=</span> <span class='num'>4</span><span class='strut'>&nbsp;</span></p>
 <p class='stm run hide_run'><span class='nam'>one</span><span class='op'>(</span><span class='num'>1</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
 <p class='pln'><span class='strut'>&nbsp;</span></p>
 <p class='stm run hide_run'><span class='key'>def</span> <span class='nam'>two</span><span class='op'>(</span><span class='nam'>x</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
-<p class='stm par run hide_run'><span class='annotate'>exit</span>&nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>x</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
+<p class='pln'>&nbsp; &nbsp; <span class='com'># A missed else that branches to &quot;exit&quot;</span><span class='strut'>&nbsp;</span></p>
+<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>exit</span>&nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>x</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
 <p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>a</span> <span class='op'>=</span> <span class='num'>5</span><span class='strut'>&nbsp;</span></p>
 <p class='pln'><span class='strut'>&nbsp;</span></p>
 <p class='stm run hide_run'><span class='nam'>two</span><span class='op'>(</span><span class='num'>1</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
+<p class='pln'><span class='strut'>&nbsp;</span></p>
+<p class='stm run hide_run'><span class='key'>def</span> <span class='nam'>three_way</span><span class='op'>(</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
+<p class='pln'>&nbsp; &nbsp; <span class='com'># for-else can be a three-way branch.</span><span class='strut'>&nbsp;</span></p>
+<p class='stm par run hide_run'><span class='annotate' title='no jumps to these line numbers'>25&nbsp;&nbsp; 26</span>&nbsp; &nbsp; <span class='key'>for</span> <span class='nam'>i</span> <span class='key'>in</span> <span class='nam'>range</span><span class='op'>(</span><span class='num'>10</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
+<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>i</span> <span class='op'>==</span> <span class='num'>3</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
+<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>break</span><span class='strut'>&nbsp;</span></p>
+<p class='pln'>&nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
+<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='num'>23</span><span class='strut'>&nbsp;</span></p>
+<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>return</span> <span class='num'>17</span><span class='strut'>&nbsp;</span></p>
+<p class='pln'><span class='strut'>&nbsp;</span></p>
+<p class='stm run hide_run'><span class='nam'>three_way</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
     
 </td>
 </tr>

File test/farm/html/run_b_branch.py

 contains("html_b_branch/b.html",
     "<span class='key'>if</span> <span class='nam'>x</span> <span class='op'>&lt;</span> <span class='num'>2</span>",
     "&nbsp; &nbsp; <span class='nam'>a</span> <span class='op'>=</span> <span class='num'>3</span>",
-    "<span class='pc_cov'>77%</span>",
-    "<span class='annotate'>8</span>",
-    "<span class='annotate'>exit</span>"
+    "<span class='pc_cov'>76%</span>",
+    "<span class='annotate' title='no jump to this line number'>8</span>",
+    "<span class='annotate' title='no jump to this line number'>exit</span>",
+    "<span class='annotate' title='no jumps to these line numbers'>25&nbsp;&nbsp; 26</span>",
     )
 contains("html_b_branch/index.html",
     "<a href='b.html'>b</a>",
-    "<span class='pc_cov'>77%</span>"
+    "<span class='pc_cov'>76%</span>"
     )
 
 clean("html_b_branch")

File test/farm/html/src/b.py

 # A test file for HTML reporting by coverage.
 
 def one(x):
+    # This will be a branch that misses the else.
     if x < 2:
-        # Needed a < to look at HTML entities.
         a = 3
     else:
         a = 4
 one(1)
 
 def two(x):
+    # A missed else that branches to "exit"
     if x:
         a = 5
         
 two(1)
+
+def three_way():
+    # for-else can be a three-way branch.
+    for i in range(10):
+        if i == 3:
+            break
+    else:
+        return 23
+    return 17
+
+three_way()