Skip to content

Commit 6d84aaf

Browse files
authored
Add submodule import tests (#18)
Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
1 parent 89629cc commit 6d84aaf

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

tests/test_autoimport.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,30 @@ class TestLazyImports(unittest.TestCase):
1010
def test_simple_imports(self):
1111
"""Test basic import statements."""
1212
with lazy():
13-
import json
14-
self.assertIsInstance(json, LazyLoader)
15-
13+
import numpy as np
14+
random_number = np.random.rand()
15+
self.assertIsInstance(np, LazyLoader)
16+
self.assertLess(random_number, 1.0)
17+
1618
def test_attribute_access(self):
1719
"""Test accessing attributes triggers actual import."""
1820
with lazy():
1921
import json
20-
t0 = time.perf_counter()
2122
result = json.dumps({"test": 123})
2223
self.assertIsInstance(result, str)
23-
self.assertLess(time.perf_counter() - t0, 1.0)
2424

25-
def test_nested_imports(self):
25+
def test_submodule_imports(self):
2626
"""Test nested module imports and functionality."""
2727
with lazy():
28-
import numpy as np
29-
random_number = np.random.rand()
28+
import numpy.random
29+
random_number = numpy.random.rand()
3030
self.assertLess(random_number, 1.0)
3131

3232
def test_direct_lazyloader(self):
3333
"""Test direct LazyLoader instantiation."""
3434
base64_lazy = LazyLoader("base64")
35-
t0 = time.perf_counter()
3635
result = base64_lazy.b64encode(b'test')
3736
self.assertEqual(result, b'dGVzdA==')
38-
self.assertLess(time.perf_counter() - t0, 1.0)
3937

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

0 commit comments

Comments
 (0)