annotate Lib/distutils/tests/test_core.py @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents 6270946115d0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
46285
fb3c9bb76b29 - Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1 """Tests for distutils.core."""
fb3c9bb76b29 - Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
2
fb3c9bb76b29 - Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
3 import StringIO
fb3c9bb76b29 - Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
4 import distutils.core
fb3c9bb76b29 - Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
5 import os
46290
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
6 import shutil
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
7 import sys
46285
fb3c9bb76b29 - Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
8 import test.test_support
67854
6270946115d0 Merged revisions 86236,86240,86332,86340,87271,87273,87447 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 66348
diff changeset
9 from test.test_support import captured_stdout, run_unittest
46285
fb3c9bb76b29 - Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
10 import unittest
56584
e67eb9660041 Changed distutils tests to avoid environment alteration
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 56152
diff changeset
11 from distutils.tests import support
46285
fb3c9bb76b29 - Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
12
fb3c9bb76b29 - Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
13 # setup script that uses __file__
fb3c9bb76b29 - Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
14 setup_using___file__ = """\
fb3c9bb76b29 - Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
15
fb3c9bb76b29 - Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
16 __file__
fb3c9bb76b29 - Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
17
fb3c9bb76b29 - Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
18 from distutils.core import setup
fb3c9bb76b29 - Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
19 setup()
fb3c9bb76b29 - Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
20 """
fb3c9bb76b29 - Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
21
46290
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
22 setup_prints_cwd = """\
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
23
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
24 import os
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
25 print os.getcwd()
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
26
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
27 from distutils.core import setup
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
28 setup()
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
29 """
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
30
46285
fb3c9bb76b29 - Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
31
56584
e67eb9660041 Changed distutils tests to avoid environment alteration
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 56152
diff changeset
32 class CoreTestCase(support.EnvironGuard, unittest.TestCase):
46285
fb3c9bb76b29 - Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
33
46290
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
34 def setUp(self):
56584
e67eb9660041 Changed distutils tests to avoid environment alteration
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 56152
diff changeset
35 super(CoreTestCase, self).setUp()
46290
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
36 self.old_stdout = sys.stdout
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
37 self.cleanup_testfn()
56584
e67eb9660041 Changed distutils tests to avoid environment alteration
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 56152
diff changeset
38 self.old_argv = sys.argv, sys.argv[:]
46290
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
39
46285
fb3c9bb76b29 - Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
40 def tearDown(self):
46290
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
41 sys.stdout = self.old_stdout
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
42 self.cleanup_testfn()
56584
e67eb9660041 Changed distutils tests to avoid environment alteration
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 56152
diff changeset
43 sys.argv = self.old_argv[0]
e67eb9660041 Changed distutils tests to avoid environment alteration
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 56152
diff changeset
44 sys.argv[:] = self.old_argv[1]
e67eb9660041 Changed distutils tests to avoid environment alteration
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 56152
diff changeset
45 super(CoreTestCase, self).tearDown()
46285
fb3c9bb76b29 - Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
46
46290
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
47 def cleanup_testfn(self):
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
48 path = test.test_support.TESTFN
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
49 if os.path.isfile(path):
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
50 os.remove(path)
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
51 elif os.path.isdir(path):
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
52 shutil.rmtree(path)
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
53
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
54 def write_setup(self, text, path=test.test_support.TESTFN):
66008
a17b21c27a33 Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 56584
diff changeset
55 f = open(path, "w")
a17b21c27a33 Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 56584
diff changeset
56 try:
a17b21c27a33 Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 56584
diff changeset
57 f.write(text)
a17b21c27a33 Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 56584
diff changeset
58 finally:
a17b21c27a33 Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 56584
diff changeset
59 f.close()
46290
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
60 return path
46285
fb3c9bb76b29 - Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
61
fb3c9bb76b29 - Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
62 def test_run_setup_provides_file(self):
fb3c9bb76b29 - Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
63 # Make sure the script can use __file__; if that's missing, the test
fb3c9bb76b29 - Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
64 # setup.py script will raise NameError.
46290
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
65 distutils.core.run_setup(
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
66 self.write_setup(setup_using___file__))
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
67
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
68 def test_run_setup_uses_current_dir(self):
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
69 # This tests that the setup script is run with the current directory
55049
74c0a78114ae Merged revisions 69846 via svnmerge from
Jesus Cea <jcea@jcea.es>
parents: 46291
diff changeset
70 # as its own current directory; this was temporarily broken by a
46290
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
71 # previous patch when TESTFN did not use the current directory.
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
72 sys.stdout = StringIO.StringIO()
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
73 cwd = os.getcwd()
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
74
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
75 # Create a directory and write the setup.py file there:
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
76 os.mkdir(test.test_support.TESTFN)
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
77 setup_py = os.path.join(test.test_support.TESTFN, "setup.py")
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
78 distutils.core.run_setup(
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
79 self.write_setup(setup_prints_cwd, path=setup_py))
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
80
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
81 output = sys.stdout.getvalue()
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
82 if output.endswith("\n"):
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
83 output = output[:-1]
4a113303f316 my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents: 46285
diff changeset
84 self.assertEqual(cwd, output)
46285
fb3c9bb76b29 - Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
85
56152
2df8bedec6d3 improved distutils test coverage: now the DEBUG mode is covered too (will help fix the issue #6954 in py3k branch)
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 55049
diff changeset
86 def test_debug_mode(self):
2df8bedec6d3 improved distutils test coverage: now the DEBUG mode is covered too (will help fix the issue #6954 in py3k branch)
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 55049
diff changeset
87 # this covers the code called when DEBUG is set
2df8bedec6d3 improved distutils test coverage: now the DEBUG mode is covered too (will help fix the issue #6954 in py3k branch)
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 55049
diff changeset
88 sys.argv = ['setup.py', '--name']
2df8bedec6d3 improved distutils test coverage: now the DEBUG mode is covered too (will help fix the issue #6954 in py3k branch)
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 55049
diff changeset
89 with captured_stdout() as stdout:
2df8bedec6d3 improved distutils test coverage: now the DEBUG mode is covered too (will help fix the issue #6954 in py3k branch)
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 55049
diff changeset
90 distutils.core.setup(name='bar')
2df8bedec6d3 improved distutils test coverage: now the DEBUG mode is covered too (will help fix the issue #6954 in py3k branch)
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 55049
diff changeset
91 stdout.seek(0)
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 66008
diff changeset
92 self.assertEqual(stdout.read(), 'bar\n')
56152
2df8bedec6d3 improved distutils test coverage: now the DEBUG mode is covered too (will help fix the issue #6954 in py3k branch)
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 55049
diff changeset
93
2df8bedec6d3 improved distutils test coverage: now the DEBUG mode is covered too (will help fix the issue #6954 in py3k branch)
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 55049
diff changeset
94 distutils.core.DEBUG = True
2df8bedec6d3 improved distutils test coverage: now the DEBUG mode is covered too (will help fix the issue #6954 in py3k branch)
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 55049
diff changeset
95 try:
2df8bedec6d3 improved distutils test coverage: now the DEBUG mode is covered too (will help fix the issue #6954 in py3k branch)
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 55049
diff changeset
96 with captured_stdout() as stdout:
2df8bedec6d3 improved distutils test coverage: now the DEBUG mode is covered too (will help fix the issue #6954 in py3k branch)
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 55049
diff changeset
97 distutils.core.setup(name='bar')
2df8bedec6d3 improved distutils test coverage: now the DEBUG mode is covered too (will help fix the issue #6954 in py3k branch)
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 55049
diff changeset
98 finally:
2df8bedec6d3 improved distutils test coverage: now the DEBUG mode is covered too (will help fix the issue #6954 in py3k branch)
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 55049
diff changeset
99 distutils.core.DEBUG = False
2df8bedec6d3 improved distutils test coverage: now the DEBUG mode is covered too (will help fix the issue #6954 in py3k branch)
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 55049
diff changeset
100 stdout.seek(0)
2df8bedec6d3 improved distutils test coverage: now the DEBUG mode is covered too (will help fix the issue #6954 in py3k branch)
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 55049
diff changeset
101 wanted = "options (after parsing config files):\n"
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 66008
diff changeset
102 self.assertEqual(stdout.readlines()[0], wanted)
46285
fb3c9bb76b29 - Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
103
fb3c9bb76b29 - Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
104 def test_suite():
fb3c9bb76b29 - Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
105 return unittest.makeSuite(CoreTestCase)
fb3c9bb76b29 - Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
106
fb3c9bb76b29 - Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
107 if __name__ == "__main__":
67854
6270946115d0 Merged revisions 86236,86240,86332,86340,87271,87273,87447 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 66348
diff changeset
108 run_unittest(test_suite())