From bad63e02b113626a048ea5eb253293c61902e291 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sat, 19 Oct 2013 22:08:37 -0400 Subject: Generator expressons are ok now. --HG-- branch : 4.0 --- coverage/html.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'coverage/html.py') diff --git a/coverage/html.py b/coverage/html.py index 956f070e..e0262998 100644 --- a/coverage/html.py +++ b/coverage/html.py @@ -270,7 +270,7 @@ class HtmlReporter(Reporter): 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, -- cgit v1.2.1 From 6b6a4488adc12d390c5e0c8f13829dd9bf125309 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 20 Oct 2013 07:58:57 -0400 Subject: with statements: no more finally close --HG-- branch : 4.0 --- coverage/html.py | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) (limited to 'coverage/html.py') diff --git a/coverage/html.py b/coverage/html.py index e0262998..d8779233 100644 --- a/coverage/html.py +++ b/coverage/html.py @@ -43,11 +43,8 @@ def data_filename(fname, pkgdir=""): def data(fname): """Return the contents of a data file of ours.""" - data_file = open(data_filename(fname)) - try: + with open(data_filename(fname)) as data_file: return data_file.read() - finally: - data_file.close() class HtmlReporter(Reporter): @@ -140,11 +137,8 @@ class HtmlReporter(Reporter): def write_html(self, fname, html): """Write `html` to `fname`, properly encoded.""" - fout = open(fname, "wb") - try: + with open(fname, "wb") as fout: fout.write(html.encode('ascii', 'xmlcharrefreplace')) - finally: - fout.close() def file_hash(self, source, cu): """Compute a hash that changes if the file needs to be re-reported.""" @@ -156,10 +150,8 @@ class HtmlReporter(Reporter): def html_file(self, cu, analysis): """Generate an HTML file for one source file.""" source_file = cu.source_file() - try: + with source_file: source = source_file.read() - finally: - source_file.close() # Find out if the file on disk is already correct. flat_rootname = cu.flat_rootname() @@ -309,11 +301,8 @@ class HtmlStatus(object): usable = False try: status_file = os.path.join(directory, self.STATUS_FILE) - fstatus = open(status_file, "rb") - try: + with open(status_file, "rb") as fstatus: status = pickle.load(fstatus) - finally: - fstatus.close() except (IOError, ValueError): usable = False else: @@ -338,11 +327,8 @@ class HtmlStatus(object): 'settings': self.settings, 'files': self.files, } - fout = open(status_file, "wb") - try: + with open(status_file, "wb") as fout: pickle.dump(status, fout) - finally: - fout.close() def settings_hash(self): """Get the hash of the coverage.py settings.""" -- cgit v1.2.1 From 7c66441eab3af17539c478a2cb4e19cd93ba0cf4 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Wed, 23 Oct 2013 22:35:51 -0400 Subject: enumerate has a start parameter! --HG-- branch : 4.0 --- coverage/html.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'coverage/html.py') diff --git a/coverage/html.py b/coverage/html.py index d8779233..e1966bfb 100644 --- a/coverage/html.py +++ b/coverage/html.py @@ -186,8 +186,7 @@ class HtmlReporter(Reporter): lines = [] - for lineno, line in enumerate(source_token_lines(source)): - lineno += 1 # 1-based line numbers. + for lineno, line in enumerate(source_token_lines(source), start=1): # Figure out how to mark this line. line_class = [] annotate_html = "" -- cgit v1.2.1