MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_with_extension

Method test_with_extension

Lib/test/test_import/__init__.py:450–479  ·  view source on GitHub ↗
(ext)

Source from the content-addressed store, hash-verified

448
449 def test_import(self):
450 def test_with_extension(ext):
451 # The extension is normally ".py", perhaps ".pyw".
452 source = TESTFN + ext
453 pyc = TESTFN + ".pyc"
454
455 with open(source, "w", encoding='utf-8') as f:
456 print("# This tests Python's ability to import a",
457 ext, "file.", file=f)
458 a = random.randrange(1000)
459 b = random.randrange(1000)
460 print("a =", a, file=f)
461 print("b =", b, file=f)
462
463 if TESTFN in sys.modules:
464 del sys.modules[TESTFN]
465 importlib.invalidate_caches()
466 try:
467 try:
468 mod = __import__(TESTFN)
469 except ImportError as err:
470 self.fail("import from %s failed: %s" % (ext, err))
471
472 self.assertEqual(mod.a, a,
473 "module loaded (%s) but contents invalid" % mod)
474 self.assertEqual(mod.b, b,
475 "module loaded (%s) but contents invalid" % mod)
476 finally:
477 forget(TESTFN)
478 unlink(source)
479 unlink(pyc)
480
481 sys.path.insert(0, os.curdir)
482 try:

Callers

nothing calls this directly

Calls 9

forgetFunction · 0.90
unlinkFunction · 0.85
randrangeMethod · 0.80
openFunction · 0.50
printFunction · 0.50
__import__Function · 0.50
invalidate_cachesMethod · 0.45
failMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected