properly supports importing classes now
This commit is contained in:
parent
04a43c8819
commit
e811203152
|
@ -72,7 +72,7 @@ def _get_module(target):
|
|||
sys.path.append(path)
|
||||
|
||||
if not class_or_function:
|
||||
raise MissingMethodOrFunction("No Method or Function specified")
|
||||
raise MissingMethodOrFunction("No Method or Function specified in '%s'" % target)
|
||||
|
||||
__import__(module)
|
||||
|
||||
|
@ -87,4 +87,6 @@ def load(target):
|
|||
return getattr(sys.modules[module], function)
|
||||
|
||||
class_object = getattr(sys.modules[module], klass)
|
||||
return getattr(class_object, function)
|
||||
if function:
|
||||
return getattr(class_object, function)
|
||||
return class_object
|
||||
|
|
|
@ -71,3 +71,10 @@ class TestSimport(unittest.TestCase):
|
|||
self.assertEqual(external.externalmodule,
|
||||
sys.modules['external.externalmodule'])
|
||||
self.assertEqual(old, external.externalmodule)
|
||||
self.assertEqual(method, external.externalmodule.Blah.method_b)
|
||||
|
||||
def test_import_class(self):
|
||||
klass = simport.load("tests/external|"
|
||||
"external.externalmodule:Blah")
|
||||
import external.externalmodule
|
||||
self.assertEqual(klass, external.externalmodule.Blah)
|
||||
|
|
Loading…
Reference in New Issue