| 1272 | |
| 1273 | @pytest.mark.skipif(IS_WASM, reason="wasm doesn't support asyncio") |
| 1274 | def test_printoptions_asyncio_safe(): |
| 1275 | asyncio = pytest.importorskip("asyncio") |
| 1276 | |
| 1277 | b = asyncio.Barrier(2) |
| 1278 | |
| 1279 | async def legacy_113(): |
| 1280 | np.set_printoptions(legacy='1.13', precision=12) |
| 1281 | await b.wait() |
| 1282 | po = np.get_printoptions() |
| 1283 | assert po['legacy'] == '1.13' |
| 1284 | assert po['precision'] == 12 |
| 1285 | orig_linewidth = po['linewidth'] |
| 1286 | with np.printoptions(linewidth=34, legacy='1.21'): |
| 1287 | po = np.get_printoptions() |
| 1288 | assert po['legacy'] == '1.21' |
| 1289 | assert po['precision'] == 12 |
| 1290 | assert po['linewidth'] == 34 |
| 1291 | po = np.get_printoptions() |
| 1292 | assert po['linewidth'] == orig_linewidth |
| 1293 | assert po['legacy'] == '1.13' |
| 1294 | assert po['precision'] == 12 |
| 1295 | |
| 1296 | async def legacy_125(): |
| 1297 | np.set_printoptions(legacy='1.25', precision=7) |
| 1298 | await b.wait() |
| 1299 | po = np.get_printoptions() |
| 1300 | assert po['legacy'] == '1.25' |
| 1301 | assert po['precision'] == 7 |
| 1302 | orig_linewidth = po['linewidth'] |
| 1303 | with np.printoptions(linewidth=6, legacy='1.13'): |
| 1304 | po = np.get_printoptions() |
| 1305 | assert po['legacy'] == '1.13' |
| 1306 | assert po['precision'] == 7 |
| 1307 | assert po['linewidth'] == 6 |
| 1308 | po = np.get_printoptions() |
| 1309 | assert po['linewidth'] == orig_linewidth |
| 1310 | assert po['legacy'] == '1.25' |
| 1311 | assert po['precision'] == 7 |
| 1312 | |
| 1313 | async def main(): |
| 1314 | await asyncio.gather(legacy_125(), legacy_125()) |
| 1315 | |
| 1316 | loop = asyncio.new_event_loop() |
| 1317 | asyncio.run(main()) |
| 1318 | loop.close() |
| 1319 | |
| 1320 | @pytest.mark.skipif(IS_WASM, reason="wasm doesn't support threads") |
| 1321 | @pytest.mark.thread_unsafe(reason="test is already explicitly multi-threaded") |