Blob Blame History Raw
From b03958b42a983a55601e98c7b1511627726724a4 Mon Sep 17 00:00:00 2001
From: Dan Callaghan <dcallagh@redhat.com>
Date: Tue, 17 Jul 2018 11:59:20 +1000
Subject: [PATCH] fix TestDiffEncoding when run in C locale

On Python 2 when the locale uses ASCII (for example, inside Fedora's
Koji build system) io.open will try to decode the file as ASCII instead
of UTF-8, which causes the test to fail:

    ======================================================================
    ERROR: test_diff_encoding (TestDiffEncoding.TestDiffEncoding)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/builddir/build/BUILD/ansible-review-0.13.7/test/TestDiffEncoding.py", line 13, in test_diff_encoding
        for line in f.readlines():
      File "/usr/lib64/python2.7/encodings/ascii.py", line 26, in decode
        return codecs.ascii_decode(input, self.errors)[0]
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xce in position 114: ordinal not in range(128)

The file is UTF-8 and the test is clearly expecting that so explicitly
specify the encoding when opening the file.
---
 test/TestDiffEncoding.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/test/TestDiffEncoding.py b/test/TestDiffEncoding.py
index 5a1b324..586169f 100644
--- a/test/TestDiffEncoding.py
+++ b/test/TestDiffEncoding.py
@@ -9,7 +9,7 @@ class TestDiffEncoding(unittest.TestCase):
     
     def test_diff_encoding(self):
         difflines = []
-        with io.open(os.path.join(self.directory, 'diff.txt'), 'r') as f:
+        with io.open(os.path.join(self.directory, 'diff.txt'), 'r', encoding='utf-8') as f:
             for line in f.readlines():
                 encodedline = line.encode("utf-8")
                 difflines.append(encodedline)
-- 
2.17.1