summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohannes Gijsbers <jlg@dds.nl>2005-01-08 13:28:54 (GMT)
committerJohannes Gijsbers <jlg@dds.nl>2005-01-08 13:28:54 (GMT)
commita3beee185cb374dfb2c68200e8b0332e28e73204 (patch)
tree4d41e335ad7d023883f169197444c311fc738ea5
parent836f5433f7ee79f208186ca0d10594b22cf7e05b (diff)
downloadcpython-a3beee185cb374dfb2c68200e8b0332e28e73204.zip
cpython-a3beee185cb374dfb2c68200e8b0332e28e73204.tar.gz
cpython-a3beee185cb374dfb2c68200e8b0332e28e73204.tar.bz2
Clean up tests by reusing functions from other modules:
* replace deltree with shutil.rmtree() * replace mkdirs with os.makedirs() * fold touchfile into GlobTests.mktemp()
-rw-r--r--Lib/test/test_glob.py39
1 files changed, 8 insertions, 31 deletions
diff --git a/Lib/test/test_glob.py b/Lib/test/test_glob.py
index f23dcf1..8a6ef7f 100644
--- a/Lib/test/test_glob.py
+++ b/Lib/test/test_glob.py
@@ -2,35 +2,7 @@ import unittest
from test.test_support import run_unittest, TESTFN
import glob
import os
-
-def mkdirs(fname):
- if os.path.exists(fname) or fname == '':
- return
- base, file = os.path.split(fname)
- mkdirs(base)
- os.mkdir(fname)
-
-def touchfile(fname):
- base, file = os.path.split(fname)
- mkdirs(base)
- f = open(fname, 'w')
- f.close()
-
-def deltree(fname):
- for f in os.listdir(fname):
- fullname = os.path.join(fname, f)
- if os.path.isdir(fullname):
- deltree(fullname)
- else:
- try:
- os.unlink(fullname)
- except:
- pass
- try:
- os.rmdir(fname)
- except:
- pass
-
+import shutil
class GlobTests(unittest.TestCase):
@@ -38,7 +10,12 @@ class GlobTests(unittest.TestCase):
return os.path.normpath(os.path.join(self.tempdir, *parts))
def mktemp(self, *parts):
- touchfile(self.norm(*parts))
+ filename = self.norm(*parts)
+ base, file = os.path.split(filename)
+ if not os.path.exists(base):
+ os.makedirs(base)
+ f = open(filename, 'w')
+ f.close()
def setUp(self):
self.tempdir = TESTFN+"_dir"
@@ -53,7 +30,7 @@ class GlobTests(unittest.TestCase):
os.symlink(self.norm('broken'), self.norm('sym2'))
def tearDown(self):
- deltree(self.tempdir)
+ shutil.rmtree(self.tempdir)
def glob(self, *parts):
if len(parts) == 1: