summaryrefslogtreecommitdiff
path: root/Lib/test/test_os.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2012-02-20 21:44:56 -0500
committerBenjamin Peterson <benjamin@python.org>2012-02-20 21:44:56 -0500
commitaee9dfba4a9230f2832dd69d67e92f8e0490a163 (patch)
tree27a9896969ac7ff79dc75017cff121a077c3eb6e /Lib/test/test_os.py
parent34b345b8885e5db8ab6627c081ca86a8b78b6989 (diff)
parentb19fb2462eac776746f6cb40cc84b0587c83b9bc (diff)
downloadcpython-git-aee9dfba4a9230f2832dd69d67e92f8e0490a163.tar.gz
merge 2.6 with hash randomization fix
Diffstat (limited to 'Lib/test/test_os.py')
-rw-r--r--Lib/test/test_os.py38
1 files changed, 36 insertions, 2 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index eec1621301..d52b78462e 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -10,6 +10,7 @@ import sys
import signal
import subprocess
import time
+
from test import test_support
import mmap
import uuid
@@ -536,8 +537,41 @@ class URandomTests (unittest.TestCase):
self.assertRaises(TypeError, os.urandom, 0.9)
self.assertRaises(TypeError, os.urandom, 1.1)
self.assertRaises(TypeError, os.urandom, 2.0)
- except NotImplementedError:
- pass
+ self.assertEqual(len(os.urandom(0.9)), 0)
+ self.assertEqual(len(os.urandom(1.1)), 1)
+ self.assertEqual(len(os.urandom(2.0)), 2)
+
+ def test_urandom_length(self):
+ self.assertEqual(len(os.urandom(0)), 0)
+ self.assertEqual(len(os.urandom(1)), 1)
+ self.assertEqual(len(os.urandom(10)), 10)
+ self.assertEqual(len(os.urandom(100)), 100)
+ self.assertEqual(len(os.urandom(1000)), 1000)
+
+ def test_urandom_value(self):
+ data1 = os.urandom(16)
+ data2 = os.urandom(16)
+ self.assertNotEqual(data1, data2)
+
+ def get_urandom_subprocess(self, count):
+ code = '\n'.join((
+ 'import os, sys',
+ 'data = os.urandom(%s)' % count,
+ 'sys.stdout.write(data)',
+ 'sys.stdout.flush()'))
+ cmd_line = [sys.executable, '-c', code]
+ p = subprocess.Popen(cmd_line, stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ out, err = p.communicate()
+ out = test_support.strip_python_stderr(out)
+ self.assertEqual(len(out), count)
+ return out
+
+ def test_urandom_subprocess(self):
+ data1 = self.get_urandom_subprocess(16)
+ data2 = self.get_urandom_subprocess(16)
+ self.assertNotEqual(data1, data2)
+>>>>>>> other
def test_execvpe_with_bad_arglist(self):
self.assertRaises(ValueError, os.execvpe, 'notepad', [], None)