587
587
def test_chmod(self):
588
588
self.assertRaises(WindowsError, os.utime, support.TESTFN, 0)
591
class TestInvalidFD(unittest.TestCase):
592
singles = ["fchdir", "dup", "fdopen", "fdatasync", "fstat",
593
"fstatvfs", "fsync", "tcgetpgrp", "ttyname"]
594
#singles.append("close")
595
#We omit close because it doesn'r raise an exception on some platforms
599
self.check(getattr(os, f))
602
locals()["test_"+f] = get_single(f)
604
def check(self, f, *args):
606
f(support.make_bad_fd(), *args)
608
self.assertEqual(e.errno, errno.EBADF)
610
self.fail("%r didn't raise a OSError with a bad file descriptor"
613
def test_isatty(self):
614
if hasattr(os, "isatty"):
615
self.assertEqual(os.isatty(support.make_bad_fd()), False)
617
def test_closerange(self):
618
if hasattr(os, "closerange"):
619
fd = support.make_bad_fd()
620
self.assertEqual(os.closerange(fd, fd + 10), None)
623
if hasattr(os, "dup2"):
624
self.check(os.dup2, 20)
626
def test_fchmod(self):
627
if hasattr(os, "fchmod"):
628
self.check(os.fchmod, 0)
630
def test_fchown(self):
631
if hasattr(os, "fchown"):
632
self.check(os.fchown, -1, -1)
634
def test_fpathconf(self):
635
if hasattr(os, "fpathconf"):
636
self.check(os.fpathconf, "PC_NAME_MAX")
638
def test_lseek(self):
639
if hasattr(os, "lseek"):
640
self.check(os.lseek, 0, 0)
643
if hasattr(os, "read"):
644
self.check(os.read, 1)
646
def test_tcsetpgrpt(self):
647
if hasattr(os, "tcsetpgrp"):
648
self.check(os.tcsetpgrp, 0)
650
def test_write(self):
651
if hasattr(os, "write"):
652
self.check(os.write, b" ")
590
655
if sys.platform != 'win32':
591
656
class Win32ErrorTests(unittest.TestCase):