~pythonregexp2.7/python/issue2636-11

« back to all changes in this revision

Viewing changes to Lib/test/test_os.py

  • Committer: Jeffrey C. "The TimeHorse" Jacobs
  • Date: 2008-09-21 17:53:26 UTC
  • mfrom: (39025.1.14 Regexp-2.7)
  • Revision ID: darklord@timehorse.com-20080921175326-92vaej2hc3yuecxb
Merged in changes from the core Regexp branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
        self.assert_(os.access(test_support.TESTFN, os.W_OK))
25
25
 
26
26
    def test_closerange(self):
27
 
        f = os.open(test_support.TESTFN, os.O_CREAT|os.O_RDWR)
 
27
        first = os.open(test_support.TESTFN, os.O_CREAT|os.O_RDWR)
 
28
        # We must allocate two consecutive file descriptors, otherwise
 
29
        # it will mess up other file descriptors (perhaps even the three
 
30
        # standard ones).
 
31
        second = os.dup(first)
 
32
        try:
 
33
            retries = 0
 
34
            while second != first + 1:
 
35
                os.close(first)
 
36
                retries += 1
 
37
                if retries > 10:
 
38
                    # XXX test skipped
 
39
                    print >> sys.stderr, (
 
40
                        "couldn't allocate two consecutive fds, "
 
41
                        "skipping test_closerange")
 
42
                    return
 
43
                first, second = second, os.dup(second)
 
44
        finally:
 
45
            os.close(second)
28
46
        # close a fd that is open, and one that isn't
29
 
        os.closerange(f, f+2)
30
 
        self.assertRaises(OSError, os.write, f, "a")
 
47
        os.closerange(first, first + 2)
 
48
        self.assertRaises(OSError, os.write, first, "a")
 
49
 
 
50
    def test_rename(self):
 
51
        path = unicode(test_support.TESTFN)
 
52
        old = sys.getrefcount(path)
 
53
        self.assertRaises(TypeError, os.rename, path, 0)
 
54
        new = sys.getrefcount(path)
 
55
        self.assertEqual(old, new)
31
56
 
32
57
 
33
58
class TemporaryFileTests(unittest.TestCase):
276
301
    # systems support centiseconds
277
302
    if sys.platform == 'win32':
278
303
        def get_file_system(path):
279
 
            import os
280
 
            root = os.path.splitdrive(os.path.realpath("."))[0] + '\\'
 
304
            root = os.path.splitdrive(os.path.abspath(path))[0] + '\\'
281
305
            import ctypes
282
306
            kernel32 = ctypes.windll.kernel32
283
307
            buf = ctypes.create_string_buffer("", 100)
295
319
            try:
296
320
                os.stat(r"c:\pagefile.sys")
297
321
            except WindowsError, e:
298
 
                if e == 2: # file does not exist; cannot run test
 
322
                if e.errno == 2: # file does not exist; cannot run test
299
323
                    return
300
324
                self.fail("Could not stat pagefile.sys")
301
325
 
480
504
            self.assertEqual(len(os.urandom(10)), 10)
481
505
            self.assertEqual(len(os.urandom(100)), 100)
482
506
            self.assertEqual(len(os.urandom(1000)), 1000)
 
507
            # see http://bugs.python.org/issue3708
 
508
            self.assertEqual(len(os.urandom(0.9)), 0)
 
509
            self.assertEqual(len(os.urandom(1.1)), 1)
 
510
            self.assertEqual(len(os.urandom(2.0)), 2)
483
511
        except NotImplementedError:
484
512
            pass
485
513