diff options
| author | Rusty Wagner <rusty@vector35.com> | 2020-06-15 20:06:31 -0400 |
|---|---|---|
| committer | Rusty Wagner <rusty@vector35.com> | 2020-06-15 20:06:31 -0400 |
| commit | 75588da11bc29b00cac46c494ea389ac87b49778 (patch) | |
| tree | fb6965447617a72a00753e6d80f7fda2311b4478 /suite/generator.py | |
| parent | e587c9f6e532d3e5fedee8504aeb0c94e3604c91 (diff) | |
Fix Python 3 unit tests
Diffstat (limited to 'suite/generator.py')
| -rwxr-xr-x | suite/generator.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/suite/generator.py b/suite/generator.py index 78925e97..3d15a813 100755 --- a/suite/generator.py +++ b/suite/generator.py @@ -7,6 +7,14 @@ from optparse import OptionParser import testcommon import time +if sys.version_info.major == 3: + # The differences between the behavior of str() on Python 2 and Python 3 make it very difficult to make + # test results created on Python 3 work when testing on Python 2. Test results generated with Python 2 + # will work when testing on both Python 2 and Python 3. + # FIXME: When Python 2 is dropped fully, use Python 3 to generate the tests. + print("Generate unit tests on Python 2. Python 3 generated test results are NOT COMPATIBLE with Python 2.") + sys.exit(1) + unit_test_template = """#!/usr/bin/env python # This is an auto generated unit test file do not edit directly import os @@ -84,7 +92,7 @@ class TestBinaryNinjaAPI(unittest.TestCase): pickle_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "oracle.pkl") try: # Python 2 does not have the encodings option - self.oracle_test_data = pickle.load(open(pickle_path, "rb"), encoding='charmap') + self.oracle_test_data = pickle.load(open(pickle_path, "rb"), encoding='utf8') except TypeError: self.oracle_test_data = pickle.load(open(pickle_path, "rb")) self.verifybuilder = testcommon.VerifyBuilder("{3}") @@ -99,7 +107,7 @@ class TestBinaryNinjaAPI(unittest.TestCase): self.assertTrue(pickle_path, "Test pickle doesn't exist") try: # Python 2 does not have the encodings option - binary_oracle = pickle.load(open(pickle_path, "rb"), encoding='charmap') + binary_oracle = pickle.load(open(pickle_path, "rb"), encoding='utf8') except TypeError: binary_oracle = pickle.load(open(pickle_path, "rb")) @@ -185,7 +193,7 @@ class UnitTestFile: api_path = map(lambda x: '"{0}"'.format(x), api_path.split(os.sep)) api_path = '{0}'.format(', '.join(api_path)) test_store = self.test_store.replace(os.sep, '/') if os.name == 'nt' else self.test_store - self.f.write(self.template.format(self.outdir, self.tests, self.binary_tests, test_store, api_path).encode('charmap')) + self.f.write(self.template.format(self.outdir, self.tests, self.binary_tests, test_store, api_path).encode('utf8')) self.f.close() def add_verify(self, test_name): |
