Imported Upstream version 1.1.2
[platform/upstream/python-nose.git] / functional_tests / test_suite.py
1 import os
2 import sys
3 import unittest
4 from nose import case
5 from nose.suite import ContextSuiteFactory
6
7 support = os.path.abspath(os.path.join(os.path.dirname(__file__), 'support'))
8
9 class TestContextSuiteFactory(unittest.TestCase):
10
11     def setUp(self):
12         self._mods = sys.modules.copy()
13         self._path = sys.path[:]
14         sys.path.insert(0, os.path.join(support, 'package2'))
15
16     def tearDown(self):
17         to_del = [ m for m in sys.modules.keys() if
18                    m not in self._mods ]
19         if to_del:
20             for mod in to_del:
21                 del sys.modules[mod]
22         sys.modules.update(self._mods)
23         sys.path = self._path
24
25     def test_find_context(self):
26         from test_pak import test_mod
27         
28         factory = ContextSuiteFactory()
29         tests = [case.FunctionTestCase(test_mod.test_add),
30                  case.FunctionTestCase(test_mod.test_minus)]
31         suite = factory(tests)
32         self.assertEqual(suite.context, test_mod)
33
34     def test_ancestry(self):
35         from test_pak.test_sub.test_mod import TestMaths
36         from test_pak.test_sub import test_mod
37         from test_pak import test_sub
38         import test_pak
39         
40         factory = ContextSuiteFactory()
41         ancestry = [l for l in factory.ancestry(TestMaths)]
42         self.assertEqual(ancestry,
43                          [test_mod, test_sub, test_pak])
44
45
46 if __name__ == '__main__':
47     unittest.main()