~ubuntu-branches/ubuntu/maverick/python3.1/maverick

« back to all changes in this revision

Viewing changes to Lib/distutils/tests/support.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-03-23 00:01:27 UTC
  • Revision ID: james.westby@ubuntu.com-20090323000127-5fstfxju4ufrhthq
Tags: upstream-3.1~a1+20090322
ImportĀ upstreamĀ versionĀ 3.1~a1+20090322

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""Support code for distutils test cases."""
 
2
import os
 
3
import shutil
 
4
import tempfile
 
5
 
 
6
from distutils import log
 
7
 
 
8
 
 
9
class LoggingSilencer(object):
 
10
 
 
11
    def setUp(self):
 
12
        super().setUp()
 
13
        self.threshold = log.set_threshold(log.FATAL)
 
14
 
 
15
    def tearDown(self):
 
16
        log.set_threshold(self.threshold)
 
17
        super().tearDown()
 
18
 
 
19
 
 
20
class TempdirManager(object):
 
21
    """Mix-in class that handles temporary directories for test cases.
 
22
 
 
23
    This is intended to be used with unittest.TestCase.
 
24
    """
 
25
 
 
26
    def setUp(self):
 
27
        super().setUp()
 
28
        self.tempdirs = []
 
29
 
 
30
    def tearDown(self):
 
31
        super().tearDown()
 
32
        while self.tempdirs:
 
33
            d = self.tempdirs.pop()
 
34
            shutil.rmtree(d, os.name in ('nt', 'cygwin'))
 
35
 
 
36
    def mkdtemp(self):
 
37
        """Create a temporary directory that will be cleaned up.
 
38
 
 
39
        Returns the path of the directory.
 
40
        """
 
41
        d = tempfile.mkdtemp()
 
42
        self.tempdirs.append(d)
 
43
        return d
 
44
 
 
45
    def write_file(self, path, content):
 
46
        """Writes a file in the given path.
 
47
 
 
48
 
 
49
        path can be a string or a sequence.
 
50
        """
 
51
        if isinstance(path, (list, tuple)):
 
52
            path = os.path.join(*path)
 
53
        f = open(path, 'w')
 
54
        try:
 
55
            f.write(content)
 
56
        finally:
 
57
            f.close()
 
58
 
 
59
class DummyCommand:
 
60
    """Class to store options for retrieval via set_undefined_options()."""
 
61
 
 
62
    def __init__(self, **kwargs):
 
63
        for kw, val in kwargs.items():
 
64
            setattr(self, kw, val)
 
65
 
 
66
    def ensure_finalized(self):
 
67
        pass