summaryrefslogtreecommitdiff
path: root/functional_tests/test_plugintest.py
blob: 7d1a65b19b584c0ef136c92832e19d8d93c8d7d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

import unittest, os
from nose.plugins import PluginTester, Plugin
from nose.tools import eq_
from cStringIO import StringIO

class StubPlugin(Plugin):
    def options(self, parser, env=os.environ):
        super(StubPlugin, self).options(parser, env=env)
    def configure(self, options, conf):
        pass    

class SomePluginTestCase(PluginTester):
    activate = None # set this to --with-yourplugin, etc
    plugins = [] # list of plugin instances
    
    def makeSuite(self):
        class SomeTest(unittest.TestCase):
            def runTest(self):
                raise ValueError("Now do something, plugin!")
        return unittest.TestSuite([SomeTest()])      

class TestPluginTester(unittest.TestCase):
    def _runPluginTest(self, test_case):
        loader = unittest.TestLoader()
        suite = loader.loadTestsFromTestCase(test_case)
        res = unittest.TestResult()
        suite(res)
        return res
        
    def testPluginTesterExecsPlugin(self):
        called = []
        class MockExecPlugin(StubPlugin):
            def configure(self, options, conf):
                called.append('configure')
        
        class MockExecTestCase(SomePluginTestCase, unittest.TestCase):
            activate = '--with-mockexec'
            plugins = [MockExecPlugin()]
            
            def test_something_anything(self):
                # here is where the test case would test
                # that the plugin interacted with stub tests
                pass      
            
        res = self._runPluginTest(MockExecTestCase)
        eq_(res.testsRun, 1)
        eq_(called[0], 'configure')

if __name__ == '__main__':
    unittest.main()