~divmod-dev/divmod.org/trunk

« back to all changes in this revision

Viewing changes to Epsilon/epsilon/test/test_setuphelper.py

  • Committer: Jean-Paul Calderone
  • Date: 2014-06-29 20:33:04 UTC
  • mfrom: (2749.1.1 remove-epsilon-1325289)
  • Revision ID: exarkun@twistedmatrix.com-20140629203304-gdkmbwl1suei4m97
mergeĀ lp:~exarkun/divmod.org/remove-epsilon-1325289

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
import sys
3
 
 
4
 
from twisted.trial import unittest
5
 
from twisted.python import log
6
 
from twisted.python.reflect import namedAny
7
 
from epsilon.setuphelper import _regeneratePluginCache
8
 
 
9
 
class TestCacheRegeneration(unittest.TestCase):
10
 
    removeModules = []
11
 
    def setUp(self):
12
 
        self.removedModules = []
13
 
        for modname in self.removeModules:
14
 
            try:
15
 
                module = namedAny(modname)
16
 
                self.removedModules.append(module)
17
 
            except:
18
 
                print 'COULD NOT LOAD', modname
19
 
        self.sysmodules = sys.modules.copy()
20
 
        self.syspath = sys.path[:]
21
 
 
22
 
        for module in self.removedModules:
23
 
            for ent in self.syspath:
24
 
                if module.__file__.startswith(ent):
25
 
                    while ent in sys.path:
26
 
                        sys.path.remove(ent)
27
 
            rem = 0
28
 
            for modname in self.sysmodules:
29
 
                if modname.startswith(module.__name__):
30
 
                    rem += 1
31
 
                    sys.modules.pop(modname)
32
 
            assert rem, 'NO HITS: %r:%r' % (module,module.__name__)
33
 
 
34
 
    def testRegeneratingIt(self):
35
 
        for mod in self.removedModules:
36
 
            self.failIf(mod.__name__ in sys.modules, 'Started with %r loaded: %r' % (mod.__name__, sys.path))
37
 
        _regeneratePluginCache(['axiom', 'xmantissa'])
38
 
        log.flushErrors(ImportError) # This is necessary since there are Axiom
39
 
                                     # plugins that depend on Mantissa, so when
40
 
                                     # Axiom is installed, Mantissa-dependent
41
 
                                     # powerups are, but Mantissa isn't some
42
 
                                     # harmless tracebacks are printed.
43
 
        for mod in self.removedModules:
44
 
            self.failIf(mod.__name__ in sys.modules, 'Loaded %r: %r' % (mod.__name__, sys.path))
45
 
 
46
 
    testRegeneratingIt.skip = """
47
 
    This test really ought to be the dependency-direction test from old
48
 
    Quotient.  As it currently stands it's just broken.
49
 
    """
50
 
 
51
 
    def tearDown(self):
52
 
        sys.path[:] = self.syspath
53
 
        sys.modules.clear()
54
 
        sys.modules.update(self.sysmodules)
55
 
 
56
 
class WithoutAxiom(TestCacheRegeneration):
57
 
    removeModules = ['axiom']
58
 
 
59
 
class WithoutMantissa(TestCacheRegeneration):
60
 
    removeModules = ['xmantissa']
61
 
 
62
 
class WithoutEither(TestCacheRegeneration):
63
 
    removeModules = ['xmantissa', 'axiom']