]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - src/allmydata/test/test_import.py
287c4f5a13e8e94a8dcad61cfed107309ed1f3ac
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / test / test_import.py
1
2 from twisted.trial import unittest
3 from twisted.python.monkey import MonkeyPatcher
4
5 import allmydata
6 import __builtin__
7
8
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":
14                 marker = "wheeeyo"
15                 raise ImportError(marker + " foolscap cant be imported")
16             else:
17                 return real_import_func(name, *args)
18
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)
22
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)