Mercurial > cpython-lru_cache-weakref
annotate Lib/distutils/tests/test_core.py @ 54294:dba767bc3155 legacy-trunk
remove mention of old ctypes version
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Sat, 23 May 2009 20:59:09 +0000 |
| parents | 74c0a78114ae |
| children | 2df8bedec6d3 |
| 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 |
|
fb3c9bb76b29
- Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
9 import unittest |
|
fb3c9bb76b29
- Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
10 |
|
fb3c9bb76b29
- Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
11 |
|
fb3c9bb76b29
- Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
12 # 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
|
13 setup_using___file__ = """\ |
|
fb3c9bb76b29
- Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
14 |
|
fb3c9bb76b29
- Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
15 __file__ |
|
fb3c9bb76b29
- Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
16 |
|
fb3c9bb76b29
- Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
17 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
|
18 setup() |
|
fb3c9bb76b29
- Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
19 """ |
|
fb3c9bb76b29
- Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
20 |
|
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
|
21 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
|
22 |
|
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 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
|
24 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
|
25 |
|
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 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
|
27 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 """ |
|
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 |
|
46285
fb3c9bb76b29
- Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
30 |
|
fb3c9bb76b29
- Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
31 class CoreTestCase(unittest.TestCase): |
|
fb3c9bb76b29
- Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
32 |
|
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
|
33 def setUp(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
|
34 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
|
35 self.cleanup_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
|
36 |
|
46285
fb3c9bb76b29
- Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
37 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
|
38 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
|
39 self.cleanup_testfn() |
|
46285
fb3c9bb76b29
- Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
40 |
|
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 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
|
42 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
|
43 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
|
44 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
|
45 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
|
46 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
|
47 |
|
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 def write_setup(self, text, 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 open(path, "w").write(text) |
|
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 return path |
|
46285
fb3c9bb76b29
- Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
51 |
|
fb3c9bb76b29
- Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
52 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
|
53 # 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
|
54 # 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
|
55 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
|
56 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
|
57 |
|
4a113303f316
my previous change did what I said it should not: it changed the current
Fred Drake <fdrake@acm.org>
parents:
46285
diff
changeset
|
58 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
|
59 # 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
|
60 # 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
|
61 # 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
|
62 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
|
63 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
|
64 |
|
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 # 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
|
66 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
|
67 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
|
68 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
|
69 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
|
70 |
|
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 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
|
72 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
|
73 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
|
74 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
|
75 |
|
fb3c9bb76b29
- Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
76 |
|
fb3c9bb76b29
- Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
77 def test_suite(): |
|
fb3c9bb76b29
- Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
78 return unittest.makeSuite(CoreTestCase) |
|
fb3c9bb76b29
- Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
79 |
|
fb3c9bb76b29
- Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
80 if __name__ == "__main__": |
|
fb3c9bb76b29
- Issue #2385: distutils.core.run_script() makes __file__ available, so the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
81 unittest.main(defaultTest="test_suite") |
