summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2004-06-17 20:14:50 (GMT)
committerFred Drake <fdrake@acm.org>2004-06-17 20:14:50 (GMT)
commitb8ab8b6da809f9ceecd715113b2c860235186b02 (patch)
treef788648daf81cb0a80838a5f0a622a3f91c792f7 /Lib
parent9e1ac2496fd3a5e1126162b7734ff26aed4495df (diff)
downloadcpython-b8ab8b6da809f9ceecd715113b2c860235186b02.zip
cpython-b8ab8b6da809f9ceecd715113b2c860235186b02.tar.gz
cpython-b8ab8b6da809f9ceecd715113b2c860235186b02.tar.bz2
move support code to a helper module to ease re-use
Diffstat (limited to 'Lib')
-rw-r--r--Lib/distutils/tests/support.py41
-rw-r--r--Lib/distutils/tests/test_install_scripts.py41
2 files changed, 48 insertions, 34 deletions
diff --git a/Lib/distutils/tests/support.py b/Lib/distutils/tests/support.py
new file mode 100644
index 0000000..cef985d
--- /dev/null
+++ b/Lib/distutils/tests/support.py
@@ -0,0 +1,41 @@
+"""Support code for distutils test cases."""
+
+import shutil
+import tempfile
+
+
+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()
+ shutil.rmtree(d)
+
+ 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
diff --git a/Lib/distutils/tests/test_install_scripts.py b/Lib/distutils/tests/test_install_scripts.py
index 824f733..0a11abf 100644
--- a/Lib/distutils/tests/test_install_scripts.py
+++ b/Lib/distutils/tests/test_install_scripts.py
@@ -1,37 +1,21 @@
"""Tests for distutils.command.install_scripts."""
import os
-import shutil
-import tempfile
import unittest
from distutils.command.install_scripts import install_scripts
from distutils.core import Distribution
+from distutils.tests import support
-class InstallScriptsTestCase(unittest.TestCase):
- def setUp(self):
- self.tempdirs = []
-
- def tearDown(self):
- while self.tempdirs:
- d = self.tempdirs.pop()
- shutil.rmtree(d)
-
- 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 InstallScriptsTestCase(support.TempdirManager, unittest.TestCase):
def test_default_settings(self):
dist = Distribution()
- dist.command_obj["build"] = DummyCommand(build_scripts="/foo/bar")
- dist.command_obj["install"] = DummyCommand(
+ dist.command_obj["build"] = support.DummyCommand(
+ build_scripts="/foo/bar")
+ dist.command_obj["install"] = support.DummyCommand(
install_scripts="/splat/funk",
force=1,
skip_build=1,
@@ -71,8 +55,8 @@ class InstallScriptsTestCase(unittest.TestCase):
target = self.mkdtemp()
dist = Distribution()
- dist.command_obj["build"] = DummyCommand(build_scripts=source)
- dist.command_obj["install"] = DummyCommand(
+ dist.command_obj["build"] = support.DummyCommand(build_scripts=source)
+ dist.command_obj["install"] = support.DummyCommand(
install_scripts=target,
force=1,
skip_build=1,
@@ -86,17 +70,6 @@ class InstallScriptsTestCase(unittest.TestCase):
self.assert_(name in installed)
-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
-
-
def test_suite():
return unittest.makeSuite(InstallScriptsTestCase)