Giter Site home page Giter Site logo

Comments (5)

nedbat avatar nedbat commented on June 27, 2024

OK, I've applied this change (<<changeset e6f11f28504f (bb)>>). I suspect that cu.name is not always the right thing to use, but it certainly works better than before.

from coveragepy.

nedbat avatar nedbat commented on June 27, 2024

Original comment by Tomi Kallio (Bitbucket: tomikall, GitHub: tomikall)


cjulien's proposed fix for the "filename" attribute does the trick, at least Hudson's Cobertura plugin is able to find the right set of source files after applying the change. Here's a diff against the latest xmlreport.py:

diff -r [3e9229efc215 (bb)](https://bitbucket.org/ned/coveragepy/commits/3e9229efc215) coverage/xmlreport.py
--- a/coverage/xmlreport.py	Wed Oct 28 08:39:31 2009 -0400
+++ b/coverage/xmlreport.py	Thu Oct 29 00:51:25 2009 +0200
@@ -97,7 +97,8 @@
         xclass.appendChild(xlines)
         className = fname.replace('.', '_')
         xclass.setAttribute("name", className)
-        xclass.setAttribute("filename", os.path.split(cu.filename)[1])
+        ext = os.path.splitext(cu.filename)[1]
+        xclass.setAttribute("filename", cu.name + ext)
         xclass.setAttribute("complexity", "0.0")
 
         # For each statement, create an XML 'line' element.

What the Cobertura plugin wants is a relative path to a source file from the directory where coverage was run. In Python 2.6, the right path for the "filename" attribute can also be got from "os.path.relpath(cu.filename)".

from coveragepy.

nedbat avatar nedbat commented on June 27, 2024

Original comment by cjulien (Bitbucket: cjulien, GitHub: cjulien)


I test the xml output, and i was happy, my code seemed to be full covered.... but it wasn't.
In the xml I found this :

<line branch="false" hits="1" number="37"/>
<line branch="false" number="38"/>

the line 37 was effectively covered, the 38 was not... with a

<line branch="false" hits="0" number="38"/>

it will really show the uncovered lines :)
Here is my proposition for correction :

--- xmlreport_orig.py
+++ xmlreport.py
@@ -64,7 +65,8 @@
                     # recorded here.
                     if not line in missing:
                         l.setAttribute("hits", str(1))
-
+                    else:
+                        l.setAttribute("hits", str(0))
                     # Q: can we get info about whether this statement
                     # is a branch?  If so, that data should be
                     # used here.                    

Another issue in the xml is the filename field :

<class branch-rate="0.0" complexity="0.0" filename="test/__init__" line-rate="1.0" name="__init__">

the filename shown here is the filename without extension....but this is not my filename, it is init.py !

I try to correct this in this way :

--- xmlreport_orig.py
+++ xmlreport.py
@@ -40,7 +40,8 @@
             # Create the 'lines' and 'package' XML elements, which
             # are populated later.  Note that a package == a directory.
             dirname, fname = os.path.split(cu.name)
+           _, ext = os.path.splitext(cu.filename)
             dirname = dirname or '.'
             package = packages.setdefault(
                 dirname, [ doc.createElement("package"), {}, 0, 0, 0, 0 ] )
@@ -48,7 +49,7 @@
             c.appendChild(lines)
             className = fname.replace('.', '_')
             c.setAttribute("name", className)
-            c.setAttribute("filename", cu.name)
+            c.setAttribute("filename", cu.name + ext)
             c.setAttribute("complexity", "0.0")
 
             try:

Hope it will be usefull :)

from coveragepy.

nedbat avatar nedbat commented on June 27, 2024

This feature is now checked in (as of <<changeset df70d70a32b2 (bb)>>), ready for testing.

from coveragepy.

nedbat avatar nedbat commented on June 27, 2024

I have every intention of merging that work back into the coverage.py trunk. I just need to find a little time...

from coveragepy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.