~ubuntu-branches/ubuntu/karmic/python3.0/karmic

« back to all changes in this revision

Viewing changes to Lib/test/test_os.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-02-16 17:18:23 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20090216171823-1d5cm5qnnjvmnzzm
Tags: 3.0.1-0ubuntu1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
# portable than they had been thought to be.
4
4
 
5
5
import os
 
6
import errno
6
7
import unittest
7
8
import warnings
8
9
import sys
277
278
            result = os.statvfs(self.fname)
278
279
        except OSError as e:
279
280
            # On AtheOS, glibc always returns ENOSYS
280
 
            import errno
281
281
            if e.errno == errno.ENOSYS:
282
282
                return
283
283
 
587
587
    def test_chmod(self):
588
588
        self.assertRaises(WindowsError, os.utime, support.TESTFN, 0)
589
589
 
 
590
 
 
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
 
596
    def get_single(f):
 
597
        def helper(self):
 
598
            if  hasattr(os, f):
 
599
                self.check(getattr(os, f))
 
600
        return helper
 
601
    for f in singles:
 
602
        locals()["test_"+f] = get_single(f)
 
603
 
 
604
    def check(self, f, *args):
 
605
        try:
 
606
            f(support.make_bad_fd(), *args)
 
607
        except OSError as e:
 
608
            self.assertEqual(e.errno, errno.EBADF)
 
609
        else:
 
610
            self.fail("%r didn't raise a OSError with a bad file descriptor"
 
611
                      % f)
 
612
 
 
613
    def test_isatty(self):
 
614
        if hasattr(os, "isatty"):
 
615
            self.assertEqual(os.isatty(support.make_bad_fd()), False)
 
616
 
 
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)
 
621
 
 
622
    def test_dup2(self):
 
623
        if hasattr(os, "dup2"):
 
624
            self.check(os.dup2, 20)
 
625
 
 
626
    def test_fchmod(self):
 
627
        if hasattr(os, "fchmod"):
 
628
            self.check(os.fchmod, 0)
 
629
 
 
630
    def test_fchown(self):
 
631
        if hasattr(os, "fchown"):
 
632
            self.check(os.fchown, -1, -1)
 
633
 
 
634
    def test_fpathconf(self):
 
635
        if hasattr(os, "fpathconf"):
 
636
            self.check(os.fpathconf, "PC_NAME_MAX")
 
637
 
 
638
    def test_lseek(self):
 
639
        if hasattr(os, "lseek"):
 
640
            self.check(os.lseek, 0, 0)
 
641
 
 
642
    def test_read(self):
 
643
        if hasattr(os, "read"):
 
644
            self.check(os.read, 1)
 
645
 
 
646
    def test_tcsetpgrpt(self):
 
647
        if hasattr(os, "tcsetpgrp"):
 
648
            self.check(os.tcsetpgrp, 0)
 
649
 
 
650
    def test_write(self):
 
651
        if hasattr(os, "write"):
 
652
            self.check(os.write, b" ")
 
653
 
 
654
 
590
655
if sys.platform != 'win32':
591
656
    class Win32ErrorTests(unittest.TestCase):
592
657
        pass