summaryrefslogtreecommitdiffstats
path: root/Lib/distutils/tests/test_sdist.py
diff options
context:
space:
mode:
authorTarek Ziadé <ziade.tarek@gmail.com>2009-02-14 14:10:23 (GMT)
committerTarek Ziadé <ziade.tarek@gmail.com>2009-02-14 14:10:23 (GMT)
commit1369900619d943d05342e7b781f1f3fb45ece4c9 (patch)
treef63793c2c87853e3bf59509f90c0edb2368ba2bf /Lib/distutils/tests/test_sdist.py
parenta4038038c69c72f96f1c7d435d50818c46892591 (diff)
downloadcpython-1369900619d943d05342e7b781f1f3fb45ece4c9.zip
cpython-1369900619d943d05342e7b781f1f3fb45ece4c9.tar.gz
cpython-1369900619d943d05342e7b781f1f3fb45ece4c9.tar.bz2
Fix for #5257: refactored all tests in distutils, so they use a temporary directory.
Diffstat (limited to 'Lib/distutils/tests/test_sdist.py')
-rw-r--r--Lib/distutils/tests/test_sdist.py50
1 files changed, 21 insertions, 29 deletions
diff --git a/Lib/distutils/tests/test_sdist.py b/Lib/distutils/tests/test_sdist.py
index 0d839b5..b2e9800 100644
--- a/Lib/distutils/tests/test_sdist.py
+++ b/Lib/distutils/tests/test_sdist.py
@@ -5,6 +5,7 @@ import shutil
import zipfile
from os.path import join
import sys
+import tempfile
from distutils.command.sdist import sdist
from distutils.core import Distribution
@@ -12,9 +13,6 @@ from distutils.tests.test_config import PyPIRCCommandTestCase
from distutils.errors import DistutilsExecError
from distutils.spawn import find_executable
-CURDIR = os.path.dirname(__file__)
-TEMP_PKG = join(CURDIR, 'temppkg')
-
SETUP_PY = """
from distutils.core import setup
import somecode
@@ -29,28 +27,25 @@ recursive-include somecode *
class sdistTestCase(PyPIRCCommandTestCase):
def setUp(self):
+ # PyPIRCCommandTestCase creates a temp dir already
+ # and put it in self.tmp_dir
PyPIRCCommandTestCase.setUp(self)
+ # setting up an environment
self.old_path = os.getcwd()
+ os.mkdir(join(self.tmp_dir, 'somecode'))
+ os.mkdir(join(self.tmp_dir, 'dist'))
+ # creating a MANIFEST, a package, and a README
+ self._write(join(self.tmp_dir, 'MANIFEST.in'), MANIFEST_IN)
+ self._write(join(self.tmp_dir, 'README'), 'xxx')
+ self._write(join(self.tmp_dir, 'somecode', '__init__.py'), '#')
+ self._write(join(self.tmp_dir, 'setup.py'), SETUP_PY)
+ os.chdir(self.tmp_dir)
def tearDown(self):
+ # back to normal
os.chdir(self.old_path)
- if os.path.exists(TEMP_PKG):
- shutil.rmtree(TEMP_PKG)
PyPIRCCommandTestCase.tearDown(self)
- def _init_tmp_pkg(self):
- if os.path.exists(TEMP_PKG):
- shutil.rmtree(TEMP_PKG)
- os.mkdir(TEMP_PKG)
- os.mkdir(join(TEMP_PKG, 'somecode'))
- os.mkdir(join(TEMP_PKG, 'dist'))
- # creating a MANIFEST, a package, and a README
- self._write(join(TEMP_PKG, 'MANIFEST.in'), MANIFEST_IN)
- self._write(join(TEMP_PKG, 'README'), 'xxx')
- self._write(join(TEMP_PKG, 'somecode', '__init__.py'), '#')
- self._write(join(TEMP_PKG, 'setup.py'), SETUP_PY)
- os.chdir(TEMP_PKG)
-
def _write(self, path, content):
f = open(path, 'w')
try:
@@ -62,18 +57,17 @@ class sdistTestCase(PyPIRCCommandTestCase):
# this test creates a package with some vcs dirs in it
# and launch sdist to make sure they get pruned
# on all systems
- self._init_tmp_pkg()
# creating VCS directories with some files in them
- os.mkdir(join(TEMP_PKG, 'somecode', '.svn'))
- self._write(join(TEMP_PKG, 'somecode', '.svn', 'ok.py'), 'xxx')
+ os.mkdir(join(self.tmp_dir, 'somecode', '.svn'))
+ self._write(join(self.tmp_dir, 'somecode', '.svn', 'ok.py'), 'xxx')
- os.mkdir(join(TEMP_PKG, 'somecode', '.hg'))
- self._write(join(TEMP_PKG, 'somecode', '.hg',
+ os.mkdir(join(self.tmp_dir, 'somecode', '.hg'))
+ self._write(join(self.tmp_dir, 'somecode', '.hg',
'ok'), 'xxx')
- os.mkdir(join(TEMP_PKG, 'somecode', '.git'))
- self._write(join(TEMP_PKG, 'somecode', '.git',
+ os.mkdir(join(self.tmp_dir, 'somecode', '.git'))
+ self._write(join(self.tmp_dir, 'somecode', '.git',
'ok'), 'xxx')
# now building a sdist
@@ -96,7 +90,7 @@ class sdistTestCase(PyPIRCCommandTestCase):
cmd.run()
# now let's check what we have
- dist_folder = join(TEMP_PKG, 'dist')
+ dist_folder = join(self.tmp_dir, 'dist')
files = os.listdir(dist_folder)
self.assertEquals(files, ['fake-1.0.zip'])
@@ -116,8 +110,6 @@ class sdistTestCase(PyPIRCCommandTestCase):
find_executable('gzip') is None):
return
- self._init_tmp_pkg()
-
# now building a sdist
dist = Distribution()
dist.script_name = 'setup.py'
@@ -137,7 +129,7 @@ class sdistTestCase(PyPIRCCommandTestCase):
cmd.run()
# making sure we have two files
- dist_folder = join(TEMP_PKG, 'dist')
+ dist_folder = join(self.tmp_dir, 'dist')
result = os.listdir(dist_folder)
result.sort()
self.assertEquals(result,