From 6dd44f9f9b7ae8718b7b734ed3701d0d1c0f73a9 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 16 Jan 2025 22:11:36 +0100 Subject: [PATCH] Add submodule import tests Signed-off-by: Glenn Jocher --- tests/test_autoimport.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/tests/test_autoimport.py b/tests/test_autoimport.py index 7dce4e0..130fbab 100644 --- a/tests/test_autoimport.py +++ b/tests/test_autoimport.py @@ -10,32 +10,30 @@ class TestLazyImports(unittest.TestCase): def test_simple_imports(self): """Test basic import statements.""" with lazy(): - import json + import numpy as np + random_number = np.random.rand() self.assertIsInstance(json, 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)