mirror of https://github.com/python/cpython
Add tests for invalid format specifiers in strftime, and for handling of invalid file descriptors in the os module.
This commit is contained in:
parent
b5bc33cdab
commit
1c62b650d0
|
@ -856,6 +856,14 @@ class TestDate(HarmlessMixedComparison, unittest.TestCase):
|
||||||
# A naive object replaces %z and %Z w/ empty strings.
|
# A naive object replaces %z and %Z w/ empty strings.
|
||||||
self.assertEqual(t.strftime("'%z' '%Z'"), "'' ''")
|
self.assertEqual(t.strftime("'%z' '%Z'"), "'' ''")
|
||||||
|
|
||||||
|
#make sure that invalid format specifiers are handled correctly
|
||||||
|
self.assertRaises(ValueError, t.strftime, "%e")
|
||||||
|
self.assertRaises(ValueError, t.strftime, "%")
|
||||||
|
self.assertRaises(ValueError, t.strftime, "%#")
|
||||||
|
|
||||||
|
#check that this standard extension works
|
||||||
|
t.strftime("%f")
|
||||||
|
|
||||||
|
|
||||||
def test_format(self):
|
def test_format(self):
|
||||||
dt = self.theclass(2007, 9, 10)
|
dt = self.theclass(2007, 9, 10)
|
||||||
|
|
|
@ -533,6 +533,55 @@ class Win32ErrorTests(unittest.TestCase):
|
||||||
def test_chmod(self):
|
def test_chmod(self):
|
||||||
self.assertRaises(WindowsError, os.utime, test_support.TESTFN, 0)
|
self.assertRaises(WindowsError, os.utime, test_support.TESTFN, 0)
|
||||||
|
|
||||||
|
class TestInvalidFD(unittest.TestCase):
|
||||||
|
singles = ["fchdir", "fdopen", "close", "dup", "fdatasync", "fstat",
|
||||||
|
"fstatvfs", "fsync", "tcgetpgrp", "ttyname"]
|
||||||
|
def get_single(f):
|
||||||
|
def helper(self):
|
||||||
|
if getattr(os, f, None):
|
||||||
|
self.assertRaises(OSError, getattr(os, f), 10)
|
||||||
|
return helper
|
||||||
|
for f in singles:
|
||||||
|
locals()["test_"+f] = get_single(f)
|
||||||
|
|
||||||
|
def test_isatty(self):
|
||||||
|
self.assertEqual(os.isatty(10), False)
|
||||||
|
|
||||||
|
def test_closerange(self):
|
||||||
|
self.assertEqual(os.closerange(10, 20), None)
|
||||||
|
|
||||||
|
def test_dup2(self):
|
||||||
|
self.assertRaises(OSError, os.dup2, 10, 20)
|
||||||
|
|
||||||
|
def test_fchmod(self):
|
||||||
|
if hasattr(os, "fchmod"):
|
||||||
|
self.assertRaises(OSError, os.fchmod, 10, 0)
|
||||||
|
|
||||||
|
def test_fchown(self):
|
||||||
|
if hasattr(os, "fchown"):
|
||||||
|
self.assertRaises(OSError, os.fchmod, 10, -1, -1)
|
||||||
|
|
||||||
|
def test_fpathconf(self):
|
||||||
|
if hasattr(os, "fpathconf"):
|
||||||
|
self.assertRaises(OSError, os.fpathconf, 10, "foo")
|
||||||
|
|
||||||
|
def test_ftruncate(self):
|
||||||
|
if hasattr(os, "ftruncate"):
|
||||||
|
self.assertRaises(OSError, os.ftruncate, 10, 0)
|
||||||
|
|
||||||
|
def test_lseek(self):
|
||||||
|
self.assertRaises(OSError, os.lseek, 10, 0, 0)
|
||||||
|
|
||||||
|
def test_read(self):
|
||||||
|
self.assertRaises(OSError, os.read, 10, 1)
|
||||||
|
|
||||||
|
def test_tcsetpgrpt(self):
|
||||||
|
if hasattr(os, "tcsetpgrp"):
|
||||||
|
self.assertRaises(OSError, os.tcsetpgrp, 10, 0)
|
||||||
|
|
||||||
|
def test_write(self):
|
||||||
|
self.assertRaises(OSError, os.write, 10, " ")
|
||||||
|
|
||||||
if sys.platform != 'win32':
|
if sys.platform != 'win32':
|
||||||
class Win32ErrorTests(unittest.TestCase):
|
class Win32ErrorTests(unittest.TestCase):
|
||||||
pass
|
pass
|
||||||
|
@ -547,7 +596,8 @@ def test_main():
|
||||||
MakedirTests,
|
MakedirTests,
|
||||||
DevNullTests,
|
DevNullTests,
|
||||||
URandomTests,
|
URandomTests,
|
||||||
Win32ErrorTests
|
Win32ErrorTests,
|
||||||
|
TestInvalidFD
|
||||||
)
|
)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in New Issue