Mercurial > cpython-lru_cache-weakref
annotate Lib/distutils/tests/support.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 | d514a8b7ae78 |
| children | f8e696e4cff1 |
| rev | line source |
|---|---|
|
32365
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1 """Support code for distutils test cases.""" |
|
51626
e5522875b98c
Fix for #5257: refactored all tests in distutils, so they use a temporary directory.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
32943
diff
changeset
|
2 import os |
|
32365
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
3 import shutil |
|
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
4 import tempfile |
|
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
5 |
|
32943
9fb5138f58dd
make sure distutils logging is shut off in tests to avoid spurious output
Fred Drake <fdrake@acm.org>
parents:
32365
diff
changeset
|
6 from distutils import log |
|
52582
2b9c91668777
added tests for the clean command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51667
diff
changeset
|
7 from distutils.core import Distribution |
|
53976
1bec64b8dd17
refactored test_sysconfig so it uses test.test_support.EnvironmentVarGuard
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
52582
diff
changeset
|
8 from test.test_support import EnvironmentVarGuard |
|
32943
9fb5138f58dd
make sure distutils logging is shut off in tests to avoid spurious output
Fred Drake <fdrake@acm.org>
parents:
32365
diff
changeset
|
9 |
|
9fb5138f58dd
make sure distutils logging is shut off in tests to avoid spurious output
Fred Drake <fdrake@acm.org>
parents:
32365
diff
changeset
|
10 class LoggingSilencer(object): |
|
9fb5138f58dd
make sure distutils logging is shut off in tests to avoid spurious output
Fred Drake <fdrake@acm.org>
parents:
32365
diff
changeset
|
11 |
|
9fb5138f58dd
make sure distutils logging is shut off in tests to avoid spurious output
Fred Drake <fdrake@acm.org>
parents:
32365
diff
changeset
|
12 def setUp(self): |
|
9fb5138f58dd
make sure distutils logging is shut off in tests to avoid spurious output
Fred Drake <fdrake@acm.org>
parents:
32365
diff
changeset
|
13 super(LoggingSilencer, self).setUp() |
|
9fb5138f58dd
make sure distutils logging is shut off in tests to avoid spurious output
Fred Drake <fdrake@acm.org>
parents:
32365
diff
changeset
|
14 self.threshold = log.set_threshold(log.FATAL) |
|
54110
d514a8b7ae78
#6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53976
diff
changeset
|
15 # catching warnings |
|
d514a8b7ae78
#6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53976
diff
changeset
|
16 # when log will be replaced by logging |
|
d514a8b7ae78
#6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53976
diff
changeset
|
17 # we won't need such monkey-patch anymore |
|
d514a8b7ae78
#6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53976
diff
changeset
|
18 self._old_log = log.Log._log |
|
d514a8b7ae78
#6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53976
diff
changeset
|
19 log.Log._log = self._log |
|
d514a8b7ae78
#6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53976
diff
changeset
|
20 self.logs = [] |
|
32943
9fb5138f58dd
make sure distutils logging is shut off in tests to avoid spurious output
Fred Drake <fdrake@acm.org>
parents:
32365
diff
changeset
|
21 |
|
9fb5138f58dd
make sure distutils logging is shut off in tests to avoid spurious output
Fred Drake <fdrake@acm.org>
parents:
32365
diff
changeset
|
22 def tearDown(self): |
|
9fb5138f58dd
make sure distutils logging is shut off in tests to avoid spurious output
Fred Drake <fdrake@acm.org>
parents:
32365
diff
changeset
|
23 log.set_threshold(self.threshold) |
|
54110
d514a8b7ae78
#6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53976
diff
changeset
|
24 log.Log._log = self._old_log |
|
32943
9fb5138f58dd
make sure distutils logging is shut off in tests to avoid spurious output
Fred Drake <fdrake@acm.org>
parents:
32365
diff
changeset
|
25 super(LoggingSilencer, self).tearDown() |
|
9fb5138f58dd
make sure distutils logging is shut off in tests to avoid spurious output
Fred Drake <fdrake@acm.org>
parents:
32365
diff
changeset
|
26 |
|
54110
d514a8b7ae78
#6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53976
diff
changeset
|
27 def _log(self, level, msg, args): |
|
d514a8b7ae78
#6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53976
diff
changeset
|
28 self.logs.append((level, msg, args)) |
|
d514a8b7ae78
#6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53976
diff
changeset
|
29 |
|
d514a8b7ae78
#6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53976
diff
changeset
|
30 def get_logs(self, *levels): |
|
d514a8b7ae78
#6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53976
diff
changeset
|
31 def _format(msg, args): |
|
d514a8b7ae78
#6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53976
diff
changeset
|
32 if len(args) == 0: |
|
d514a8b7ae78
#6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53976
diff
changeset
|
33 return msg |
|
d514a8b7ae78
#6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53976
diff
changeset
|
34 return msg % args |
|
d514a8b7ae78
#6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53976
diff
changeset
|
35 return [_format(msg, args) for level, msg, args |
|
d514a8b7ae78
#6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53976
diff
changeset
|
36 in self.logs if level in levels] |
|
d514a8b7ae78
#6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53976
diff
changeset
|
37 |
|
d514a8b7ae78
#6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53976
diff
changeset
|
38 def clear_logs(self): |
|
d514a8b7ae78
#6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53976
diff
changeset
|
39 self.logs = [] |
|
32365
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
40 |
|
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
41 class TempdirManager(object): |
|
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
42 """Mix-in class that handles temporary directories for test cases. |
|
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
43 |
|
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
44 This is intended to be used with unittest.TestCase. |
|
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
45 """ |
|
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
46 |
|
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
47 def setUp(self): |
|
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
48 super(TempdirManager, self).setUp() |
|
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
49 self.tempdirs = [] |
|
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
50 |
|
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
51 def tearDown(self): |
|
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
52 super(TempdirManager, self).tearDown() |
|
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
53 while self.tempdirs: |
|
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
54 d = self.tempdirs.pop() |
|
51626
e5522875b98c
Fix for #5257: refactored all tests in distutils, so they use a temporary directory.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
32943
diff
changeset
|
55 shutil.rmtree(d, os.name in ('nt', 'cygwin')) |
|
32365
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
56 |
|
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
57 def mkdtemp(self): |
|
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
58 """Create a temporary directory that will be cleaned up. |
|
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
59 |
|
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
60 Returns the path of the directory. |
|
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
61 """ |
|
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
62 d = tempfile.mkdtemp() |
|
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
63 self.tempdirs.append(d) |
|
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
64 return d |
|
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
65 |
|
52582
2b9c91668777
added tests for the clean command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51667
diff
changeset
|
66 def write_file(self, path, content='xxx'): |
|
51667
982f9e2925a4
Fixed #2279: distutils.sdist.add_defaults now add files listed in package_data and data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51626
diff
changeset
|
67 """Writes a file in the given path. |
|
982f9e2925a4
Fixed #2279: distutils.sdist.add_defaults now add files listed in package_data and data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51626
diff
changeset
|
68 |
|
982f9e2925a4
Fixed #2279: distutils.sdist.add_defaults now add files listed in package_data and data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51626
diff
changeset
|
69 |
|
982f9e2925a4
Fixed #2279: distutils.sdist.add_defaults now add files listed in package_data and data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51626
diff
changeset
|
70 path can be a string or a sequence. |
|
982f9e2925a4
Fixed #2279: distutils.sdist.add_defaults now add files listed in package_data and data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51626
diff
changeset
|
71 """ |
|
982f9e2925a4
Fixed #2279: distutils.sdist.add_defaults now add files listed in package_data and data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51626
diff
changeset
|
72 if isinstance(path, (list, tuple)): |
|
982f9e2925a4
Fixed #2279: distutils.sdist.add_defaults now add files listed in package_data and data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51626
diff
changeset
|
73 path = os.path.join(*path) |
|
982f9e2925a4
Fixed #2279: distutils.sdist.add_defaults now add files listed in package_data and data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51626
diff
changeset
|
74 f = open(path, 'w') |
|
982f9e2925a4
Fixed #2279: distutils.sdist.add_defaults now add files listed in package_data and data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51626
diff
changeset
|
75 try: |
|
982f9e2925a4
Fixed #2279: distutils.sdist.add_defaults now add files listed in package_data and data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51626
diff
changeset
|
76 f.write(content) |
|
982f9e2925a4
Fixed #2279: distutils.sdist.add_defaults now add files listed in package_data and data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51626
diff
changeset
|
77 finally: |
|
982f9e2925a4
Fixed #2279: distutils.sdist.add_defaults now add files listed in package_data and data_files
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51626
diff
changeset
|
78 f.close() |
|
32365
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
79 |
|
52582
2b9c91668777
added tests for the clean command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51667
diff
changeset
|
80 def create_dist(self, pkg_name='foo', **kw): |
|
2b9c91668777
added tests for the clean command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51667
diff
changeset
|
81 """Will generate a test environment. |
|
2b9c91668777
added tests for the clean command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51667
diff
changeset
|
82 |
|
2b9c91668777
added tests for the clean command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51667
diff
changeset
|
83 This function creates: |
|
2b9c91668777
added tests for the clean command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51667
diff
changeset
|
84 - a Distribution instance using keywords |
|
2b9c91668777
added tests for the clean command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51667
diff
changeset
|
85 - a temporary directory with a package structure |
|
2b9c91668777
added tests for the clean command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51667
diff
changeset
|
86 |
|
2b9c91668777
added tests for the clean command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51667
diff
changeset
|
87 It returns the package directory and the distribution |
|
2b9c91668777
added tests for the clean command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51667
diff
changeset
|
88 instance. |
|
2b9c91668777
added tests for the clean command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51667
diff
changeset
|
89 """ |
|
2b9c91668777
added tests for the clean command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51667
diff
changeset
|
90 tmp_dir = self.mkdtemp() |
|
2b9c91668777
added tests for the clean command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51667
diff
changeset
|
91 pkg_dir = os.path.join(tmp_dir, pkg_name) |
|
2b9c91668777
added tests for the clean command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51667
diff
changeset
|
92 os.mkdir(pkg_dir) |
|
2b9c91668777
added tests for the clean command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51667
diff
changeset
|
93 dist = Distribution(attrs=kw) |
|
2b9c91668777
added tests for the clean command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51667
diff
changeset
|
94 |
|
2b9c91668777
added tests for the clean command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51667
diff
changeset
|
95 return pkg_dir, dist |
|
2b9c91668777
added tests for the clean command
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51667
diff
changeset
|
96 |
|
32365
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
97 class DummyCommand: |
|
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
98 """Class to store options for retrieval via set_undefined_options().""" |
|
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
99 |
|
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
100 def __init__(self, **kwargs): |
|
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
101 for kw, val in kwargs.items(): |
|
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
102 setattr(self, kw, val) |
|
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
103 |
|
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
104 def ensure_finalized(self): |
|
331e5d8b296f
move support code to a helper module to ease re-use
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
105 pass |
|
53976
1bec64b8dd17
refactored test_sysconfig so it uses test.test_support.EnvironmentVarGuard
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
52582
diff
changeset
|
106 |
|
1bec64b8dd17
refactored test_sysconfig so it uses test.test_support.EnvironmentVarGuard
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
52582
diff
changeset
|
107 class EnvironGuard(object): |
|
1bec64b8dd17
refactored test_sysconfig so it uses test.test_support.EnvironmentVarGuard
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
52582
diff
changeset
|
108 |
|
1bec64b8dd17
refactored test_sysconfig so it uses test.test_support.EnvironmentVarGuard
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
52582
diff
changeset
|
109 def setUp(self): |
|
1bec64b8dd17
refactored test_sysconfig so it uses test.test_support.EnvironmentVarGuard
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
52582
diff
changeset
|
110 super(EnvironGuard, self).setUp() |
|
1bec64b8dd17
refactored test_sysconfig so it uses test.test_support.EnvironmentVarGuard
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
52582
diff
changeset
|
111 self.environ = EnvironmentVarGuard() |
|
1bec64b8dd17
refactored test_sysconfig so it uses test.test_support.EnvironmentVarGuard
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
52582
diff
changeset
|
112 |
|
1bec64b8dd17
refactored test_sysconfig so it uses test.test_support.EnvironmentVarGuard
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
52582
diff
changeset
|
113 def tearDown(self): |
|
1bec64b8dd17
refactored test_sysconfig so it uses test.test_support.EnvironmentVarGuard
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
52582
diff
changeset
|
114 self.environ.__exit__() |
|
1bec64b8dd17
refactored test_sysconfig so it uses test.test_support.EnvironmentVarGuard
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
52582
diff
changeset
|
115 super(EnvironGuard, self).tearDown() |
