~ubuntu-branches/ubuntu/maverick/python3.1/maverick

« back to all changes in this revision

Viewing changes to Lib/distutils/tests/test_core.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-03-23 00:01:27 UTC
  • Revision ID: james.westby@ubuntu.com-20090323000127-5fstfxju4ufrhthq
Tags: upstream-3.1~a1+20090322
ImportĀ upstreamĀ versionĀ 3.1~a1+20090322

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""Tests for distutils.core."""
 
2
 
 
3
import io
 
4
import distutils.core
 
5
import os
 
6
import shutil
 
7
import sys
 
8
import test.support
 
9
import unittest
 
10
 
 
11
 
 
12
# setup script that uses __file__
 
13
setup_using___file__ = """\
 
14
 
 
15
__file__
 
16
 
 
17
from distutils.core import setup
 
18
setup()
 
19
"""
 
20
 
 
21
setup_prints_cwd = """\
 
22
 
 
23
import os
 
24
print(os.getcwd())
 
25
 
 
26
from distutils.core import setup
 
27
setup()
 
28
"""
 
29
 
 
30
 
 
31
class CoreTestCase(unittest.TestCase):
 
32
 
 
33
    def setUp(self):
 
34
        self.old_stdout = sys.stdout
 
35
        self.cleanup_testfn()
 
36
 
 
37
    def tearDown(self):
 
38
        sys.stdout = self.old_stdout
 
39
        self.cleanup_testfn()
 
40
 
 
41
    def cleanup_testfn(self):
 
42
        path = test.support.TESTFN
 
43
        if os.path.isfile(path):
 
44
            os.remove(path)
 
45
        elif os.path.isdir(path):
 
46
            shutil.rmtree(path)
 
47
 
 
48
    def write_setup(self, text, path=test.support.TESTFN):
 
49
        open(path, "w").write(text)
 
50
        return path
 
51
 
 
52
    def test_run_setup_provides_file(self):
 
53
        # Make sure the script can use __file__; if that's missing, the test
 
54
        # setup.py script will raise NameError.
 
55
        distutils.core.run_setup(
 
56
            self.write_setup(setup_using___file__))
 
57
 
 
58
    def test_run_setup_uses_current_dir(self):
 
59
        # This tests that the setup script is run with the current directory
 
60
        # as its own current directory; this was temporarily broken by a
 
61
        # previous patch when TESTFN did not use the current directory.
 
62
        sys.stdout = io.StringIO()
 
63
        cwd = os.getcwd()
 
64
 
 
65
        # Create a directory and write the setup.py file there:
 
66
        os.mkdir(test.support.TESTFN)
 
67
        setup_py = os.path.join(test.support.TESTFN, "setup.py")
 
68
        distutils.core.run_setup(
 
69
            self.write_setup(setup_prints_cwd, path=setup_py))
 
70
 
 
71
        output = sys.stdout.getvalue()
 
72
        if output.endswith("\n"):
 
73
            output = output[:-1]
 
74
        self.assertEqual(cwd, output)
 
75
 
 
76
 
 
77
def test_suite():
 
78
    return unittest.makeSuite(CoreTestCase)
 
79
 
 
80
if __name__ == "__main__":
 
81
    unittest.main(defaultTest="test_suite")