summaryrefslogtreecommitdiff
path: root/extras/tests/test_extras.py
diff options
context:
space:
mode:
authorRobert Collins <robertc@robertcollins.net>2016-05-18 18:54:35 +1200
committerRobert Collins <robertc@robertcollins.net>2016-05-18 20:58:37 +1200
commitd3a80f0ecd2c24c9d849a907ffe4680933a76b68 (patch)
tree7c48aa3de4338dfa51e825ddb25835346cf850a8 /extras/tests/test_extras.py
parent3ab32ecf6a17b574bd28d9abb4155580caf3191c (diff)
downloadpython-test-extras-d3a80f0ecd2c24c9d849a907ffe4680933a76b68.tar.gz
Handle import cycles.
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):