2011-04-10 15:58:44 +00:00
|
|
|
|
|
|
|
from twisted.trial import unittest
|
2015-07-17 21:03:53 +00:00
|
|
|
from twisted.python.monkey import MonkeyPatcher
|
2011-04-10 15:58:44 +00:00
|
|
|
|
|
|
|
import allmydata
|
2015-07-17 21:03:53 +00:00
|
|
|
import __builtin__
|
2011-04-10 15:58:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
class T(unittest.TestCase):
|
2015-07-17 21:03:53 +00:00
|
|
|
def test_report_import_error(self):
|
2015-07-28 22:41:13 +00:00
|
|
|
marker = "wheeeyo"
|
2015-07-17 21:03:53 +00:00
|
|
|
real_import_func = __import__
|
2011-04-10 15:58:44 +00:00
|
|
|
def raiseIE_from_this_particular_func(name, *args):
|
|
|
|
if name == "foolscap":
|
|
|
|
raise ImportError(marker + " foolscap cant be imported")
|
|
|
|
else:
|
|
|
|
return real_import_func(name, *args)
|
|
|
|
|
2015-07-17 21:03:53 +00:00
|
|
|
# Let's run as little code as possible with __import__ patched.
|
|
|
|
patcher = MonkeyPatcher((__builtin__, '__import__', raiseIE_from_this_particular_func))
|
2015-07-28 22:41:13 +00:00
|
|
|
vers_and_locs, errors = patcher.runWithPatches(allmydata.get_package_versions_and_locations)
|
2011-04-10 15:58:44 +00:00
|
|
|
|
2015-07-28 22:41:13 +00:00
|
|
|
foolscap_stuffs = [stuff for (pkg, stuff) in vers_and_locs if pkg == 'foolscap']
|
|
|
|
self.failUnlessEqual(len(foolscap_stuffs), 1)
|
|
|
|
comment = str(foolscap_stuffs[0][2])
|
|
|
|
self.failUnlessIn(marker, comment)
|
|
|
|
self.failUnlessIn('raiseIE_from_this_particular_func', comment)
|
|
|
|
|
|
|
|
self.failUnless([e for e in errors if "dependency \'foolscap\' could not be imported" in e])
|