diff --git a/tests/import/builtin_ext.py b/tests/import/builtin_ext.py new file mode 100644 index 0000000000..dd8f95cbc1 --- /dev/null +++ b/tests/import/builtin_ext.py @@ -0,0 +1,36 @@ +import sys + +print(sys, hasattr(sys, "__file__")) + +sys.path.clear() +sys.path.append("ext") + +# All three should only get builtins, despite sys.py, usys.py, and +# micropython.py being in the path. +import micropython + +print(micropython, hasattr(micropython, "__file__")) +import sys + +print(sys, hasattr(sys, "__file__")) +import usys + +print(usys, hasattr(usys, "__file__")) + +# This should get os.py, which uses uos to get the builtin. +import os + +print(os, hasattr(os, "__file__"), os.sep, os.extra) + +# This should get time.py, which uses empty sys.path to get the builtin. +import time + +print(time, hasattr(time, "__file__"), time.sleep, time.extra) + +# These should get the builtins. +import uos + +print(uos, hasattr(uos, "__file__"), hasattr(uos, "extra")) +import utime + +print(utime, hasattr(utime, "__file__"), hasattr(utime, "extra")) diff --git a/tests/import/builtin_ext.py.exp b/tests/import/builtin_ext.py.exp new file mode 100644 index 0000000000..08496e14b7 --- /dev/null +++ b/tests/import/builtin_ext.py.exp @@ -0,0 +1,10 @@ + False + False + False + False +os from filesystem + True / 1 +time from filesystem + True 1 + False False + False False diff --git a/tests/import/ext/micropython.py b/tests/import/ext/micropython.py new file mode 100644 index 0000000000..88c8b770e1 --- /dev/null +++ b/tests/import/ext/micropython.py @@ -0,0 +1,2 @@ +# micropython is always builtin and cannot be overriden by the filesystem. +print("ERROR: micropython from filesystem") diff --git a/tests/import/ext/os.py b/tests/import/ext/os.py new file mode 100644 index 0000000000..e1448805d0 --- /dev/null +++ b/tests/import/ext/os.py @@ -0,0 +1,5 @@ +print("os from filesystem") + +from uos import * + +extra = 1 diff --git a/tests/import/ext/sys.py b/tests/import/ext/sys.py new file mode 100644 index 0000000000..71ee633e11 --- /dev/null +++ b/tests/import/ext/sys.py @@ -0,0 +1,2 @@ +# sys is always builtin and cannot be overriden by the filesystem. +print("ERROR: sys from filesystem") diff --git a/tests/import/ext/time.py b/tests/import/ext/time.py new file mode 100644 index 0000000000..6f2d4a42c0 --- /dev/null +++ b/tests/import/ext/time.py @@ -0,0 +1,14 @@ +print("time from filesystem") + +# Tests the CPython-compatible / non-u-prefix way of forcing a builtin +# import. +import sys + +_path = sys.path[:] +sys.path.clear() +from time import * + +sys.path.extend(_path) +del _path + +extra = 1 diff --git a/tests/import/ext/usys.py b/tests/import/ext/usys.py new file mode 100644 index 0000000000..d7629a4499 --- /dev/null +++ b/tests/import/ext/usys.py @@ -0,0 +1,3 @@ +# usys (and any u-prefix) is always builtin and cannot be overriden by the +# filesystem. +print("ERROR: usys from filesystem")