summaryrefslogtreecommitdiff
path: root/extras/tests/test_extras.py
diff options
context:
space:
mode:
Diffstat (limited to 'extras/tests/test_extras.py')
-rw-r--r--extras/tests/test_extras.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/extras/tests/test_extras.py b/extras/tests/test_extras.py
index be1ed1c..d048bda 100644
--- a/extras/tests/test_extras.py
+++ b/extras/tests/test_extras.py
@@ -1,5 +1,8 @@
# Copyright (c) 2010-2012 extras developers. See LICENSE for details.
+import sys
+import types
+
from testtools import TestCase
from testtools.matchers import (
Equals,
@@ -125,6 +128,22 @@ class TestTryImport(TestCase):
# the error callback is not called on success.
check_error_callback(self, try_import, 'os.path', 0, True)
+ def test_handle_partly_imported_name(self):
+ # try_import('thing.other') when thing.other is mid-import
+ # used to fail because thing.other is not assigned until thing.other
+ # finishes its import - but thing.other is accessible via sys.modules.
+ outer = types.ModuleType("extras.outer")
+ inner = types.ModuleType("extras.outer.inner")
+ inner.attribute = object()
+ self.addCleanup(sys.modules.pop, "extras.outer", None)
+ self.addCleanup(sys.modules.pop, "extras.outer.inner", None)
+ sys.modules["extras.outer"] = outer
+ sys.modules["extras.outer.inner"] = inner
+ result = try_import("extras.outer.inner.attribute")
+ self.expectThat(result, Is(inner.attribute))
+ result = try_import("extras.outer.inner")
+ self.expectThat(result, Is(inner))
+
class TestTryImports(TestCase):