From: Johannes Gijsbers Date: Sat, 8 Jan 2005 13:28:54 +0000 (+0000) Subject: Clean up tests by reusing functions from other modules: X-Git-Tag: v2.5a0~2157 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a3beee185cb374dfb2c68200e8b0332e28e73204;p=thirdparty%2FPython%2Fcpython.git Clean up tests by reusing functions from other modules: * replace deltree with shutil.rmtree() * replace mkdirs with os.makedirs() * fold touchfile into GlobTests.mktemp() --- diff --git a/Lib/test/test_glob.py b/Lib/test/test_glob.py index f23dcf189c48..8a6ef7fada37 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: