1
"""Tests for distutils.core."""
12
# setup script that uses __file__
13
setup_using___file__ = """\
17
from distutils.core import setup
21
setup_prints_cwd = """\
26
from distutils.core import setup
31
class CoreTestCase(unittest.TestCase):
34
self.old_stdout = sys.stdout
38
sys.stdout = self.old_stdout
41
def cleanup_testfn(self):
42
path = test.support.TESTFN
43
if os.path.isfile(path):
45
elif os.path.isdir(path):
48
def write_setup(self, text, path=test.support.TESTFN):
49
open(path, "w").write(text)
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__))
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()
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))
71
output = sys.stdout.getvalue()
72
if output.endswith("\n"):
74
self.assertEqual(cwd, output)
78
return unittest.makeSuite(CoreTestCase)
80
if __name__ == "__main__":
81
unittest.main(defaultTest="test_suite")