2 from twisted.trial import unittest
3 from twisted.python.monkey import MonkeyPatcher
9 class T(unittest.TestCase):
10 def test_report_import_error(self):
12 real_import_func = __import__
13 def raiseIE_from_this_particular_func(name, *args):
14 if name == "foolscap":
15 raise ImportError(marker + " foolscap cant be imported")
17 return real_import_func(name, *args)
19 # Let's run as little code as possible with __import__ patched.
20 patcher = MonkeyPatcher((__builtin__, '__import__', raiseIE_from_this_particular_func))
21 vers_and_locs, errors = patcher.runWithPatches(allmydata.get_package_versions_and_locations)
23 foolscap_stuffs = [stuff for (pkg, stuff) in vers_and_locs if pkg == 'foolscap']
24 self.failUnlessEqual(len(foolscap_stuffs), 1)
25 comment = str(foolscap_stuffs[0][2])
26 self.failUnlessIn(marker, comment)
27 self.failUnlessIn('raiseIE_from_this_particular_func', comment)
29 self.failUnless([e for e in errors if "dependency \'foolscap\' could not be imported" in e])