Imported Upstream version 1.1.2
[platform/upstream/python-nose.git] / functional_tests / test_plugintest.py
1
2 import unittest, os
3 from nose.plugins import PluginTester, Plugin
4 from nose.tools import eq_
5 from cStringIO import StringIO
6
7 class StubPlugin(Plugin):
8     def options(self, parser, env=os.environ):
9         super(StubPlugin, self).options(parser, env=env)
10     def configure(self, options, conf):
11         pass    
12
13 class SomePluginTestCase(PluginTester):
14     activate = None # set this to --with-yourplugin, etc
15     plugins = [] # list of plugin instances
16     
17     def makeSuite(self):
18         class SomeTest(unittest.TestCase):
19             def runTest(self):
20                 raise ValueError("Now do something, plugin!")
21         return unittest.TestSuite([SomeTest()])      
22
23 class TestPluginTester(unittest.TestCase):
24     def _runPluginTest(self, test_case):
25         loader = unittest.TestLoader()
26         suite = loader.loadTestsFromTestCase(test_case)
27         res = unittest.TestResult()
28         suite(res)
29         return res
30         
31     def testPluginTesterExecsPlugin(self):
32         called = []
33         class MockExecPlugin(StubPlugin):
34             def configure(self, options, conf):
35                 called.append('configure')
36         
37         class MockExecTestCase(SomePluginTestCase, unittest.TestCase):
38             activate = '--with-mockexec'
39             plugins = [MockExecPlugin()]
40             
41             def test_something_anything(self):
42                 # here is where the test case would test
43                 # that the plugin interacted with stub tests
44                 pass      
45             
46         res = self._runPluginTest(MockExecTestCase)
47         eq_(res.testsRun, 1)
48         eq_(called[0], 'configure')
49
50 if __name__ == '__main__':
51     unittest.main()