summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2013-10-19 21:52:22 -0400
committerNed Batchelder <ned@nedbatchelder.com>2013-10-19 21:52:22 -0400
commitdfb5405959bbe14ebcf533cd442c41a314b8a4fd (patch)
treee6a78608ef35a0699c3381dda2813e0739d3c47d
parent438f29546437ff235772ad8d3a915c42f7bb2665 (diff)
downloadpython-coveragepy-dfb5405959bbe14ebcf533cd442c41a314b8a4fd.tar.gz
Now I can use decorators.
-rw-r--r--TODO.txt3
-rw-r--r--coverage/parser.py4
-rw-r--r--coverage/results.py20
-rw-r--r--tests/coveragetest.py2
4 files changed, 15 insertions, 14 deletions
diff --git a/TODO.txt b/TODO.txt
index 4dbc664..a134bb4 100644
--- a/TODO.txt
+++ b/TODO.txt
@@ -15,9 +15,10 @@ Key:
- Remove 2.3, 2.4, 2.5 limitations
+ set, sorted, reversed, rpartition
- generator expressions
- - decorators
+ + decorators
- collections.defaultdict
+ .startswith((,))
+ - "with" statements
+ Remove code only run on <2.6
diff --git a/coverage/parser.py b/coverage/parser.py
index 2663bac..0873e7a 100644
--- a/coverage/parser.py
+++ b/coverage/parser.py
@@ -65,13 +65,13 @@ class CodeParser(object):
# Lazily-created ByteParser
self._byte_parser = None
- def _get_byte_parser(self):
+ @property
+ def byte_parser(self):
"""Create a ByteParser on demand."""
if not self._byte_parser:
self._byte_parser = \
ByteParser(text=self.text, filename=self.filename)
return self._byte_parser
- byte_parser = property(_get_byte_parser)
def lines_matching(self, *regexes):
"""Find the lines matching one of a list of regexes.
diff --git a/coverage/results.py b/coverage/results.py
index 6507d56..7ffd66b 100644
--- a/coverage/results.py
+++ b/coverage/results.py
@@ -210,25 +210,26 @@ class Numbers(object):
self.n_partial_branches = n_partial_branches
self.n_missing_branches = n_missing_branches
+ @classmethod
def set_precision(cls, precision):
"""Set the number of decimal places used to report percentages."""
assert 0 <= precision < 10
cls._precision = precision
cls._near0 = 1.0 / 10**precision
cls._near100 = 100.0 - cls._near0
- set_precision = classmethod(set_precision)
- def _get_n_executed(self):
+ @property
+ def n_executed(self):
"""Returns the number of executed statements."""
return self.n_statements - self.n_missing
- n_executed = property(_get_n_executed)
- def _get_n_executed_branches(self):
+ @property
+ def n_executed_branches(self):
"""Returns the number of executed branches."""
return self.n_branches - self.n_missing_branches
- n_executed_branches = property(_get_n_executed_branches)
- def _get_pc_covered(self):
+ @property
+ def pc_covered(self):
"""Returns a single percentage value for coverage."""
if self.n_statements > 0:
pc_cov = (100.0 * (self.n_executed + self.n_executed_branches) /
@@ -236,9 +237,9 @@ class Numbers(object):
else:
pc_cov = 100.0
return pc_cov
- pc_covered = property(_get_pc_covered)
- def _get_pc_covered_str(self):
+ @property
+ def pc_covered_str(self):
"""Returns the percent covered, as a string, without a percent sign.
Note that "0" is only returned when the value is truly zero, and "100"
@@ -254,15 +255,14 @@ class Numbers(object):
else:
pc = round(pc, self._precision)
return "%.*f" % (self._precision, pc)
- pc_covered_str = property(_get_pc_covered_str)
+ @classmethod
def pc_str_width(cls):
"""How many characters wide can pc_covered_str be?"""
width = 3 # "100"
if cls._precision > 0:
width += 1 + cls._precision
return width
- pc_str_width = classmethod(pc_str_width)
def __add__(self, other):
nums = Numbers()
diff --git a/tests/coveragetest.py b/tests/coveragetest.py
index 4fe8191..cb2957d 100644
--- a/tests/coveragetest.py
+++ b/tests/coveragetest.py
@@ -508,6 +508,7 @@ class CoverageTest(TestCase):
# Map from class to info about how it ran.
class_behaviors = {}
+ @classmethod
def report_on_class_behavior(cls):
"""Called at process exit to report on class behavior."""
for test_class, behavior in cls.class_behaviors.items():
@@ -532,7 +533,6 @@ class CoverageTest(TestCase):
where,
)
)
- report_on_class_behavior = classmethod(report_on_class_behavior)
def class_behavior(self):
"""Get the ClassBehavior instance for this test."""