|
2 | 2 | # these are all functions _testcapi exports whose name begins with 'test_'. |
3 | 3 |
|
4 | 4 | from __future__ import with_statement |
| 5 | +import os |
5 | 6 | import random |
6 | 7 | import subprocess |
7 | 8 | import sys |
@@ -141,8 +142,38 @@ class Test6012(unittest.TestCase): |
141 | 142 | def test(self): |
142 | 143 | self.assertEqual(_testcapi.argparsing("Hello", "World"), 1) |
143 | 144 |
|
| 145 | + |
| 146 | +class EmbeddingTest(unittest.TestCase): |
| 147 | + |
| 148 | + def test_subinterps(self): |
| 149 | + # XXX only tested under Unix checkouts |
| 150 | + basepath = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) |
| 151 | + oldcwd = os.getcwd() |
| 152 | + # This is needed otherwise we get a fatal error: |
| 153 | + # "Py_Initialize: Unable to get the locale encoding |
| 154 | + # LookupError: no codec search functions registered: can't find encoding" |
| 155 | + os.chdir(basepath) |
| 156 | + try: |
| 157 | + exe = os.path.join(basepath, "Modules", "_testembed") |
| 158 | + if not os.path.exists(exe): |
| 159 | + self.skipTest("%r doesn't exist" % exe) |
| 160 | + p = subprocess.Popen([exe], |
| 161 | + stdout=subprocess.PIPE, |
| 162 | + stderr=subprocess.PIPE) |
| 163 | + (out, err) = p.communicate() |
| 164 | + self.assertEqual(p.returncode, 0, |
| 165 | + "bad returncode %d, stderr is %r" % |
| 166 | + (p.returncode, err)) |
| 167 | + if support.verbose: |
| 168 | + print() |
| 169 | + print(out.decode('latin1')) |
| 170 | + print(err.decode('latin1')) |
| 171 | + finally: |
| 172 | + os.chdir(oldcwd) |
| 173 | + |
| 174 | + |
144 | 175 | def test_main(): |
145 | | - support.run_unittest(CAPITest) |
| 176 | + support.run_unittest(CAPITest, TestPendingCalls, Test6012, EmbeddingTest) |
146 | 177 |
|
147 | 178 | for name in dir(_testcapi): |
148 | 179 | if name.startswith('test_'): |
@@ -177,8 +208,6 @@ def callback(): |
177 | 208 | t.start() |
178 | 209 | t.join() |
179 | 210 |
|
180 | | - support.run_unittest(TestPendingCalls, Test6012) |
181 | | - |
182 | 211 |
|
183 | 212 | if __name__ == "__main__": |
184 | 213 | test_main() |
0 commit comments