Skip to content

Commit

Permalink
Add submodule import tests (#18)
Browse files Browse the repository at this point in the history
Signed-off-by: Glenn Jocher <[email protected]>
  • Loading branch information
glenn-jocher authored Jan 16, 2025
1 parent 89629cc commit 6d84aaf
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions tests/test_autoimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,30 @@ class TestLazyImports(unittest.TestCase):
def test_simple_imports(self):
"""Test basic import statements."""
with lazy():
import json
self.assertIsInstance(json, LazyLoader)

import numpy as np
random_number = np.random.rand()
self.assertIsInstance(np, LazyLoader)
self.assertLess(random_number, 1.0)

def test_attribute_access(self):
"""Test accessing attributes triggers actual import."""
with lazy():
import json
t0 = time.perf_counter()
result = json.dumps({"test": 123})
self.assertIsInstance(result, str)
self.assertLess(time.perf_counter() - t0, 1.0)

def test_nested_imports(self):
def test_submodule_imports(self):
"""Test nested module imports and functionality."""
with lazy():
import numpy as np
random_number = np.random.rand()
import numpy.random
random_number = numpy.random.rand()
self.assertLess(random_number, 1.0)

def test_direct_lazyloader(self):
"""Test direct LazyLoader instantiation."""
base64_lazy = LazyLoader("base64")
t0 = time.perf_counter()
result = base64_lazy.b64encode(b'test')
self.assertEqual(result, b'dGVzdA==')
self.assertLess(time.perf_counter() - t0, 1.0)

if __name__ == '__main__':
unittest.main(verbosity=2)

0 comments on commit 6d84aaf

Please sign in to comment.