diff options
author | Guido van Rossum <guido@python.org> | 2007-08-03 18:40:49 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-08-03 18:40:49 (GMT) |
commit | ad8d30092ccebad0f940fe0ed3ff25a18c25dddf (patch) | |
tree | 368f9ee7089ab4932a273b56e8e8de9bf502afab /Lib | |
parent | 6afaeb757af0dbd8508a0f2352ade61e41bec84c (diff) | |
download | cpython-ad8d30092ccebad0f940fe0ed3ff25a18c25dddf.zip cpython-ad8d30092ccebad0f940fe0ed3ff25a18c25dddf.tar.gz cpython-ad8d30092ccebad0f940fe0ed3ff25a18c25dddf.tar.bz2 |
SF patch# 1766592 by Paul Colomiets.
Fix test_zipimport.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/doctest.py | 2 | ||||
-rw-r--r-- | Lib/test/test_zipimport.py | 21 |
2 files changed, 10 insertions, 13 deletions
diff --git a/Lib/doctest.py b/Lib/doctest.py index 3f139fc..bc30a1a 100644 --- a/Lib/doctest.py +++ b/Lib/doctest.py @@ -209,7 +209,7 @@ def _load_testfile(filename, package, module_relative): filename = _module_relative_path(package, filename) if hasattr(package, '__loader__'): if hasattr(package.__loader__, 'get_data'): - return package.__loader__.get_data(filename), filename + return package.__loader__.get_data(filename).decode('utf-8'), filename return open(filename, encoding="utf-8").read(), filename def _indent(s, indent=4): diff --git a/Lib/test/test_zipimport.py b/Lib/test/test_zipimport.py index 8daac4b..bae2172 100644 --- a/Lib/test/test_zipimport.py +++ b/Lib/test/test_zipimport.py @@ -153,18 +153,16 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase): def testBadMagic(self): # make pyc magic word invalid, forcing loading from .py - m0 = ord(test_pyc[0]) - m0 ^= 0x04 # flip an arbitrary bit - badmagic_pyc = chr(m0) + test_pyc[1:] + badmagic_pyc = bytes(test_pyc) + badmagic_pyc[0] ^= 0x04 # flip an arbitrary bit files = {TESTMOD + ".py": (NOW, test_src), TESTMOD + pyc_ext: (NOW, badmagic_pyc)} self.doTest(".py", files, TESTMOD) def testBadMagic2(self): # make pyc magic word invalid, causing an ImportError - m0 = ord(test_pyc[0]) - m0 ^= 0x04 # flip an arbitrary bit - badmagic_pyc = chr(m0) + test_pyc[1:] + badmagic_pyc = bytes(test_pyc) + badmagic_pyc[0] ^= 0x04 # flip an arbitrary bit files = {TESTMOD + pyc_ext: (NOW, badmagic_pyc)} try: self.doTest(".py", files, TESTMOD) @@ -174,10 +172,9 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase): self.fail("expected ImportError; import from bad pyc") def testBadMTime(self): - t3 = ord(test_pyc[7]) - t3 ^= 0x02 # flip the second bit -- not the first as that one - # isn't stored in the .py's mtime in the zip archive. - badtime_pyc = test_pyc[:7] + chr(t3) + test_pyc[8:] + badtime_pyc = bytes(test_pyc) + badtime_pyc[7] ^= 0x02 # flip the second bit -- not the first as that one + # isn't stored in the .py's mtime in the zip archive. files = {TESTMOD + ".py": (NOW, test_src), TESTMOD + pyc_ext: (NOW, badtime_pyc)} self.doTest(".py", files, TESTMOD) @@ -232,7 +229,7 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase): z.compression = self.compression try: name = "testdata.dat" - data = "".join([chr(x) for x in range(256)]) * 500 + data = bytes(x for x in range(256)) z.writestr(name, data) z.close() zi = zipimport.zipimporter(TEMP_ZIP) @@ -246,7 +243,7 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase): src = """if 1: # indent hack def get_file(): return __file__ - if __loader__.get_data("some.data") != "some data": + if __loader__.get_data("some.data") != b"some data": raise AssertionError, "bad data"\n""" pyc = make_pyc(compile(src, "<???>", "exec"), NOW) files = {TESTMOD + pyc_ext: (NOW, pyc), |