Files
RustPython/extra_tests/snippets/stdlib_imp.py
Rex Ledesma 4e2e0b41c6 chore: add ruff format --check (#5774)
* chore: add `ruff format --check`

* fix tests
2025-05-12 14:20:01 +09:00

32 lines
674 B
Python

import _imp
import time as import_time
assert _imp.is_builtin("time") == True
assert _imp.is_builtin("os") == False
assert _imp.is_builtin("not existing module") == False
assert _imp.is_frozen("__hello__") == True
assert _imp.is_frozen("math") == False
class FakeSpec:
def __init__(self, name):
self.name = name
A = FakeSpec("time")
imp_time = _imp.create_builtin(A)
# FIXME: cpython3.9 fail
# assert imp_time.sleep == import_time.sleep
B = FakeSpec("not existing module")
assert _imp.create_builtin(B) == None
_imp.exec_builtin(imp_time) == 0
_imp.get_frozen_object("__hello__")
hello = _imp.init_frozen("__hello__")
assert hello.initialized == True