2011-04-10 08:58:44 -07:00
|
|
|
|
|
|
|
from twisted.trial import unittest
|
2015-07-17 22:03:53 +01:00
|
|
|
from twisted.python.monkey import MonkeyPatcher
|
2011-04-10 08:58:44 -07:00
|
|
|
|
|
|
|
import allmydata
|
2015-07-17 22:03:53 +01:00
|
|
|
import __builtin__
|
2011-04-10 08:58:44 -07:00
|
|
|
|
|
|
|
|
|
|
|
class T(unittest.TestCase):
|
2015-07-17 22:03:53 +01:00
|
|
|
def test_report_import_error(self):
|
|
|
|
real_import_func = __import__
|
2011-04-10 08:58:44 -07:00
|
|
|
def raiseIE_from_this_particular_func(name, *args):
|
|
|
|
if name == "foolscap":
|
|
|
|
marker = "wheeeyo"
|
|
|
|
raise ImportError(marker + " foolscap cant be imported")
|
|
|
|
else:
|
|
|
|
return real_import_func(name, *args)
|
|
|
|
|
2015-07-17 22:03:53 +01:00
|
|
|
# Let's run as little code as possible with __import__ patched.
|
|
|
|
patcher = MonkeyPatcher((__builtin__, '__import__', raiseIE_from_this_particular_func))
|
|
|
|
vers_and_locs = patcher.runWithPatches(allmydata.get_package_versions_and_locations)
|
2011-04-10 08:58:44 -07:00
|
|
|
|
|
|
|
for (pkgname, stuff) in vers_and_locs:
|
|
|
|
if pkgname == 'foolscap':
|
|
|
|
self.failUnless('wheeeyo' in str(stuff[2]), stuff)
|
|
|
|
self.failUnless('raiseIE_from_this_particular_func' in str(stuff[2]), stuff)
|