public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: devel@edk2.groups.io
Cc: Zhiju Fan <zhijux.fan@intel.com>,
	Philippe Mathieu-Daude <philmd@redhat.com>,
	Bob Feng <bob.c.feng@intel.com>,
	Liming Gao <liming.gao@intel.com>
Subject: [PATCH v2] BaseTools: Fix Python3 encoding issue in TestTools
Date: Thu,  5 Dec 2019 19:44:56 +0100	[thread overview]
Message-ID: <20191205184456.17799-1-philmd@redhat.com> (raw)

Under Centos 7.7 we get:

  Build environment: \
    Linux-3.10.0-1062.7.1.el7.x86_64-x86_64-with-centos-7.7.1908-Core
  [...]
  ======================================================================
  ERROR: testRandomDataCycles (TianoCompress.Tests)
  ----------------------------------------------------------------------
  Traceback (most recent call last):
    File "edk2/BaseTools/Tests/TianoCompress.py", line 60, \
        in testRandomDataCycles
      self.compressionTestCycle(data)
    File "edk2/BaseTools/Tests/TianoCompress.py", line 46, \
        in compressionTestCycle
      start = self.ReadTmpFile('input')
    File "edk2/BaseTools/Tests/TestTools.py", line 139, in ReadTmpFile
      data = f.read()
    File "/usr/lib64/python3.6/encodings/ascii.py", line 26, in decode
      return codecs.ascii_decode(input, self.errors)[0]
  UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 3: \
    ordinal not in range(128)

  ----------------------------------------------------------------------

Fix by using the 'io' module (per [1]), and specifying the UTF-8 encoding.

[1] https://mail.python.org/pipermail/python-list/2015-March/687124.html
Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Philippe Mathieu-Daude <philmd@redhat.com>
---
v2: Use io, wrap commit message lines per CheckPatch
---
 BaseTools/Tests/TestTools.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/BaseTools/Tests/TestTools.py b/BaseTools/Tests/TestTools.py
index 1099fd4eeaea..8aaad3609669 100644
--- a/BaseTools/Tests/TestTools.py
+++ b/BaseTools/Tests/TestTools.py
@@ -11,6 +11,7 @@ from __future__ import print_function
 # Import Modules
 #
 import base64
+import io
 import os
 import os.path
 import random
@@ -18,7 +19,6 @@ import shutil
 import subprocess
 import sys
 import unittest
-import codecs
 
 TestsDir = os.path.realpath(os.path.split(sys.argv[0])[0])
 BaseToolsDir = os.path.realpath(os.path.join(TestsDir, '..'))
@@ -135,7 +135,7 @@ class BaseToolsTest(unittest.TestCase):
         return open(os.path.join(self.testDir, fileName), mode)
 
     def ReadTmpFile(self, fileName):
-        f = open(self.GetTmpFilePath(fileName), 'r')
+        f = io.open(self.GetTmpFilePath(fileName), 'r', encoding='utf-8')
         data = f.read()
         f.close()
         return data
@@ -145,7 +145,7 @@ class BaseToolsTest(unittest.TestCase):
             with open(self.GetTmpFilePath(fileName), 'wb') as f:
                 f.write(data)
         else:
-            with codecs.open(self.GetTmpFilePath(fileName), 'w', encoding='utf-8') as f:
+            with io.open(self.GetTmpFilePath(fileName), 'w', encoding='utf-8') as f:
                 f.write(data)
 
     def GenRandomFileData(self, fileName, minlen = None, maxlen = None):
-- 
2.21.0


                 reply	other threads:[~2019-12-05 18:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191205184456.17799-1-philmd@redhat.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox