2004-06-17 17:14:50 -03:00
|
|
|
"""Support code for distutils test cases."""
|
2009-02-14 10:10:23 -04:00
|
|
|
import os
|
2004-06-17 17:14:50 -03:00
|
|
|
import shutil
|
|
|
|
import tempfile
|
|
|
|
|
2004-08-03 15:53:07 -03:00
|
|
|
from distutils import log
|
|
|
|
|
|
|
|
|
|
|
|
class LoggingSilencer(object):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(LoggingSilencer, self).setUp()
|
|
|
|
self.threshold = log.set_threshold(log.FATAL)
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
log.set_threshold(self.threshold)
|
|
|
|
super(LoggingSilencer, self).tearDown()
|
|
|
|
|
2004-06-17 17:14:50 -03:00
|
|
|
|
|
|
|
class TempdirManager(object):
|
|
|
|
"""Mix-in class that handles temporary directories for test cases.
|
|
|
|
|
|
|
|
This is intended to be used with unittest.TestCase.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TempdirManager, self).setUp()
|
|
|
|
self.tempdirs = []
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
super(TempdirManager, self).tearDown()
|
|
|
|
while self.tempdirs:
|
|
|
|
d = self.tempdirs.pop()
|
2009-02-14 10:10:23 -04:00
|
|
|
shutil.rmtree(d, os.name in ('nt', 'cygwin'))
|
2004-06-17 17:14:50 -03:00
|
|
|
|
|
|
|
def mkdtemp(self):
|
|
|
|
"""Create a temporary directory that will be cleaned up.
|
|
|
|
|
|
|
|
Returns the path of the directory.
|
|
|
|
"""
|
|
|
|
d = tempfile.mkdtemp()
|
|
|
|
self.tempdirs.append(d)
|
|
|
|
return d
|
|
|
|
|
|
|
|
|
|
|
|
class DummyCommand:
|
|
|
|
"""Class to store options for retrieval via set_undefined_options()."""
|
|
|
|
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
for kw, val in kwargs.items():
|
|
|
|
setattr(self, kw, val)
|
|
|
|
|
|
|
|
def ensure_finalized(self):
|
|
|
|
pass
|