(self)
| 116 | return proc.stdout |
| 117 | |
| 118 | def test_sys_path_0(self): |
| 119 | # The main interpreter's sys.path[0] should be used by subinterpreters. |
| 120 | script = ''' |
| 121 | import sys |
| 122 | from concurrent import interpreters |
| 123 | |
| 124 | orig = sys.path[0] |
| 125 | |
| 126 | interp = interpreters.create() |
| 127 | interp.exec(f"""if True: |
| 128 | import json |
| 129 | import sys |
| 130 | print(json.dumps({{ |
| 131 | 'main': {orig!r}, |
| 132 | 'sub': sys.path[0], |
| 133 | }}, indent=4), flush=True) |
| 134 | """) |
| 135 | interp.close() |
| 136 | ''' |
| 137 | # <tmp>/ |
| 138 | # pkg/ |
| 139 | # __init__.py |
| 140 | # __main__.py |
| 141 | # script.py |
| 142 | # script.py |
| 143 | cwd = self.create_temp_dir() |
| 144 | self.write_script(cwd, 'pkg', '__init__.py', text='') |
| 145 | self.write_script(cwd, 'pkg', '__main__.py', text=script) |
| 146 | self.write_script(cwd, 'pkg', 'script.py', text=script) |
| 147 | self.write_script(cwd, 'script.py', text=script) |
| 148 | |
| 149 | cases = [ |
| 150 | ('script.py', cwd), |
| 151 | ('-m script', cwd), |
| 152 | ('-m pkg', cwd), |
| 153 | ('-m pkg.script', cwd), |
| 154 | ('-c "import script"', ''), |
| 155 | ] |
| 156 | for argv, expected in cases: |
| 157 | with self.subTest(f'python3 {argv}'): |
| 158 | out = self.run_python(argv, cwd=cwd) |
| 159 | data = json.loads(out) |
| 160 | sp0_main, sp0_sub = data['main'], data['sub'] |
| 161 | self.assertEqual(sp0_sub, sp0_main) |
| 162 | self.assertEqual(sp0_sub, expected) |
| 163 | # XXX Also check them all with the -P cmdline flag? |
| 164 | |
| 165 | |
| 166 | class FinalizationTests(TestBase): |
nothing calls this directly
no test coverage detected