BaseTools: update Test scripts support python3
update Test scripts support python2 and python3 Cc: Bob Feng <bob.c.feng@intel.com> Cc: Liming Gao <liming.gao@intel.com> Cc: Yonghong Zhu <yonghong.zhu@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:
@ -26,7 +26,7 @@ modules = (
|
|||||||
|
|
||||||
|
|
||||||
def TheTestSuite():
|
def TheTestSuite():
|
||||||
suites = map(lambda module: module.TheTestSuite(), modules)
|
suites = list(map(lambda module: module.TheTestSuite(), modules))
|
||||||
return unittest.TestSuite(suites)
|
return unittest.TestSuite(suites)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -110,7 +110,7 @@ class Tests(TestTools.BaseToolsTest):
|
|||||||
# This test makes sure that BaseTools rejects these characters
|
# This test makes sure that BaseTools rejects these characters
|
||||||
# if seen in a .uni file.
|
# if seen in a .uni file.
|
||||||
#
|
#
|
||||||
data = codecs.BOM_UTF16_LE + '//\x01\xd8 '
|
data = codecs.BOM_UTF16_LE + b'//\x01\xd8 '
|
||||||
|
|
||||||
self.CheckFile(encoding=None, shouldPass=False, string=data)
|
self.CheckFile(encoding=None, shouldPass=False, string=data)
|
||||||
|
|
||||||
@ -161,7 +161,7 @@ class Tests(TestTools.BaseToolsTest):
|
|||||||
# This test makes sure that BaseTools rejects these characters
|
# This test makes sure that BaseTools rejects these characters
|
||||||
# if seen in a .uni file.
|
# if seen in a .uni file.
|
||||||
#
|
#
|
||||||
data = '\xed\xa0\x81'
|
data = b'\xed\xa0\x81'
|
||||||
|
|
||||||
self.CheckFile(encoding=None, shouldPass=False, string=data)
|
self.CheckFile(encoding=None, shouldPass=False, string=data)
|
||||||
|
|
||||||
@ -170,7 +170,7 @@ class Tests(TestTools.BaseToolsTest):
|
|||||||
# Same test as testSurrogatePairUnicodeCharInUtf8File, but add
|
# Same test as testSurrogatePairUnicodeCharInUtf8File, but add
|
||||||
# the UTF-8 BOM
|
# the UTF-8 BOM
|
||||||
#
|
#
|
||||||
data = codecs.BOM_UTF8 + '\xed\xa0\x81'
|
data = codecs.BOM_UTF8 + b'\xed\xa0\x81'
|
||||||
|
|
||||||
self.CheckFile(encoding=None, shouldPass=False, string=data)
|
self.CheckFile(encoding=None, shouldPass=False, string=data)
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ if PythonSourceDir not in sys.path:
|
|||||||
|
|
||||||
def MakeTheTestSuite(localItems):
|
def MakeTheTestSuite(localItems):
|
||||||
tests = []
|
tests = []
|
||||||
for name, item in localItems.iteritems():
|
for name, item in localItems.items():
|
||||||
if isinstance(item, type):
|
if isinstance(item, type):
|
||||||
if issubclass(item, unittest.TestCase):
|
if issubclass(item, unittest.TestCase):
|
||||||
tests.append(unittest.TestLoader().loadTestsFromTestCase(item))
|
tests.append(unittest.TestLoader().loadTestsFromTestCase(item))
|
||||||
@ -146,9 +146,12 @@ class BaseToolsTest(unittest.TestCase):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
def WriteTmpFile(self, fileName, data):
|
def WriteTmpFile(self, fileName, data):
|
||||||
f = open(self.GetTmpFilePath(fileName), 'w')
|
if isinstance(data, bytes):
|
||||||
|
with open(self.GetTmpFilePath(fileName), 'wb') as f:
|
||||||
|
f.write(data)
|
||||||
|
else:
|
||||||
|
with open(self.GetTmpFilePath(fileName), 'w') as f:
|
||||||
f.write(data)
|
f.write(data)
|
||||||
f.close()
|
|
||||||
|
|
||||||
def GenRandomFileData(self, fileName, minlen = None, maxlen = None):
|
def GenRandomFileData(self, fileName, minlen = None, maxlen = None):
|
||||||
if maxlen is None: maxlen = minlen
|
if maxlen is None: maxlen = minlen
|
||||||
@ -161,7 +164,7 @@ class BaseToolsTest(unittest.TestCase):
|
|||||||
if maxlen is None: maxlen = minlen
|
if maxlen is None: maxlen = minlen
|
||||||
return ''.join(
|
return ''.join(
|
||||||
[chr(random.randint(0, 255))
|
[chr(random.randint(0, 255))
|
||||||
for x in xrange(random.randint(minlen, maxlen))
|
for x in range(random.randint(minlen, maxlen))
|
||||||
])
|
])
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
Reference in New Issue
Block a user