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):
11 real_import_func = __import__
12 def raiseIE_from_this_particular_func(name, *args):
13 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 = patcher.runWithPatches(allmydata.get_package_versions_and_locations)
23 for (pkgname, stuff) in vers_and_locs:
24 if pkgname == 'foolscap':
25 self.failUnless('wheeeyo' in str(stuff[2]), stuff)
26 self.failUnless('raiseIE_from_this_particular_func' in str(stuff[2]), stuff)