24
24
self.assert_(os.access(test_support.TESTFN, os.W_OK))
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
31
second = os.dup(first)
34
while second != first + 1:
39
print >> sys.stderr, (
40
"couldn't allocate two consecutive fds, "
41
"skipping test_closerange")
43
first, second = second, os.dup(second)
28
46
# close a fd that is open, and one that isn't
30
self.assertRaises(OSError, os.write, f, "a")
47
os.closerange(first, first + 2)
48
self.assertRaises(OSError, os.write, first, "a")
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)
33
58
class TemporaryFileTests(unittest.TestCase):
276
301
# systems support centiseconds
277
302
if sys.platform == 'win32':
278
303
def get_file_system(path):
280
root = os.path.splitdrive(os.path.realpath("."))[0] + '\\'
304
root = os.path.splitdrive(os.path.abspath(path))[0] + '\\'
282
306
kernel32 = ctypes.windll.kernel32
283
307
buf = ctypes.create_string_buffer("", 100)
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: