MCPcopy Index your code
hub / github.com/python/cpython / test_whence

Method test_whence

Lib/test/test_interpreters/test_api.py:371–401  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

369 interp.id = 1_000_000
370
371 def test_whence(self):
372 main = interpreters.get_main()
373 interp = interpreters.create()
374
375 with self.subTest('main'):
376 self.assertEqual(main.whence, WHENCE_STR_RUNTIME)
377
378 with self.subTest('from _interpreters'):
379 self.assertEqual(interp.whence, WHENCE_STR_STDLIB)
380
381 with self.subTest('from C-API'):
382 text = self.run_temp_from_capi(f"""
383 import {interpreters.__name__} as interpreters
384 interp = interpreters.get_current()
385 print(repr(interp.whence))
386 """)
387 whence = eval(text)
388 self.assertEqual(whence, WHENCE_STR_CAPI)
389
390 with self.subTest('readonly'):
391 for value in [
392 None,
393 WHENCE_STR_UNKNOWN,
394 WHENCE_STR_RUNTIME,
395 WHENCE_STR_STDLIB,
396 WHENCE_STR_CAPI,
397 ]:
398 with self.assertRaises(AttributeError):
399 interp.whence = value
400 with self.assertRaises(AttributeError):
401 main.whence = value
402
403 def test_hashable(self):
404 interp = interpreters.create()

Callers

nothing calls this directly

Calls 5

run_temp_from_capiMethod · 0.80
createMethod · 0.45
subTestMethod · 0.45
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected