BaseTools:TestTools character encoding issue

Specifies encoding when opening a file using codecs

Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhiju.Fan <zhijux.fan@intel.com>
Tested-by: Laszlo Ersek <lersek@redhat.com>
Tested-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Bob Feng <bob.c.feng@intel.com>
This commit is contained in:
Zhiju Fan 2019-01-09 10:31:32 +08:00 committed by Feng, Bob C
parent 3f7cb70c5a
commit 31e3eeb5e3
1 changed files with 2 additions and 1 deletions

View File

@ -24,6 +24,7 @@ import shutil
import subprocess import subprocess
import sys import sys
import unittest import unittest
import codecs
TestsDir = os.path.realpath(os.path.split(sys.argv[0])[0]) TestsDir = os.path.realpath(os.path.split(sys.argv[0])[0])
BaseToolsDir = os.path.realpath(os.path.join(TestsDir, '..')) BaseToolsDir = os.path.realpath(os.path.join(TestsDir, '..'))
@ -150,7 +151,7 @@ class BaseToolsTest(unittest.TestCase):
with open(self.GetTmpFilePath(fileName), 'wb') as f: with open(self.GetTmpFilePath(fileName), 'wb') as f:
f.write(data) f.write(data)
else: else:
with open(self.GetTmpFilePath(fileName), 'w') as f: with codecs.open(self.GetTmpFilePath(fileName), 'w', encoding='utf-8') as f:
f.write(data) f.write(data)
def GenRandomFileData(self, fileName, minlen = None, maxlen = None): def GenRandomFileData(self, fileName, minlen = None, maxlen = None):