summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJim Mussared <jim.mussared@gmail.com>2023-05-23 22:03:50 +1000
committerDamien George <damien@micropython.org>2023-06-01 16:21:37 +1000
commit99a0c45aef6f0fd64f86a2048b999bdb7d74377c (patch)
treea6786dd8de2aadaa5aae6268cc917cba1035ca76 /tests
parentdfa7677e2fb1ff2314be04b5ea05346ac168fe84 (diff)
tests/import/import_pkg9.py: Add test for subpackage attribute.
When foo.bar is imported, bar is added as an attribute to foo. Previously this happened on every import, but should only happen on first import. This verifies the behavior for relative imports and overriding. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/import/import_pkg9.py16
-rw-r--r--tests/import/pkg9/__init__.py5
-rw-r--r--tests/import/pkg9/mod1.py2
-rw-r--r--tests/import/pkg9/mod2.py1
4 files changed, 24 insertions, 0 deletions
diff --git a/tests/import/import_pkg9.py b/tests/import/import_pkg9.py
new file mode 100644
index 000000000..4de028494
--- /dev/null
+++ b/tests/import/import_pkg9.py
@@ -0,0 +1,16 @@
+# tests that import only sets subpackage attribute on first import
+
+import pkg9
+
+pkg9.mod1()
+pkg9.mod2()
+
+import pkg9.mod1
+
+pkg9.mod1()
+pkg9.mod2()
+
+import pkg9.mod2
+
+pkg9.mod1()
+print(pkg9.mod2.__name__, type(pkg9.mod2).__name__)
diff --git a/tests/import/pkg9/__init__.py b/tests/import/pkg9/__init__.py
new file mode 100644
index 000000000..5d08d4b4a
--- /dev/null
+++ b/tests/import/pkg9/__init__.py
@@ -0,0 +1,5 @@
+from .mod1 import mod1
+
+
+def mod2():
+ print("mod2")
diff --git a/tests/import/pkg9/mod1.py b/tests/import/pkg9/mod1.py
new file mode 100644
index 000000000..7e7066bad
--- /dev/null
+++ b/tests/import/pkg9/mod1.py
@@ -0,0 +1,2 @@
+def mod1():
+ print("mod1")
diff --git a/tests/import/pkg9/mod2.py b/tests/import/pkg9/mod2.py
new file mode 100644
index 000000000..f4b3e265f
--- /dev/null
+++ b/tests/import/pkg9/mod2.py
@@ -0,0 +1 @@
+from . import mod2