]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - src/allmydata/test/test_import.py
Don't show scary diagnostic warnings from --version[-and-path] (corrected). refs...
[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         marker = "wheeeyo"
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")
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, errors = patcher.runWithPatches(allmydata.get_package_versions_and_locations)
22
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)
28
29         self.failUnless([e for e in errors if "dependency \'foolscap\' could not be imported" in e])