From 0ebd4f0ebab9620a6fc74cb4c0d337ba2c2d8916 Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Tue, 14 Apr 2015 20:11:12 +0200 Subject: Fix #363: crash when annotating non-ascii characters in python 2. --HG-- extra : amend_source : 8297268531b6014e4f2c2a445385f89688a3fb93 --- coverage/annotate.py | 5 +++++ tests/farm/annotate/run_encodings.py | 7 +++++++ tests/farm/annotate/src/utf8.py | 4 ++++ 3 files changed, 16 insertions(+) create mode 100644 tests/farm/annotate/run_encodings.py create mode 100644 tests/farm/annotate/src/utf8.py diff --git a/coverage/annotate.py b/coverage/annotate.py index 3487feb6..d4bbeb3d 100644 --- a/coverage/annotate.py +++ b/coverage/annotate.py @@ -2,6 +2,7 @@ import os, re +from coverage import env from coverage.report import Reporter class AnnotateReporter(Reporter): @@ -89,4 +90,8 @@ class AnnotateReporter(Reporter): dest.write('> ') else: dest.write('! ') + + if env.PY2: + line = line.encode('utf-8') + dest.write(line) diff --git a/tests/farm/annotate/run_encodings.py b/tests/farm/annotate/run_encodings.py new file mode 100644 index 00000000..eb1a3a9a --- /dev/null +++ b/tests/farm/annotate/run_encodings.py @@ -0,0 +1,7 @@ +copy("src", "out") +run(""" + coverage run utf8.py + coverage annotate utf8.py + """, rundir="out") +compare("out", "gold_encodings", "*,cover") +clean("out") diff --git a/tests/farm/annotate/src/utf8.py b/tests/farm/annotate/src/utf8.py new file mode 100644 index 00000000..27342d87 --- /dev/null +++ b/tests/farm/annotate/src/utf8.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# This comment has an accent: é + +print("spam eggs") -- cgit v1.2.1