summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2009-09-30 08:45:39 -0400
committerNed Batchelder <ned@nedbatchelder.com>2009-09-30 08:45:39 -0400
commit4c5448eda225588b705074a68663b9322b54006c (patch)
tree8a786e851dd4e91632d22e420a5c3afb0a47abff
parentefb089e1576eaa9326cce08978f81c25169850f2 (diff)
downloadpython-coveragepy-4c5448eda225588b705074a68663b9322b54006c.tar.gz
Last clean up on the egg-reading code. Fixes issue #25.
-rw-r--r--CHANGES.txt8
-rw-r--r--TODO.txt5
-rw-r--r--coverage/codeunit.py21
3 files changed, 24 insertions, 10 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index b7dda4d..bad5461 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -2,6 +2,14 @@
Change history for Coverage.py
------------------------------
+Next version
+------------
+
+- Source code can now be read from eggs. Thanks, rozza. Fixes `issue 25`_
+
+.. _issue 25: http://bitbucket.org/ned/coveragepy/issue/25
+
+
Version 3.1b1, 27 September 2009
--------------------------------
diff --git a/TODO.txt b/TODO.txt
index 4cdb051..6407692 100644
--- a/TODO.txt
+++ b/TODO.txt
@@ -2,7 +2,10 @@ Coverage TODO
* 3.1
-- Python 3.1 support.
++ Python 3.1 support.
+
+* 3.2
+
- bitvector in trace extension.
diff --git a/coverage/codeunit.py b/coverage/codeunit.py
index d85735d..79ae4f0 100644
--- a/coverage/codeunit.py
+++ b/coverage/codeunit.py
@@ -86,7 +86,6 @@ class CodeUnit:
self.name = n
self.modname = modname
-
def __repr__(self):
return "<CodeUnit name=%r filename=%r>" % (self.name, self.filename)
@@ -129,12 +128,16 @@ class CodeUnit:
def source_file(self):
"""Return an open file for reading the source of the code unit."""
- if not os.path.exists(self.filename):
- source = self.file_locator.get_zip_data(self.filename)
- if source is None:
- raise CoverageException(
- "No source for code %r." % self.filename
- )
+ if os.path.exists(self.filename):
+ # A regular text file: open it.
+ return open(self.filename)
+
+ # Maybe it's in a zip file?
+ source = self.file_locator.get_zip_data(self.filename)
+ if source is not None:
return StringIO(source)
-
- return open(self.filename)
+
+ # Couldn't find source.
+ raise CoverageException(
+ "No source for code %r." % self.filename
+ )