From 57e762c85d767eba791782596665d3e6980c83a7 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Tue, 18 Jun 2019 17:35:18 -0400 Subject: Context reporting improvements and test Contexts should only be reported on lines that are marked as executed. The empty outer context is now reported as "(empty)". --- coverage/debug.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'coverage/debug.py') diff --git a/coverage/debug.py b/coverage/debug.py index 3a6b1fdc..c11c927a 100644 --- a/coverage/debug.py +++ b/coverage/debug.py @@ -8,6 +8,7 @@ import functools import inspect import itertools import os +import pprint import sys try: import _thread @@ -193,6 +194,23 @@ class SimpleReprMixin(object): ) +def simplify(v): + """Turn things which are nearly dict/list/etc into dict/list/etc.""" + if isinstance(v, dict): + return {k:simplify(vv) for k, vv in v.items()} + elif isinstance(v, (list, tuple)): + return type(v)(simplify(vv) for vv in v) + elif hasattr(v, "__dict__"): + return simplify({'.'+k: v for k, v in v.__dict__.items()}) + else: + return v + + +def pp(v): + """Debug helper to pretty-print data, including SimpleNamespace objects.""" + pprint.pprint(simplify(v)) + + def filter_text(text, filters): """Run `text` through a series of filters. -- cgit v1.2.1