summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorLarry Hastings <larry@hastings.org>2015-04-20 08:19:55 (GMT)
committerLarry Hastings <larry@hastings.org>2015-04-20 08:19:55 (GMT)
commit1acdb95965928a103dc4222c245931daf7c3fedf (patch)
treee4ef3d4359a230dd59d0cbc448c5e1404e9da840 /Lib
parent103e57a713d3d292924b9b89047f7c3ff8d2d28b (diff)
parent7e9d1d1a1b8ec4db9b9b6789b448c4202ab84b48 (diff)
downloadcpython-1acdb95965928a103dc4222c245931daf7c3fedf.zip
cpython-1acdb95965928a103dc4222c245931daf7c3fedf.tar.gz
cpython-1acdb95965928a103dc4222c245931daf7c3fedf.tar.bz2
Merge Python 3.5.0a4 release engineering commits.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_binascii.py12
-rw-r--r--Lib/test/test_posix.py66
2 files changed, 78 insertions, 0 deletions
diff --git a/Lib/test/test_binascii.py b/Lib/test/test_binascii.py
index 48fcb86..4e67887 100644
--- a/Lib/test/test_binascii.py
+++ b/Lib/test/test_binascii.py
@@ -135,6 +135,18 @@ class BinASCIITest(unittest.TestCase):
# Issue #7701 (crash on a pydebug build)
self.assertEqual(binascii.b2a_uu(b'x'), b'!> \n')
+ def test_crc_hqx(self):
+ crc = binascii.crc_hqx(self.type2test(b"Test the CRC-32 of"), 0)
+ crc = binascii.crc_hqx(self.type2test(b" this string."), crc)
+ self.assertEqual(crc, 14290)
+
+ self.assertRaises(TypeError, binascii.crc_hqx)
+ self.assertRaises(TypeError, binascii.crc_hqx, self.type2test(b''))
+
+ for crc in 0, 1, 0x1234, 0x12345, 0x12345678, -1:
+ self.assertEqual(binascii.crc_hqx(self.type2test(b''), crc),
+ crc & 0xffff)
+
def test_crc32(self):
crc = binascii.crc32(self.type2test(b"Test the CRC-32 of"))
crc = binascii.crc32(self.type2test(b" this string."), crc)
diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py
index f37f2de..77e5b0c4 100644
--- a/Lib/test/test_posix.py
+++ b/Lib/test/test_posix.py
@@ -442,6 +442,36 @@ class PosixTester(unittest.TestCase):
else:
self.assertTrue(stat.S_ISFIFO(posix.stat(support.TESTFN).st_mode))
+ @unittest.skipUnless(hasattr(posix, 'stat'), 'test needs posix.stat()')
+ @unittest.skipUnless(hasattr(posix, 'makedev'), 'test needs posix.makedev()')
+ def test_makedev(self):
+ st = posix.stat(support.TESTFN)
+ dev = st.st_dev
+ self.assertIsInstance(dev, int)
+ self.assertGreaterEqual(dev, 0)
+
+ major = posix.major(dev)
+ self.assertIsInstance(major, int)
+ self.assertGreaterEqual(major, 0)
+ self.assertEqual(posix.major(dev), major)
+ self.assertRaises(TypeError, posix.major, float(dev))
+ self.assertRaises(TypeError, posix.major)
+ self.assertRaises((ValueError, OverflowError), posix.major, -1)
+
+ minor = posix.minor(dev)
+ self.assertIsInstance(minor, int)
+ self.assertGreaterEqual(minor, 0)
+ self.assertEqual(posix.minor(dev), minor)
+ self.assertRaises(TypeError, posix.minor, float(dev))
+ self.assertRaises(TypeError, posix.minor)
+ self.assertRaises((ValueError, OverflowError), posix.minor, -1)
+
+ self.assertEqual(posix.makedev(major, minor), dev)
+ self.assertRaises(TypeError, posix.makedev, float(major), minor)
+ self.assertRaises(TypeError, posix.makedev, major, float(minor))
+ self.assertRaises(TypeError, posix.makedev, major)
+ self.assertRaises(TypeError, posix.makedev)
+
def _test_all_chown_common(self, chown_func, first_param, stat_func):
"""Common code for chown, fchown and lchown tests."""
def check_stat(uid, gid):
@@ -1138,6 +1168,42 @@ class PosixTester(unittest.TestCase):
else:
self.fail("No valid path_error2() test for os." + name)
+ def test_path_with_null_character(self):
+ fn = support.TESTFN
+ fn_with_NUL = fn + '\0'
+ self.addCleanup(support.unlink, fn)
+ support.unlink(fn)
+ fd = None
+ try:
+ with self.assertRaises(ValueError):
+ fd = os.open(fn_with_NUL, os.O_WRONLY | os.O_CREAT) # raises
+ finally:
+ if fd is not None:
+ os.close(fd)
+ self.assertFalse(os.path.exists(fn))
+ self.assertRaises(ValueError, os.mkdir, fn_with_NUL)
+ self.assertFalse(os.path.exists(fn))
+ open(fn, 'wb').close()
+ self.assertRaises(ValueError, os.stat, fn_with_NUL)
+
+ def test_path_with_null_byte(self):
+ fn = os.fsencode(support.TESTFN)
+ fn_with_NUL = fn + b'\0'
+ self.addCleanup(support.unlink, fn)
+ support.unlink(fn)
+ fd = None
+ try:
+ with self.assertRaises(ValueError):
+ fd = os.open(fn_with_NUL, os.O_WRONLY | os.O_CREAT) # raises
+ finally:
+ if fd is not None:
+ os.close(fd)
+ self.assertFalse(os.path.exists(fn))
+ self.assertRaises(ValueError, os.mkdir, fn_with_NUL)
+ self.assertFalse(os.path.exists(fn))
+ open(fn, 'wb').close()
+ self.assertRaises(ValueError, os.stat, fn_with_NUL)
+
class PosixGroupsTester(unittest.TestCase):
def setUp(self):