8000 tests/import/import_pkg9.py: Add test for subpackage attribute. · micropython/micropython@662e4f4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 662e4f4

Browse files
committed
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>
1 parent 465d660 commit 662e4f4

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

tests/import/import_pkg9.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# tests that import only sets subpackage attribute on first import
2+
3+
import pkg9
4+
5+
pkg9.mod1()
6+
pkg9.mod2()
7+
8+
import pkg9.mod1
9+
10+
pkg9.mod1()
11+
pkg9.mod2()
12+
13+
import pkg9.mod2
14+
15+
pkg9.mod1()
16+
print(pkg9.mod2.__name__, type(pkg9.mod2).__name__)

tests/import/pkg9/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from .mod1 import mod1
2+
3+
4+
def mod2():
5+
print("mod2")

tests/import/pkg9/mod1.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def mod1():
2+
print("mod1")

tests/import/pkg9/mod2.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import mod2

0 commit comments

Comments
 (0)
0