mirror of https://github.com/python/cpython
Remove useless failOnException() method
This commit is contained in:
parent
6aacc14e29
commit
8cd8d5e8f2
|
@ -45,11 +45,6 @@ class TC(unittest.TestCase):
|
||||||
self._warnings_manager.__exit__(None, None, None)
|
self._warnings_manager.__exit__(None, None, None)
|
||||||
|
|
||||||
|
|
||||||
def failOnException(self, what, ei=None):
|
|
||||||
if ei is None:
|
|
||||||
ei = sys.exc_info()
|
|
||||||
self.fail("%s raised %s: %s" % (what, ei[0], ei[1]))
|
|
||||||
|
|
||||||
def nameCheck(self, name, dir, pre, suf):
|
def nameCheck(self, name, dir, pre, suf):
|
||||||
(ndir, nbase) = os.path.split(name)
|
(ndir, nbase) = os.path.split(name)
|
||||||
npre = nbase[:len(pre)]
|
npre = nbase[:len(pre)]
|
||||||
|
@ -128,13 +123,10 @@ class test__RandomNameSequence(TC):
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
r = self.r
|
r = self.r
|
||||||
try:
|
|
||||||
for s in r:
|
for s in r:
|
||||||
i += 1
|
i += 1
|
||||||
if i == 20:
|
if i == 20:
|
||||||
break
|
break
|
||||||
except:
|
|
||||||
self.failOnException("iteration")
|
|
||||||
|
|
||||||
@unittest.skipUnless(hasattr(os, 'fork'),
|
@unittest.skipUnless(hasattr(os, 'fork'),
|
||||||
"os.fork is required for this test")
|
"os.fork is required for this test")
|
||||||
|
@ -258,10 +250,7 @@ class test__mkstemp_inner(TC):
|
||||||
def do_create(self, dir=None, pre="", suf="", bin=1):
|
def do_create(self, dir=None, pre="", suf="", bin=1):
|
||||||
if dir is None:
|
if dir is None:
|
||||||
dir = tempfile.gettempdir()
|
dir = tempfile.gettempdir()
|
||||||
try:
|
|
||||||
file = self.mkstemped(dir, pre, suf, bin)
|
file = self.mkstemped(dir, pre, suf, bin)
|
||||||
except:
|
|
||||||
self.failOnException("_mkstemp_inner")
|
|
||||||
|
|
||||||
self.nameCheck(file.name, dir, pre, suf)
|
self.nameCheck(file.name, dir, pre, suf)
|
||||||
return file
|
return file
|
||||||
|
@ -376,10 +365,7 @@ class test_gettempprefix(TC):
|
||||||
d = tempfile.mkdtemp(prefix="")
|
d = tempfile.mkdtemp(prefix="")
|
||||||
try:
|
try:
|
||||||
p = os.path.join(d, p)
|
p = os.path.join(d, p)
|
||||||
try:
|
|
||||||
fd = os.open(p, os.O_RDWR | os.O_CREAT)
|
fd = os.open(p, os.O_RDWR | os.O_CREAT)
|
||||||
except:
|
|
||||||
self.failOnException("os.open")
|
|
||||||
os.close(fd)
|
os.close(fd)
|
||||||
os.unlink(p)
|
os.unlink(p)
|
||||||
finally:
|
finally:
|
||||||
|
@ -406,12 +392,9 @@ class test_gettempdir(TC):
|
||||||
# sneaky: just instantiate a NamedTemporaryFile, which
|
# sneaky: just instantiate a NamedTemporaryFile, which
|
||||||
# defaults to writing into the directory returned by
|
# defaults to writing into the directory returned by
|
||||||
# gettempdir.
|
# gettempdir.
|
||||||
try:
|
|
||||||
file = tempfile.NamedTemporaryFile()
|
file = tempfile.NamedTemporaryFile()
|
||||||
file.write(b"blat")
|
file.write(b"blat")
|
||||||
file.close()
|
file.close()
|
||||||
except:
|
|
||||||
self.failOnException("create file in %s" % tempfile.gettempdir())
|
|
||||||
|
|
||||||
def test_same_thing(self):
|
def test_same_thing(self):
|
||||||
# gettempdir always returns the same object
|
# gettempdir always returns the same object
|
||||||
|
@ -429,14 +412,11 @@ class test_mkstemp(TC):
|
||||||
def do_create(self, dir=None, pre="", suf=""):
|
def do_create(self, dir=None, pre="", suf=""):
|
||||||
if dir is None:
|
if dir is None:
|
||||||
dir = tempfile.gettempdir()
|
dir = tempfile.gettempdir()
|
||||||
try:
|
|
||||||
(fd, name) = tempfile.mkstemp(dir=dir, prefix=pre, suffix=suf)
|
(fd, name) = tempfile.mkstemp(dir=dir, prefix=pre, suffix=suf)
|
||||||
(ndir, nbase) = os.path.split(name)
|
(ndir, nbase) = os.path.split(name)
|
||||||
adir = os.path.abspath(dir)
|
adir = os.path.abspath(dir)
|
||||||
self.assertEqual(adir, ndir,
|
self.assertEqual(adir, ndir,
|
||||||
"Directory '%s' incorrectly returned as '%s'" % (adir, ndir))
|
"Directory '%s' incorrectly returned as '%s'" % (adir, ndir))
|
||||||
except:
|
|
||||||
self.failOnException("mkstemp")
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.nameCheck(name, dir, pre, suf)
|
self.nameCheck(name, dir, pre, suf)
|
||||||
|
@ -470,10 +450,7 @@ class test_mkdtemp(TC):
|
||||||
def do_create(self, dir=None, pre="", suf=""):
|
def do_create(self, dir=None, pre="", suf=""):
|
||||||
if dir is None:
|
if dir is None:
|
||||||
dir = tempfile.gettempdir()
|
dir = tempfile.gettempdir()
|
||||||
try:
|
|
||||||
name = tempfile.mkdtemp(dir=dir, prefix=pre, suffix=suf)
|
name = tempfile.mkdtemp(dir=dir, prefix=pre, suffix=suf)
|
||||||
except:
|
|
||||||
self.failOnException("mkdtemp")
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.nameCheck(name, dir, pre, suf)
|
self.nameCheck(name, dir, pre, suf)
|
||||||
|
@ -560,10 +537,7 @@ class test_mktemp(TC):
|
||||||
self._unlink(self.name)
|
self._unlink(self.name)
|
||||||
|
|
||||||
def do_create(self, pre="", suf=""):
|
def do_create(self, pre="", suf=""):
|
||||||
try:
|
|
||||||
file = self.mktemped(self.dir, pre, suf)
|
file = self.mktemped(self.dir, pre, suf)
|
||||||
except:
|
|
||||||
self.failOnException("mktemp")
|
|
||||||
|
|
||||||
self.nameCheck(file.name, self.dir, pre, suf)
|
self.nameCheck(file.name, self.dir, pre, suf)
|
||||||
return file
|
return file
|
||||||
|
@ -602,11 +576,8 @@ class test_NamedTemporaryFile(TC):
|
||||||
def do_create(self, dir=None, pre="", suf="", delete=True):
|
def do_create(self, dir=None, pre="", suf="", delete=True):
|
||||||
if dir is None:
|
if dir is None:
|
||||||
dir = tempfile.gettempdir()
|
dir = tempfile.gettempdir()
|
||||||
try:
|
|
||||||
file = tempfile.NamedTemporaryFile(dir=dir, prefix=pre, suffix=suf,
|
file = tempfile.NamedTemporaryFile(dir=dir, prefix=pre, suffix=suf,
|
||||||
delete=delete)
|
delete=delete)
|
||||||
except:
|
|
||||||
self.failOnException("NamedTemporaryFile")
|
|
||||||
|
|
||||||
self.nameCheck(file.name, dir, pre, suf)
|
self.nameCheck(file.name, dir, pre, suf)
|
||||||
return file
|
return file
|
||||||
|
@ -659,11 +630,8 @@ class test_NamedTemporaryFile(TC):
|
||||||
f = tempfile.NamedTemporaryFile()
|
f = tempfile.NamedTemporaryFile()
|
||||||
f.write(b'abc\n')
|
f.write(b'abc\n')
|
||||||
f.close()
|
f.close()
|
||||||
try:
|
|
||||||
f.close()
|
f.close()
|
||||||
f.close()
|
f.close()
|
||||||
except:
|
|
||||||
self.failOnException("close")
|
|
||||||
|
|
||||||
def test_context_manager(self):
|
def test_context_manager(self):
|
||||||
# A NamedTemporaryFile can be used as a context manager
|
# A NamedTemporaryFile can be used as a context manager
|
||||||
|
@ -685,10 +653,7 @@ class test_SpooledTemporaryFile(TC):
|
||||||
def do_create(self, max_size=0, dir=None, pre="", suf=""):
|
def do_create(self, max_size=0, dir=None, pre="", suf=""):
|
||||||
if dir is None:
|
if dir is None:
|
||||||
dir = tempfile.gettempdir()
|
dir = tempfile.gettempdir()
|
||||||
try:
|
|
||||||
file = tempfile.SpooledTemporaryFile(max_size=max_size, dir=dir, prefix=pre, suffix=suf)
|
file = tempfile.SpooledTemporaryFile(max_size=max_size, dir=dir, prefix=pre, suffix=suf)
|
||||||
except:
|
|
||||||
self.failOnException("SpooledTemporaryFile")
|
|
||||||
|
|
||||||
return file
|
return file
|
||||||
|
|
||||||
|
@ -776,11 +741,8 @@ class test_SpooledTemporaryFile(TC):
|
||||||
f.write(b'abc\n')
|
f.write(b'abc\n')
|
||||||
self.assertFalse(f._rolled)
|
self.assertFalse(f._rolled)
|
||||||
f.close()
|
f.close()
|
||||||
try:
|
|
||||||
f.close()
|
f.close()
|
||||||
f.close()
|
f.close()
|
||||||
except:
|
|
||||||
self.failOnException("close")
|
|
||||||
|
|
||||||
def test_multiple_close_after_rollover(self):
|
def test_multiple_close_after_rollover(self):
|
||||||
# A SpooledTemporaryFile can be closed many times without error
|
# A SpooledTemporaryFile can be closed many times without error
|
||||||
|
@ -788,11 +750,8 @@ class test_SpooledTemporaryFile(TC):
|
||||||
f.write(b'abc\n')
|
f.write(b'abc\n')
|
||||||
self.assertTrue(f._rolled)
|
self.assertTrue(f._rolled)
|
||||||
f.close()
|
f.close()
|
||||||
try:
|
|
||||||
f.close()
|
f.close()
|
||||||
f.close()
|
f.close()
|
||||||
except:
|
|
||||||
self.failOnException("close")
|
|
||||||
|
|
||||||
def test_bound_methods(self):
|
def test_bound_methods(self):
|
||||||
# It should be OK to steal a bound method from a SpooledTemporaryFile
|
# It should be OK to steal a bound method from a SpooledTemporaryFile
|
||||||
|
@ -909,10 +868,7 @@ class test_TemporaryFile(TC):
|
||||||
def test_basic(self):
|
def test_basic(self):
|
||||||
# TemporaryFile can create files
|
# TemporaryFile can create files
|
||||||
# No point in testing the name params - the file has no name.
|
# No point in testing the name params - the file has no name.
|
||||||
try:
|
|
||||||
tempfile.TemporaryFile()
|
tempfile.TemporaryFile()
|
||||||
except:
|
|
||||||
self.failOnException("TemporaryFile")
|
|
||||||
|
|
||||||
def test_has_no_name(self):
|
def test_has_no_name(self):
|
||||||
# TemporaryFile creates files with no names (on this system)
|
# TemporaryFile creates files with no names (on this system)
|
||||||
|
@ -925,22 +881,18 @@ class test_TemporaryFile(TC):
|
||||||
try:
|
try:
|
||||||
os.rmdir(dir)
|
os.rmdir(dir)
|
||||||
except:
|
except:
|
||||||
ei = sys.exc_info()
|
|
||||||
# cleanup
|
# cleanup
|
||||||
f.close()
|
f.close()
|
||||||
os.rmdir(dir)
|
os.rmdir(dir)
|
||||||
self.failOnException("rmdir", ei)
|
raise
|
||||||
|
|
||||||
def test_multiple_close(self):
|
def test_multiple_close(self):
|
||||||
# A TemporaryFile can be closed many times without error
|
# A TemporaryFile can be closed many times without error
|
||||||
f = tempfile.TemporaryFile()
|
f = tempfile.TemporaryFile()
|
||||||
f.write(b'abc\n')
|
f.write(b'abc\n')
|
||||||
f.close()
|
f.close()
|
||||||
try:
|
|
||||||
f.close()
|
f.close()
|
||||||
f.close()
|
f.close()
|
||||||
except:
|
|
||||||
self.failOnException("close")
|
|
||||||
|
|
||||||
# How to test the mode and bufsize parameters?
|
# How to test the mode and bufsize parameters?
|
||||||
def test_mode_and_encoding(self):
|
def test_mode_and_encoding(self):
|
||||||
|
@ -983,10 +935,7 @@ class test_TemporaryDirectory(TC):
|
||||||
def do_create(self, dir=None, pre="", suf="", recurse=1):
|
def do_create(self, dir=None, pre="", suf="", recurse=1):
|
||||||
if dir is None:
|
if dir is None:
|
||||||
dir = tempfile.gettempdir()
|
dir = tempfile.gettempdir()
|
||||||
try:
|
|
||||||
tmp = tempfile.TemporaryDirectory(dir=dir, prefix=pre, suffix=suf)
|
tmp = tempfile.TemporaryDirectory(dir=dir, prefix=pre, suffix=suf)
|
||||||
except:
|
|
||||||
self.failOnException("TemporaryDirectory")
|
|
||||||
self.nameCheck(tmp.name, dir, pre, suf)
|
self.nameCheck(tmp.name, dir, pre, suf)
|
||||||
# Create a subdirectory and some files
|
# Create a subdirectory and some files
|
||||||
if recurse:
|
if recurse:
|
||||||
|
@ -1110,11 +1059,8 @@ class test_TemporaryDirectory(TC):
|
||||||
# Can be cleaned-up many times without error
|
# Can be cleaned-up many times without error
|
||||||
d = self.do_create()
|
d = self.do_create()
|
||||||
d.cleanup()
|
d.cleanup()
|
||||||
try:
|
|
||||||
d.cleanup()
|
d.cleanup()
|
||||||
d.cleanup()
|
d.cleanup()
|
||||||
except:
|
|
||||||
self.failOnException("cleanup")
|
|
||||||
|
|
||||||
def test_context_manager(self):
|
def test_context_manager(self):
|
||||||
# Can be used as a context manager
|
# Can be used as a context manager
|
||||||
|
|
Loading…
Reference in New Issue