Imported Upstream version 1.1.2
[platform/upstream/python-nose.git] / functional_tests / test_commands.py
1 import os
2 import sys
3 import unittest
4 from nose.plugins.skip import SkipTest
5 from nose import commands
6 from StringIO import StringIO
7
8 support = os.path.join(
9     os.path.dirname(__file__), 'support', 'issue191')
10
11
12 class TestCommands(unittest.TestCase):
13     def setUp(self):
14         try:
15             import setuptools
16         except ImportError:
17             raise SkipTest("setuptools not available")
18         self.dir = os.getcwd()
19         self.stderr = sys.stderr
20         os.chdir(support)
21
22     def tearDown(self):
23         os.chdir(self.dir)
24         sys.stderr = self.stderr
25     
26     def test_setup_nosetests_command_works(self):
27         from setuptools.dist import Distribution
28         buf = StringIO()
29         sys.stderr = buf
30         cmd = commands.nosetests(
31             Distribution(attrs={'script_name': 'setup.py',
32                                 'package_dir': {'issue191': support}}))
33         cmd.finalize_options()
34         ## FIXME why doesn't Config see the chdir above?
35         print cmd._nosetests__config.workingDir
36         cmd._nosetests__config.workingDir = support
37         cmd._nosetests__config.stream = buf
38         try:
39             cmd.run()
40         except SystemExit, e:
41             self.assertFalse(e.args[0], buf.getvalue())
42         else:
43             self.fail("cmd.run() did not exit")
44
45
46 if __name__ == '__main__':
47     unittest.main()