mirror of
https://github.com/python/cpython.git
synced 2025-08-02 16:13:13 +00:00
move support code to a helper module to ease re-use
This commit is contained in:
parent
9e1ac2496f
commit
b8ab8b6da8
2 changed files with 48 additions and 34 deletions
41
Lib/distutils/tests/support.py
Normal file
41
Lib/distutils/tests/support.py
Normal file
|
@ -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
|
|
@ -1,37 +1,21 @@
|
||||||
"""Tests for distutils.command.install_scripts."""
|
"""Tests for distutils.command.install_scripts."""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import shutil
|
|
||||||
import tempfile
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from distutils.command.install_scripts import install_scripts
|
from distutils.command.install_scripts import install_scripts
|
||||||
from distutils.core import Distribution
|
from distutils.core import Distribution
|
||||||
|
|
||||||
|
from distutils.tests import support
|
||||||
|
|
||||||
class InstallScriptsTestCase(unittest.TestCase):
|
|
||||||
|
|
||||||
def setUp(self):
|
class InstallScriptsTestCase(support.TempdirManager, unittest.TestCase):
|
||||||
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
|
|
||||||
|
|
||||||
def test_default_settings(self):
|
def test_default_settings(self):
|
||||||
dist = Distribution()
|
dist = Distribution()
|
||||||
dist.command_obj["build"] = DummyCommand(build_scripts="/foo/bar")
|
dist.command_obj["build"] = support.DummyCommand(
|
||||||
dist.command_obj["install"] = DummyCommand(
|
build_scripts="/foo/bar")
|
||||||
|
dist.command_obj["install"] = support.DummyCommand(
|
||||||
install_scripts="/splat/funk",
|
install_scripts="/splat/funk",
|
||||||
force=1,
|
force=1,
|
||||||
skip_build=1,
|
skip_build=1,
|
||||||
|
@ -71,8 +55,8 @@ class InstallScriptsTestCase(unittest.TestCase):
|
||||||
|
|
||||||
target = self.mkdtemp()
|
target = self.mkdtemp()
|
||||||
dist = Distribution()
|
dist = Distribution()
|
||||||
dist.command_obj["build"] = DummyCommand(build_scripts=source)
|
dist.command_obj["build"] = support.DummyCommand(build_scripts=source)
|
||||||
dist.command_obj["install"] = DummyCommand(
|
dist.command_obj["install"] = support.DummyCommand(
|
||||||
install_scripts=target,
|
install_scripts=target,
|
||||||
force=1,
|
force=1,
|
||||||
skip_build=1,
|
skip_build=1,
|
||||||
|
@ -86,17 +70,6 @@ class InstallScriptsTestCase(unittest.TestCase):
|
||||||
self.assert_(name in installed)
|
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():
|
def test_suite():
|
||||||
return unittest.makeSuite(InstallScriptsTestCase)
|
return unittest.makeSuite(InstallScriptsTestCase)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue