Commit eab2a50d authored by Antoine Pitrou's avatar Antoine Pitrou

PEP8-ize test names

parent 8cd8d5e8
...@@ -31,7 +31,7 @@ else: ...@@ -31,7 +31,7 @@ else:
# threads is not done here. # threads is not done here.
# Common functionality. # Common functionality.
class TC(unittest.TestCase): class BaseTestCase(unittest.TestCase):
str_check = re.compile(r"[a-zA-Z0-9_-]{6}$") str_check = re.compile(r"[a-zA-Z0-9_-]{6}$")
...@@ -63,9 +63,8 @@ class TC(unittest.TestCase): ...@@ -63,9 +63,8 @@ class TC(unittest.TestCase):
"random string '%s' does not match /^[a-zA-Z0-9_-]{6}$/" "random string '%s' does not match /^[a-zA-Z0-9_-]{6}$/"
% nbase) % nbase)
test_classes = []
class test_exports(TC): class TestExports(BaseTestCase):
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__
...@@ -92,10 +91,8 @@ class test_exports(TC): ...@@ -92,10 +91,8 @@ class test_exports(TC):
self.assertTrue(len(unexp) == 0, self.assertTrue(len(unexp) == 0,
"unexpected keys: %s" % unexp) "unexpected keys: %s" % unexp)
test_classes.append(test_exports)
class TestRandomNameSequence(BaseTestCase):
class test__RandomNameSequence(TC):
"""Test the internal iterator object _RandomNameSequence.""" """Test the internal iterator object _RandomNameSequence."""
def setUp(self): def setUp(self):
...@@ -159,10 +156,8 @@ class test__RandomNameSequence(TC): ...@@ -159,10 +156,8 @@ class test__RandomNameSequence(TC):
self.assertNotEqual(child_value, parent_value) self.assertNotEqual(child_value, parent_value)
test_classes.append(test__RandomNameSequence)
class test__candidate_tempdir_list(TC): class TestCandidateTempdirList(BaseTestCase):
"""Test the internal function _candidate_tempdir_list.""" """Test the internal function _candidate_tempdir_list."""
def test_nonempty_list(self): def test_nonempty_list(self):
...@@ -201,13 +196,11 @@ class test__candidate_tempdir_list(TC): ...@@ -201,13 +196,11 @@ class test__candidate_tempdir_list(TC):
# Not practical to try to verify the presence of OS-specific # Not practical to try to verify the presence of OS-specific
# paths in this list. # paths in this list.
test_classes.append(test__candidate_tempdir_list)
# We test _get_default_tempdir by testing gettempdir. # We test _get_default_tempdir by testing gettempdir.
class test__get_candidate_names(TC): class TestGetCandidateNames(BaseTestCase):
"""Test the internal function _get_candidate_names.""" """Test the internal function _get_candidate_names."""
def test_retval(self): def test_retval(self):
...@@ -222,10 +215,8 @@ class test__get_candidate_names(TC): ...@@ -222,10 +215,8 @@ class test__get_candidate_names(TC):
self.assertTrue(a is b) self.assertTrue(a is b)
test_classes.append(test__get_candidate_names)
class TestMkstempInner(BaseTestCase):
class test__mkstemp_inner(TC):
"""Test the internal function _mkstemp_inner.""" """Test the internal function _mkstemp_inner."""
class mkstemped: class mkstemped:
...@@ -342,10 +333,8 @@ class test__mkstemp_inner(TC): ...@@ -342,10 +333,8 @@ class test__mkstemp_inner(TC):
os.lseek(f.fd, 0, os.SEEK_SET) os.lseek(f.fd, 0, os.SEEK_SET)
self.assertEqual(os.read(f.fd, 20), b"blat") self.assertEqual(os.read(f.fd, 20), b"blat")
test_classes.append(test__mkstemp_inner)
class test_gettempprefix(TC): class TestGetTempPrefix(BaseTestCase):
"""Test gettempprefix().""" """Test gettempprefix()."""
def test_sane_template(self): def test_sane_template(self):
...@@ -371,10 +360,8 @@ class test_gettempprefix(TC): ...@@ -371,10 +360,8 @@ class test_gettempprefix(TC):
finally: finally:
os.rmdir(d) os.rmdir(d)
test_classes.append(test_gettempprefix)
class TestGetTempDir(BaseTestCase):
class test_gettempdir(TC):
"""Test gettempdir().""" """Test gettempdir()."""
def test_directory_exists(self): def test_directory_exists(self):
...@@ -403,10 +390,8 @@ class test_gettempdir(TC): ...@@ -403,10 +390,8 @@ class test_gettempdir(TC):
self.assertTrue(a is b) self.assertTrue(a is b)
test_classes.append(test_gettempdir)
class test_mkstemp(TC): class TestMkstemp(BaseTestCase):
"""Test mkstemp().""" """Test mkstemp()."""
def do_create(self, dir=None, pre="", suf=""): def do_create(self, dir=None, pre="", suf=""):
...@@ -441,10 +426,8 @@ class test_mkstemp(TC): ...@@ -441,10 +426,8 @@ class test_mkstemp(TC):
finally: finally:
os.rmdir(dir) os.rmdir(dir)
test_classes.append(test_mkstemp)
class TestMkdtemp(BaseTestCase):
class test_mkdtemp(TC):
"""Test mkdtemp().""" """Test mkdtemp()."""
def do_create(self, dir=None, pre="", suf=""): def do_create(self, dir=None, pre="", suf=""):
...@@ -505,10 +488,8 @@ class test_mkdtemp(TC): ...@@ -505,10 +488,8 @@ class test_mkdtemp(TC):
finally: finally:
os.rmdir(dir) os.rmdir(dir)
test_classes.append(test_mkdtemp)
class test_mktemp(TC): class TestMktemp(BaseTestCase):
"""Test mktemp().""" """Test mktemp()."""
# For safety, all use of mktemp must occur in a private directory. # For safety, all use of mktemp must occur in a private directory.
...@@ -564,13 +545,11 @@ class test_mktemp(TC): ...@@ -564,13 +545,11 @@ class test_mktemp(TC):
## self.assertRaises(RuntimeWarning, ## self.assertRaises(RuntimeWarning,
## tempfile.mktemp, dir=self.dir) ## tempfile.mktemp, dir=self.dir)
test_classes.append(test_mktemp)
# We test _TemporaryFileWrapper by testing NamedTemporaryFile. # We test _TemporaryFileWrapper by testing NamedTemporaryFile.
class test_NamedTemporaryFile(TC): class TestNamedTemporaryFile(BaseTestCase):
"""Test NamedTemporaryFile().""" """Test NamedTemporaryFile()."""
def do_create(self, dir=None, pre="", suf="", delete=True): def do_create(self, dir=None, pre="", suf="", delete=True):
...@@ -645,9 +624,8 @@ class test_NamedTemporaryFile(TC): ...@@ -645,9 +624,8 @@ class test_NamedTemporaryFile(TC):
# How to test the mode and bufsize parameters? # How to test the mode and bufsize parameters?
test_classes.append(test_NamedTemporaryFile)
class test_SpooledTemporaryFile(TC): class TestSpooledTemporaryFile(BaseTestCase):
"""Test SpooledTemporaryFile().""" """Test SpooledTemporaryFile()."""
def do_create(self, max_size=0, dir=None, pre="", suf=""): def do_create(self, max_size=0, dir=None, pre="", suf=""):
...@@ -859,58 +837,54 @@ class test_SpooledTemporaryFile(TC): ...@@ -859,58 +837,54 @@ class test_SpooledTemporaryFile(TC):
if has_stat: if has_stat:
self.assertEqual(os.fstat(f.fileno()).st_size, 20) self.assertEqual(os.fstat(f.fileno()).st_size, 20)
test_classes.append(test_SpooledTemporaryFile)
if tempfile.NamedTemporaryFile is not tempfile.TemporaryFile:
class test_TemporaryFile(TC): class TestTemporaryFile(BaseTestCase):
"""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.
tempfile.TemporaryFile() tempfile.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(b'blat') f.write(b'blat')
# Sneaky: because this file has no name, it should not prevent # Sneaky: because this file has no name, it should not prevent
# us from removing the directory it was created in. # us from removing the directory it was created in.
try: try:
os.rmdir(dir) os.rmdir(dir)
except: except:
# cleanup # cleanup
f.close()
os.rmdir(dir)
raise
def test_multiple_close(self):
# A TemporaryFile can be closed many times without error
f = tempfile.TemporaryFile()
f.write(b'abc\n')
f.close()
f.close()
f.close() f.close()
os.rmdir(dir)
raise
def test_multiple_close(self):
# A TemporaryFile can be closed many times without error
f = tempfile.TemporaryFile()
f.write(b'abc\n')
f.close()
f.close()
f.close()
# How to test the mode and bufsize parameters?
def test_mode_and_encoding(self):
def roundtrip(input, *args, **kwargs):
with tempfile.TemporaryFile(*args, **kwargs) as fileobj:
fileobj.write(input)
fileobj.seek(0)
self.assertEqual(input, fileobj.read())
roundtrip(b"1234", "w+b") # How to test the mode and bufsize parameters?
roundtrip("abdc\n", "w+") def test_mode_and_encoding(self):
roundtrip("\u039B", "w+", encoding="utf-16")
roundtrip("foo\r\n", "w+", newline="")
def roundtrip(input, *args, **kwargs):
with tempfile.TemporaryFile(*args, **kwargs) as fileobj:
fileobj.write(input)
fileobj.seek(0)
self.assertEqual(input, fileobj.read())
if tempfile.NamedTemporaryFile is not tempfile.TemporaryFile: roundtrip(b"1234", "w+b")
test_classes.append(test_TemporaryFile) roundtrip("abdc\n", "w+")
roundtrip("\u039B", "w+", encoding="utf-16")
roundtrip("foo\r\n", "w+", newline="")
# Helper for test_del_on_shutdown # Helper for test_del_on_shutdown
...@@ -929,7 +903,7 @@ class NulledModules: ...@@ -929,7 +903,7 @@ class NulledModules:
d.clear() d.clear()
d.update(c) d.update(c)
class test_TemporaryDirectory(TC): class TestTemporaryDirectory(BaseTestCase):
"""Test TemporaryDirectory().""" """Test TemporaryDirectory()."""
def do_create(self, dir=None, pre="", suf="", recurse=1): def do_create(self, dir=None, pre="", suf="", recurse=1):
...@@ -1071,10 +1045,8 @@ class test_TemporaryDirectory(TC): ...@@ -1071,10 +1045,8 @@ class test_TemporaryDirectory(TC):
self.assertFalse(os.path.exists(name)) self.assertFalse(os.path.exists(name))
test_classes.append(test_TemporaryDirectory)
def test_main(): def test_main():
support.run_unittest(*test_classes) support.run_unittest(__name__)
if __name__ == "__main__": if __name__ == "__main__":
test_main() 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