1. Ned Batchelder
  2. coverage.py

Commits

Ned Batchelder  committed 6703e33

Generator expressons are ok now.

  • Participants
  • Parent commits ca1cb34
  • Branches 4.0

Comments (0)

Files changed (16)

File TODO.txt

View file
 
 - Remove 2.3, 2.4, 2.5 limitations
     + set, sorted, reversed, rpartition
-    - generator expressions
+    + generator expressions
     + decorators
     - collections.defaultdict
     + .startswith((,))

File coverage/backward.py

View file
 
     def binary_bytes(byte_values):
         """Produce a byte string with the ints from `byte_values`."""
-        return "".join([chr(b) for b in byte_values])
+        return "".join(chr(b) for b in byte_values)
 
     def byte_to_int(byte_value):
         """Turn an element of a bytes object into an int."""

File coverage/config.py

View file
         def dollar_replace(m):
             """Called for each $replacement."""
             # Only one of the groups will have matched, just get its text.
-            word = [w for w in m.groups() if w is not None][0]
+            word = next(w for w in m.groups() if w is not None)
             if word == "$":
                 return "$"
             else:

File coverage/data.py

View file
     def line_data(self):
         """Return the map from filenames to lists of line numbers executed."""
         return dict(
-            [(f, sorted(lmap.keys())) for f, lmap in iitems(self.lines)]
+            (f, sorted(lmap.keys())) for f, lmap in iitems(self.lines)
             )
 
     def arc_data(self):
         """Return the map from filenames to lists of line number pairs."""
         return dict(
-            [(f, sorted(amap.keys())) for f, amap in iitems(self.arcs)]
+            (f, sorted(amap.keys())) for f, amap in iitems(self.arcs)
             )
 
     def write_file(self, filename):

File coverage/debug.py

View file
     nicely formatted, ready to print.
 
     """
-    label_len = max([len(l) for l, _d in info])
+    label_len = max(len(l) for l, _d in info)
     for label, data in info:
         if data == []:
             data = "-none-"

File coverage/html.py

View file
             data("index.html"), self.template_globals
             )
 
-        self.totals = sum([f['nums'] for f in self.files])
+        self.totals = sum(f['nums'] for f in self.files)
 
         html = index_tmpl.render({
             'arcs': self.arcs,

File coverage/misc.py

View file
 def short_stack():
     """Return a string summarizing the call stack."""
     stack = inspect.stack()[:0:-1]
-    return "\n".join(["%30s : %s @%d" % (t[3],t[1],t[2]) for t in stack])
+    return "\n".join("%30s : %s @%d" % (t[3],t[1],t[2]) for t in stack)
 
 
 def expensive(fn):
 def join_regex(regexes):
     """Combine a list of regexes into one that matches any of them."""
     if len(regexes) > 1:
-        return "|".join(["(%s)" % r for r in regexes])
+        return "|".join("(%s)" % r for r in regexes)
     elif regexes:
         return regexes[0]
     else:

File coverage/parser.py

View file
 
         """
         children = CodeObjects(self.code)
-        return [ByteParser(code=c, text=self.text) for c in children]
+        return (ByteParser(code=c, text=self.text) for c in children)
 
     def _bytes_lines(self):
         """Map byte offsets to line numbers in `code`.
     def _block_stack_repr(self, block_stack):
         """Get a string version of `block_stack`, for debugging."""
         blocks = ", ".join(
-            ["(%s, %r)" % (dis.opname[b[0]], b[1]) for b in block_stack]
+            "(%s, %r)" % (dis.opname[b[0]], b[1]) for b in block_stack
         )
         return "[" + blocks + "]"
 
     def validate_chunks(self, chunks):
         """Validate the rule that chunks have a single entrance."""
         # starts is the entrances to the chunks
-        starts = set([ch.byte for ch in chunks])
+        starts = set(ch.byte for ch in chunks)
         for ch in chunks:
-            assert all([(ex in starts or ex < 0) for ex in ch.exits])
+            assert all((ex in starts or ex < 0) for ex in ch.exits)
 
     def _arcs(self):
         """Find the executable arcs in the code.
         chunks = self._split_into_chunks()
 
         # A map from byte offsets to chunks jumped into.
-        byte_chunks = dict([(c.byte, c) for c in chunks])
+        byte_chunks = dict((c.byte, c) for c in chunks)
 
         # There's always an entrance at the first chunk.
         yield (-1, byte_chunks[0].line)

File coverage/results.py

View file
             n_branches = self.total_branches()
             mba = self.missing_branch_arcs()
             n_partial_branches = sum(
-                [len(v) for k,v in iitems(mba) if k not in self.missing]
+                len(v) for k,v in iitems(mba) if k not in self.missing
                 )
-            n_missing_branches = sum([len(v) for k,v in iitems(mba)])
+            n_missing_branches = sum(len(v) for k,v in iitems(mba))
         else:
             n_branches = n_partial_branches = n_missing_branches = 0
             self.no_branch = set()
         """Returns a sorted list of the arcs actually executed in the code."""
         executed = self.coverage.data.executed_arcs(self.filename)
         m2fl = self.parser.first_line
-        executed = [(m2fl(l1), m2fl(l2)) for (l1,l2) in executed]
+        executed = ((m2fl(l1), m2fl(l2)) for (l1,l2) in executed)
         return sorted(executed)
 
     def arcs_missing(self):
         """Returns a sorted list of the arcs in the code not executed."""
         possible = self.arc_possibilities()
         executed = self.arcs_executed()
-        missing = [
+        missing = (
             p for p in possible
                 if p not in executed
                     and p[0] not in self.no_branch
-            ]
+        )
         return sorted(missing)
 
     def arcs_unpredicted(self):
         # Exclude arcs here which connect a line to itself.  They can occur
         # in executed data in some cases.  This is where they can cause
         # trouble, and here is where it's the least burden to remove them.
-        unpredicted = [
+        unpredicted = (
             e for e in executed
                 if e not in possible
                     and e[0] != e[1]
-            ]
+        )
         return sorted(unpredicted)
 
     def branch_lines(self):
     def total_branches(self):
         """How many total branches are there?"""
         exit_counts = self.parser.exit_counts()
-        return sum([count for count in exit_counts.values() if count > 1])
+        return sum(count for count in exit_counts.values() if count > 1)
 
     def missing_branch_arcs(self):
         """Return arcs that weren't executed from branch lines.

File coverage/xmlreport.py

View file
         class_hits = class_lines - len(analysis.missing)
 
         if self.arcs:
-            class_branches = sum([t for t,k in branch_stats.values()])
-            missing_branches = sum([t-k for t,k in branch_stats.values()])
+            class_branches = sum(t for t, k in branch_stats.values())
+            missing_branches = sum(t - k for t, k in branch_stats.values())
             class_br_hits = class_branches - missing_branches
         else:
             class_branches = 0.0

File igor.py

View file
 
     if '__pypy__' in sys.builtin_module_names:
         pypy_version = sys.pypy_version_info         # pylint: disable=E1101
-        version += " (pypy %s)" % ".".join([str(v) for v in pypy_version])
+        version += " (pypy %s)" % ".".join(str(v) for v in pypy_version)
 
     print('=== %s %s %s (%s) ===' % (impl, version, label, sys.executable))
 

File tests/coveragetest.py

View file
 
     # Map chars to numbers for arcz_to_arcs
     _arcz_map = {'.': -1}
-    _arcz_map.update(dict([(c, ord(c)-ord('0')) for c in '123456789']))
+    _arcz_map.update(dict((c, ord(c)-ord('0')) for c in '123456789'))
     _arcz_map.update(dict(
-        [(c, 10+ord(c)-ord('A')) for c in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ']
-        ))
+        (c, 10+ord(c)-ord('A')) for c in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+    ))
 
     def arcz_to_arcs(self, arcz):
         """Convert a compact textual representation of arcs to a list of pairs.
     def assertEqualArcs(self, a1, a2, msg=None):
         """Assert that the arc lists `a1` and `a2` are equal."""
         # Make them into multi-line strings so we can see what's going wrong.
-        s1 = "\n".join([repr(a) for a in a1]) + "\n"
-        s2 = "\n".join([repr(a) for a in a2]) + "\n"
+        s1 = "\n".join(repr(a) for a in a1) + "\n"
+        s2 = "\n".join(repr(a) for a in a2) + "\n"
         self.assertMultiLineEqual(s1, s2, msg)
 
     def check_coverage(self, text, lines=None, missing="", report="",

File tests/test_farm.py

View file
             copy run runfunc compare contains doesnt_contain clean skip
             """.split()
         if self.clean_only:
-            glo = dict([(fn, self.noop) for fn in fns])
+            glo = dict((fn, self.noop) for fn in fns)
             glo['clean'] = self.clean
         else:
-            glo = dict([(fn, getattr(self, fn)) for fn in fns])
+            glo = dict((fn, getattr(self, fn)) for fn in fns)
             if self.dont_clean:                 # pragma: not covered
                 glo['clean'] = self.noop
 

File tests/test_phystokens.py

View file
         """Tokenize `source`, then put it back together, should be the same."""
         tokenized = ""
         for line in source_token_lines(source):
-            text = "".join([t for _,t in line])
+            text = "".join(t for _, t in line)
             tokenized += text + "\n"
         # source_token_lines doesn't preserve trailing spaces, so trim all that
         # before comparing.

File tests/test_process.py

View file
         if '__pypy__' in sys.builtin_module_names:
             # Pypy has an extra frame in the traceback for some reason
             lines2 = out2.splitlines()
-            out2 = "".join([l+"\n" for l in lines2 if "toplevel" not in l])
+            out2 = "".join(l+"\n" for l in lines2 if "toplevel" not in l)
         self.assertMultiLineEqual(out, out2)
 
         # But also make sure that the output is what we expect.

File tests/test_testing.py

View file
         # Try it with a "coverage debug sys" command.
         out = self.run_command("coverage debug sys").splitlines()
         # "environment: COV_FOOBAR = XYZZY" or "COV_FOOBAR = XYZZY"
-        executable = [l for l in out if "executable:" in l][0]
+        executable = next(l for l in out if "executable:" in l)
         executable = executable.split(":", 1)[1].strip()
         self.assertTrue(same_python_executable(executable, sys.executable))
-        environ = [l for l in out if "COV_FOOBAR" in l][0]
+        environ = next(l for l in out if "COV_FOOBAR" in l)
         _, _, environ = environ.rpartition(":")
         self.assertEqual(environ.strip(), "COV_FOOBAR = XYZZY")