Skip to content

Commit 617e9d1

Browse files
committed
Add more tests
1 parent 0409481 commit 617e9d1

File tree

9 files changed

+895
-0
lines changed

9 files changed

+895
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Module that exists but doesn't have expected attributes
2+
x = 42
3+
# No 'nonexistent_attr' here
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Module that raises an error during import
2+
raise ValueError("This module always fails to import")
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Test that globals() returns lazy proxy objects without reifying
2+
lazy import test.test_import.data.lazy_imports.basic2 as basic2
3+
4+
def get_from_globals():
5+
g = globals()
6+
return g['basic2']
7+
8+
def get_direct():
9+
return basic2
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SyntaxError: lazy import inside class body is not allowed
2+
class Foo:
3+
lazy import json
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Test __lazy_modules__ with from imports
2+
__lazy_modules__ = ['test.test_import.data.lazy_imports.basic2']
3+
from test.test_import.data.lazy_imports.basic2 import x, f
4+
5+
def get_x():
6+
return x
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Test that lazy from import with multiple names only reifies accessed names
2+
lazy from test.test_import.data.lazy_imports.basic2 import f, x
3+
4+
def get_globals():
5+
return globals()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Test relative imports with lazy keyword
2+
lazy from . import basic2
3+
4+
def get_basic2():
5+
return basic2
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Test relative from imports with lazy keyword
2+
lazy from .basic2 import x, f
3+
4+
def get_x():
5+
return x
6+
7+
def get_f():
8+
return f

0 commit comments

Comments
 (0)