]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blobdiff - src/allmydata/test/test_import.py
Eliminate mock dependency.
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / test / test_import.py
index 6ca7edfdd47d2c9909a2ddb61ae9811c709e5641..287c4f5a13e8e94a8dcad61cfed107309ed1f3ac 100644 (file)
@@ -1,14 +1,14 @@
 
 from twisted.trial import unittest
+from twisted.python.monkey import MonkeyPatcher
 
 import allmydata
-import mock
+import __builtin__
 
-real_import_func = __import__
 
 class T(unittest.TestCase):
-    @mock.patch('__builtin__.__import__')
-    def test_report_import_error(self, mockimport):
+    def test_report_import_error(self):
+        real_import_func = __import__
         def raiseIE_from_this_particular_func(name, *args):
             if name == "foolscap":
                 marker = "wheeeyo"
@@ -16,9 +16,10 @@ class T(unittest.TestCase):
             else:
                 return real_import_func(name, *args)
 
-        mockimport.side_effect = raiseIE_from_this_particular_func
+        # 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)
 
-        vers_and_locs =  allmydata.get_package_versions_and_locations()
         for (pkgname, stuff) in vers_and_locs:
             if pkgname == 'foolscap':
                 self.failUnless('wheeeyo' in str(stuff[2]), stuff)