|
45 | 45 | CPYTHON3 = os.getenv("MICROPY_CPYTHON3", "python3")
|
46 | 46 | MICROPYTHON = os.getenv("MICROPY_MICROPYTHON", "../ports/unix/build-standard/micropython")
|
47 | 47 |
|
| 48 | +# Set PYTHONIOENCODING so that CPython will use utf-8 on systems which set another encoding in the locale |
| 49 | +os.environ["PYTHONIOENCODING"] = "utf-8" |
| 50 | + |
| 51 | +# Set PYTHONUNBUFFERED so that CPython will interleave stdout & stderr without buffering |
| 52 | +os.environ["PYTHONUNBUFFERED"] = "a non-empty string" |
| 53 | + |
48 | 54 | TESTPATH = "../tests/cpydiff"
|
49 | 55 | DOCPATH = "../docs/genrst"
|
50 | 56 | SRCDIR = "../docs/differences"
|
@@ -111,28 +117,30 @@ def run_tests(tests):
|
111 | 117 | results = []
|
112 | 118 | for test in tests:
|
113 | 119 | test_fullpath = os.path.join(TESTPATH, test.name)
|
114 |
| - with open(test_fullpath, "rb") as f: |
| 120 | + with open(test_fullpath, "r") as f: |
115 | 121 | input_py = f.read()
|
116 | 122 |
|
117 | 123 | process = subprocess.Popen(
|
118 | 124 | CPYTHON3,
|
119 | 125 | shell=True,
|
120 | 126 | stdout=subprocess.PIPE,
|
121 | 127 | stdin=subprocess.PIPE,
|
122 |
| - stderr=subprocess.PIPE, |
| 128 | + stderr=subprocess.STDOUT, |
| 129 | + encoding="utf-8", |
123 | 130 | )
|
124 |
| - output_cpy = [com.decode("utf8") for com in process.communicate(input_py)] |
| 131 | + output_cpy = process.communicate(input_py)[0] |
125 | 132 |
|
126 | 133 | process = subprocess.Popen(
|
127 | 134 | MICROPYTHON,
|
128 | 135 | shell=True,
|
129 | 136 | stdout=subprocess.PIPE,
|
130 | 137 | stdin=subprocess.PIPE,
|
131 |
| - stderr=subprocess.PIPE, |
| 138 | + stderr=subprocess.STDOUT, |
| 139 | + encoding="utf-8", |
132 | 140 | )
|
133 |
| - output_upy = [com.decode("utf8") for com in process.communicate(input_py)] |
| 141 | + output_upy = process.communicate(input_py)[0] |
134 | 142 |
|
135 |
| - if output_cpy[0] == output_upy[0] and output_cpy[1] == output_upy[1]: |
| 143 | + if output_cpy == output_upy: |
136 | 144 | print("Error: Test has same output in CPython vs MicroPython: " + test_fullpath)
|
137 | 145 | same_results = True
|
138 | 146 | else:
|
@@ -246,9 +254,9 @@ def gen_rst(results):
|
246 | 254 | rst.write("**Workaround:** " + output.workaround + "\n\n")
|
247 | 255 |
|
248 | 256 | rst.write("Sample code::\n\n" + indent(output.code, TAB) + "\n")
|
249 |
| - output_cpy = indent("".join(output.output_cpy[0:2]), TAB).rstrip() |
| 257 | + output_cpy = indent(output.output_cpy, TAB).rstrip() |
250 | 258 | output_cpy = ("::\n\n" if output_cpy != "" else "") + output_cpy
|
251 |
| - output_upy = indent("".join(output.output_upy[0:2]), TAB).rstrip() |
| 259 | + output_upy = indent(output.output_upy, TAB).rstrip() |
252 | 260 | output_upy = ("::\n\n" if output_upy != "" else "") + output_upy
|
253 | 261 | table = gen_table([["CPy output:", output_cpy], ["uPy output:", output_upy]])
|
254 | 262 | rst.write(table)
|
|
0 commit comments