Commit 8ccd9b63 authored by Guido van Rossum's avatar Guido van Rossum

Standardize behavior: no docstrings in test functions. Also get rid

of dummy_test_TemporaryFile class; when NamedTemporaryFile and
TemporaryFile are the same, simply don't add a test suite for
TemporaryFile.
parent a5ce2e8c
...@@ -58,7 +58,7 @@ test_classes = [] ...@@ -58,7 +58,7 @@ test_classes = []
class test_exports(TC): class test_exports(TC):
def test_exports(self): def test_exports(self):
"""There are no surprising symbols in the tempfile module""" # There are no surprising symbols in the tempfile module
dict = tempfile.__dict__ dict = tempfile.__dict__
expected = { expected = {
...@@ -91,12 +91,12 @@ class test__RandomNameSequence(TC): ...@@ -91,12 +91,12 @@ class test__RandomNameSequence(TC):
self.r = tempfile._RandomNameSequence() self.r = tempfile._RandomNameSequence()
def test_get_six_char_str(self): def test_get_six_char_str(self):
"""_RandomNameSequence returns a six-character string""" # _RandomNameSequence returns a six-character string
s = self.r.next() s = self.r.next()
self.nameCheck(s, '', '', '') self.nameCheck(s, '', '', '')
def test_many(self): def test_many(self):
"""_RandomNameSequence returns no duplicate strings (stochastic)""" # _RandomNameSequence returns no duplicate strings (stochastic)
dict = {} dict = {}
r = self.r r = self.r
...@@ -107,7 +107,7 @@ class test__RandomNameSequence(TC): ...@@ -107,7 +107,7 @@ class test__RandomNameSequence(TC):
dict[s] = 1 dict[s] = 1
def test_supports_iter(self): def test_supports_iter(self):
"""_RandomNameSequence supports the iterator protocol""" # _RandomNameSequence supports the iterator protocol
i = 0 i = 0
r = self.r r = self.r
...@@ -126,7 +126,7 @@ class test__candidate_tempdir_list(TC): ...@@ -126,7 +126,7 @@ class test__candidate_tempdir_list(TC):
"""Test the internal function _candidate_tempdir_list.""" """Test the internal function _candidate_tempdir_list."""
def test_nonempty_list(self): def test_nonempty_list(self):
"""_candidate_tempdir_list returns a nonempty list of strings""" # _candidate_tempdir_list returns a nonempty list of strings
cand = tempfile._candidate_tempdir_list() cand = tempfile._candidate_tempdir_list()
...@@ -136,7 +136,7 @@ class test__candidate_tempdir_list(TC): ...@@ -136,7 +136,7 @@ class test__candidate_tempdir_list(TC):
"%s is not a string" % c) "%s is not a string" % c)
def test_wanted_dirs(self): def test_wanted_dirs(self):
"""_candidate_tempdir_list contains the expected directories""" # _candidate_tempdir_list contains the expected directories
# Make sure the interesting environment variables are all set. # Make sure the interesting environment variables are all set.
added = [] added = []
...@@ -177,12 +177,12 @@ class test__get_candidate_names(TC): ...@@ -177,12 +177,12 @@ class test__get_candidate_names(TC):
"""Test the internal function _get_candidate_names.""" """Test the internal function _get_candidate_names."""
def test_retval(self): def test_retval(self):
"""_get_candidate_names returns a _RandomNameSequence object""" # _get_candidate_names returns a _RandomNameSequence object
obj = tempfile._get_candidate_names() obj = tempfile._get_candidate_names()
self.assert_(isinstance(obj, tempfile._RandomNameSequence)) self.assert_(isinstance(obj, tempfile._RandomNameSequence))
def test_same_thing(self): def test_same_thing(self):
"""_get_candidate_names always returns the same object""" # _get_candidate_names always returns the same object
a = tempfile._get_candidate_names() a = tempfile._get_candidate_names()
b = tempfile._get_candidate_names() b = tempfile._get_candidate_names()
...@@ -225,7 +225,7 @@ class test__mkstemp_inner(TC): ...@@ -225,7 +225,7 @@ class test__mkstemp_inner(TC):
return file return file
def test_basic(self): def test_basic(self):
"""_mkstemp_inner can create files""" # _mkstemp_inner can create files
self.do_create().write("blat") self.do_create().write("blat")
self.do_create(pre="a").write("blat") self.do_create(pre="a").write("blat")
self.do_create(suf="b").write("blat") self.do_create(suf="b").write("blat")
...@@ -233,13 +233,13 @@ class test__mkstemp_inner(TC): ...@@ -233,13 +233,13 @@ class test__mkstemp_inner(TC):
self.do_create(pre="aa", suf=".txt").write("blat") self.do_create(pre="aa", suf=".txt").write("blat")
def test_basic_many(self): def test_basic_many(self):
"""_mkstemp_inner can create many files (stochastic)""" # _mkstemp_inner can create many files (stochastic)
extant = range(TEST_FILES) extant = range(TEST_FILES)
for i in extant: for i in extant:
extant[i] = self.do_create(pre="aa") extant[i] = self.do_create(pre="aa")
def test_choose_directory(self): def test_choose_directory(self):
"""_mkstemp_inner can create files in a user-selected directory""" # _mkstemp_inner can create files in a user-selected directory
dir = tempfile.mkdtemp() dir = tempfile.mkdtemp()
try: try:
self.do_create(dir=dir).write("blat") self.do_create(dir=dir).write("blat")
...@@ -247,7 +247,7 @@ class test__mkstemp_inner(TC): ...@@ -247,7 +247,7 @@ class test__mkstemp_inner(TC):
os.rmdir(dir) os.rmdir(dir)
def test_file_mode(self): def test_file_mode(self):
"""_mkstemp_inner creates files with the proper mode""" # _mkstemp_inner creates files with the proper mode
if not has_stat: if not has_stat:
return # ugh, can't use TestSkipped. return # ugh, can't use TestSkipped.
...@@ -262,7 +262,7 @@ class test__mkstemp_inner(TC): ...@@ -262,7 +262,7 @@ class test__mkstemp_inner(TC):
self.assertEqual(mode, expected) self.assertEqual(mode, expected)
def test_noinherit(self): def test_noinherit(self):
"""_mkstemp_inner file handles are not inherited by child processes""" # _mkstemp_inner file handles are not inherited by child processes
if not has_spawnl: if not has_spawnl:
return # ugh, can't use TestSkipped. return # ugh, can't use TestSkipped.
...@@ -292,7 +292,7 @@ class test__mkstemp_inner(TC): ...@@ -292,7 +292,7 @@ class test__mkstemp_inner(TC):
self.failIf(retval > 0, "child process reports failure") self.failIf(retval > 0, "child process reports failure")
def test_textmode(self): def test_textmode(self):
"""_mkstemp_inner can create files in text mode""" # _mkstemp_inner can create files in text mode
if not has_textmode: if not has_textmode:
return # ugh, can't use TestSkipped. return # ugh, can't use TestSkipped.
...@@ -306,14 +306,14 @@ class test_gettempprefix(TC): ...@@ -306,14 +306,14 @@ class test_gettempprefix(TC):
"""Test gettempprefix().""" """Test gettempprefix()."""
def test_sane_template(self): def test_sane_template(self):
"""gettempprefix returns a nonempty prefix string""" # gettempprefix returns a nonempty prefix string
p = tempfile.gettempprefix() p = tempfile.gettempprefix()
self.assert_(isinstance(p, basestring)) self.assert_(isinstance(p, basestring))
self.assert_(len(p) > 0) self.assert_(len(p) > 0)
def test_usable_template(self): def test_usable_template(self):
"""gettempprefix returns a usable prefix string""" # gettempprefix returns a usable prefix string
# Create a temp directory, avoiding use of the prefix. # Create a temp directory, avoiding use of the prefix.
# Then attempt to create a file whose name is # Then attempt to create a file whose name is
...@@ -338,7 +338,7 @@ class test_gettempdir(TC): ...@@ -338,7 +338,7 @@ class test_gettempdir(TC):
"""Test gettempdir().""" """Test gettempdir()."""
def test_directory_exists(self): def test_directory_exists(self):
"""gettempdir returns a directory which exists""" # gettempdir returns a directory which exists
dir = tempfile.gettempdir() dir = tempfile.gettempdir()
self.assert_(os.path.isabs(dir) or dir == os.curdir, self.assert_(os.path.isabs(dir) or dir == os.curdir,
...@@ -347,7 +347,7 @@ class test_gettempdir(TC): ...@@ -347,7 +347,7 @@ class test_gettempdir(TC):
"%s is not a directory" % dir) "%s is not a directory" % dir)
def test_directory_writable(self): def test_directory_writable(self):
"""gettempdir returns a directory writable by the user""" # gettempdir returns a directory writable by the user
# 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
...@@ -360,7 +360,7 @@ class test_gettempdir(TC): ...@@ -360,7 +360,7 @@ class test_gettempdir(TC):
self.failOnException("create file in %s" % tempfile.gettempdir()) 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
a = tempfile.gettempdir() a = tempfile.gettempdir()
b = tempfile.gettempdir() b = tempfile.gettempdir()
...@@ -371,6 +371,7 @@ test_classes.append(test_gettempdir) ...@@ -371,6 +371,7 @@ test_classes.append(test_gettempdir)
class test_mkstemp(TC): class test_mkstemp(TC):
"""Test mkstemp().""" """Test mkstemp()."""
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()
...@@ -386,7 +387,7 @@ class test_mkstemp(TC): ...@@ -386,7 +387,7 @@ class test_mkstemp(TC):
os.unlink(name) os.unlink(name)
def test_basic(self): def test_basic(self):
"""mkstemp can create files""" # mkstemp can create files
self.do_create() self.do_create()
self.do_create(pre="a") self.do_create(pre="a")
self.do_create(suf="b") self.do_create(suf="b")
...@@ -394,7 +395,7 @@ class test_mkstemp(TC): ...@@ -394,7 +395,7 @@ class test_mkstemp(TC):
self.do_create(pre="aa", suf=".txt") self.do_create(pre="aa", suf=".txt")
def test_choose_directory(self): def test_choose_directory(self):
"""mkstemp can create directories in a user-selected directory""" # mkstemp can create directories in a user-selected directory
dir = tempfile.mkdtemp() dir = tempfile.mkdtemp()
try: try:
self.do_create(dir=dir) self.do_create(dir=dir)
...@@ -423,7 +424,7 @@ class test_mkdtemp(TC): ...@@ -423,7 +424,7 @@ class test_mkdtemp(TC):
raise raise
def test_basic(self): def test_basic(self):
"""mkdtemp can create directories""" # mkdtemp can create directories
os.rmdir(self.do_create()) os.rmdir(self.do_create())
os.rmdir(self.do_create(pre="a")) os.rmdir(self.do_create(pre="a"))
os.rmdir(self.do_create(suf="b")) os.rmdir(self.do_create(suf="b"))
...@@ -431,7 +432,7 @@ class test_mkdtemp(TC): ...@@ -431,7 +432,7 @@ class test_mkdtemp(TC):
os.rmdir(self.do_create(pre="aa", suf=".txt")) os.rmdir(self.do_create(pre="aa", suf=".txt"))
def test_basic_many(self): def test_basic_many(self):
"""mkdtemp can create many directories (stochastic)""" # mkdtemp can create many directories (stochastic)
extant = range(TEST_FILES) extant = range(TEST_FILES)
try: try:
for i in extant: for i in extant:
...@@ -442,7 +443,7 @@ class test_mkdtemp(TC): ...@@ -442,7 +443,7 @@ class test_mkdtemp(TC):
os.rmdir(i) os.rmdir(i)
def test_choose_directory(self): def test_choose_directory(self):
"""mkdtemp can create directories in a user-selected directory""" # mkdtemp can create directories in a user-selected directory
dir = tempfile.mkdtemp() dir = tempfile.mkdtemp()
try: try:
os.rmdir(self.do_create(dir=dir)) os.rmdir(self.do_create(dir=dir))
...@@ -450,7 +451,7 @@ class test_mkdtemp(TC): ...@@ -450,7 +451,7 @@ class test_mkdtemp(TC):
os.rmdir(dir) os.rmdir(dir)
def test_mode(self): def test_mode(self):
"""mkdtemp creates directories with the proper mode""" # mkdtemp creates directories with the proper mode
if not has_stat: if not has_stat:
return # ugh, can't use TestSkipped. return # ugh, can't use TestSkipped.
...@@ -511,7 +512,7 @@ class test_mktemp(TC): ...@@ -511,7 +512,7 @@ class test_mktemp(TC):
return file return file
def test_basic(self): def test_basic(self):
"""mktemp can choose usable file names""" # mktemp can choose usable file names
self.do_create() self.do_create()
self.do_create(pre="a") self.do_create(pre="a")
self.do_create(suf="b") self.do_create(suf="b")
...@@ -519,13 +520,13 @@ class test_mktemp(TC): ...@@ -519,13 +520,13 @@ class test_mktemp(TC):
self.do_create(pre="aa", suf=".txt") self.do_create(pre="aa", suf=".txt")
def test_many(self): def test_many(self):
"""mktemp can choose many usable file names (stochastic)""" # mktemp can choose many usable file names (stochastic)
extant = range(TEST_FILES) extant = range(TEST_FILES)
for i in extant: for i in extant:
extant[i] = self.do_create(pre="aa") extant[i] = self.do_create(pre="aa")
def test_warning(self): def test_warning(self):
"""mktemp issues a warning when used""" # mktemp issues a warning when used
warnings.filterwarnings("error", warnings.filterwarnings("error",
category=RuntimeWarning, category=RuntimeWarning,
message="mktemp") message="mktemp")
...@@ -554,7 +555,7 @@ class test_NamedTemporaryFile(TC): ...@@ -554,7 +555,7 @@ class test_NamedTemporaryFile(TC):
def test_basic(self): def test_basic(self):
"""NamedTemporaryFile can create files""" # NamedTemporaryFile can create files
self.do_create() self.do_create()
self.do_create(pre="a") self.do_create(pre="a")
self.do_create(suf="b") self.do_create(suf="b")
...@@ -562,13 +563,13 @@ class test_NamedTemporaryFile(TC): ...@@ -562,13 +563,13 @@ class test_NamedTemporaryFile(TC):
self.do_create(pre="aa", suf=".txt") self.do_create(pre="aa", suf=".txt")
def test_creates_named(self): def test_creates_named(self):
"""NamedTemporaryFile creates files with names""" # NamedTemporaryFile creates files with names
f = tempfile.NamedTemporaryFile() f = tempfile.NamedTemporaryFile()
self.failUnless(os.path.exists(f.name), self.failUnless(os.path.exists(f.name),
"NamedTemporaryFile %s does not exist" % f.name) "NamedTemporaryFile %s does not exist" % f.name)
def test_del_on_close(self): def test_del_on_close(self):
"""A NamedTemporaryFile is deleted when closed""" # A NamedTemporaryFile is deleted when closed
dir = tempfile.mkdtemp() dir = tempfile.mkdtemp()
try: try:
f = tempfile.NamedTemporaryFile(dir=dir) f = tempfile.NamedTemporaryFile(dir=dir)
...@@ -580,7 +581,7 @@ class test_NamedTemporaryFile(TC): ...@@ -580,7 +581,7 @@ class test_NamedTemporaryFile(TC):
os.rmdir(dir) os.rmdir(dir)
def test_multiple_close(self): def test_multiple_close(self):
"""A NamedTemporaryFile can be closed many times without error""" # A NamedTemporaryFile can be closed many times without error
f = tempfile.NamedTemporaryFile() f = tempfile.NamedTemporaryFile()
f.write('abc\n') f.write('abc\n')
...@@ -600,7 +601,7 @@ class test_TemporaryFile(TC): ...@@ -600,7 +601,7 @@ class test_TemporaryFile(TC):
"""Test TemporaryFile().""" """Test TemporaryFile()."""
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: try:
tempfile.TemporaryFile() tempfile.TemporaryFile()
...@@ -608,7 +609,7 @@ class test_TemporaryFile(TC): ...@@ -608,7 +609,7 @@ class test_TemporaryFile(TC):
self.failOnException("TemporaryFile") 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)
dir = tempfile.mkdtemp() dir = tempfile.mkdtemp()
f = tempfile.TemporaryFile(dir=dir) f = tempfile.TemporaryFile(dir=dir)
f.write('blat') f.write('blat')
...@@ -625,7 +626,7 @@ class test_TemporaryFile(TC): ...@@ -625,7 +626,7 @@ class test_TemporaryFile(TC):
self.failOnException("rmdir", ei) self.failOnException("rmdir", ei)
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('abc\n') f.write('abc\n')
f.close() f.close()
...@@ -637,14 +638,8 @@ class test_TemporaryFile(TC): ...@@ -637,14 +638,8 @@ class test_TemporaryFile(TC):
# How to test the mode and bufsize parameters? # How to test the mode and bufsize parameters?
class dummy_test_TemporaryFile(TC):
def test_dummy(self):
"""TemporaryFile and NamedTemporaryFile are the same (on this system)"""
pass
if tempfile.NamedTemporaryFile is tempfile.TemporaryFile: if tempfile.NamedTemporaryFile is not tempfile.TemporaryFile:
test_classes.append(dummy_test_TemporaryFile)
else:
test_classes.append(test_TemporaryFile) test_classes.append(test_TemporaryFile)
def test_main(): def test_main():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment