55import zipfile
66from os .path import join
77import sys
8+ import tempfile
89
910from distutils .command .sdist import sdist
1011from distutils .core import Distribution
1112from distutils .tests .test_config import PyPIRCCommandTestCase
1213from distutils .errors import DistutilsExecError
1314from distutils .spawn import find_executable
1415
15- CURDIR = os .path .dirname (__file__ )
16- TEMP_PKG = join (CURDIR , 'temppkg' )
17-
1816SETUP_PY = """
1917from distutils.core import setup
2018import somecode
2927class sdistTestCase (PyPIRCCommandTestCase ):
3028
3129 def setUp (self ):
30+ # PyPIRCCommandTestCase creates a temp dir already
31+ # and put it in self.tmp_dir
3232 PyPIRCCommandTestCase .setUp (self )
33+ # setting up an environment
3334 self .old_path = os .getcwd ()
35+ os .mkdir (join (self .tmp_dir , 'somecode' ))
36+ os .mkdir (join (self .tmp_dir , 'dist' ))
37+ # creating a MANIFEST, a package, and a README
38+ self ._write (join (self .tmp_dir , 'MANIFEST.in' ), MANIFEST_IN )
39+ self ._write (join (self .tmp_dir , 'README' ), 'xxx' )
40+ self ._write (join (self .tmp_dir , 'somecode' , '__init__.py' ), '#' )
41+ self ._write (join (self .tmp_dir , 'setup.py' ), SETUP_PY )
42+ os .chdir (self .tmp_dir )
3443
3544 def tearDown (self ):
45+ # back to normal
3646 os .chdir (self .old_path )
37- if os .path .exists (TEMP_PKG ):
38- shutil .rmtree (TEMP_PKG )
3947 PyPIRCCommandTestCase .tearDown (self )
4048
41- def _init_tmp_pkg (self ):
42- if os .path .exists (TEMP_PKG ):
43- shutil .rmtree (TEMP_PKG )
44- os .mkdir (TEMP_PKG )
45- os .mkdir (join (TEMP_PKG , 'somecode' ))
46- os .mkdir (join (TEMP_PKG , 'dist' ))
47- # creating a MANIFEST, a package, and a README
48- self ._write (join (TEMP_PKG , 'MANIFEST.in' ), MANIFEST_IN )
49- self ._write (join (TEMP_PKG , 'README' ), 'xxx' )
50- self ._write (join (TEMP_PKG , 'somecode' , '__init__.py' ), '#' )
51- self ._write (join (TEMP_PKG , 'setup.py' ), SETUP_PY )
52- os .chdir (TEMP_PKG )
53-
5449 def _write (self , path , content ):
5550 f = open (path , 'w' )
5651 try :
@@ -62,18 +57,17 @@ def test_prune_file_list(self):
6257 # this test creates a package with some vcs dirs in it
6358 # and launch sdist to make sure they get pruned
6459 # on all systems
65- self ._init_tmp_pkg ()
6660
6761 # creating VCS directories with some files in them
68- os .mkdir (join (TEMP_PKG , 'somecode' , '.svn' ))
69- self ._write (join (TEMP_PKG , 'somecode' , '.svn' , 'ok.py' ), 'xxx' )
62+ os .mkdir (join (self . tmp_dir , 'somecode' , '.svn' ))
63+ self ._write (join (self . tmp_dir , 'somecode' , '.svn' , 'ok.py' ), 'xxx' )
7064
71- os .mkdir (join (TEMP_PKG , 'somecode' , '.hg' ))
72- self ._write (join (TEMP_PKG , 'somecode' , '.hg' ,
65+ os .mkdir (join (self . tmp_dir , 'somecode' , '.hg' ))
66+ self ._write (join (self . tmp_dir , 'somecode' , '.hg' ,
7367 'ok' ), 'xxx' )
7468
75- os .mkdir (join (TEMP_PKG , 'somecode' , '.git' ))
76- self ._write (join (TEMP_PKG , 'somecode' , '.git' ,
69+ os .mkdir (join (self . tmp_dir , 'somecode' , '.git' ))
70+ self ._write (join (self . tmp_dir , 'somecode' , '.git' ,
7771 'ok' ), 'xxx' )
7872
7973 # now building a sdist
@@ -96,7 +90,7 @@ def test_prune_file_list(self):
9690 cmd .run ()
9791
9892 # now let's check what we have
99- dist_folder = join (TEMP_PKG , 'dist' )
93+ dist_folder = join (self . tmp_dir , 'dist' )
10094 files = os .listdir (dist_folder )
10195 self .assertEquals (files , ['fake-1.0.zip' ])
10296
@@ -116,8 +110,6 @@ def test_make_distribution(self):
116110 find_executable ('gzip' ) is None ):
117111 return
118112
119- self ._init_tmp_pkg ()
120-
121113 # now building a sdist
122114 dist = Distribution ()
123115 dist .script_name = 'setup.py'
@@ -137,7 +129,7 @@ def test_make_distribution(self):
137129 cmd .run ()
138130
139131 # making sure we have two files
140- dist_folder = join (TEMP_PKG , 'dist' )
132+ dist_folder = join (self . tmp_dir , 'dist' )
141133 result = os .listdir (dist_folder )
142134 result .sort ()
143135 self .assertEquals (result ,
0 commit comments