summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_mmap.py21
-rw-r--r--Lib/test/test_os.py45
-rw-r--r--Lib/test/test_posixpath.py5
-rw-r--r--Lib/test/test_sys.py8
4 files changed, 68 insertions, 11 deletions
diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py
index f3e28cc..dec0980 100644
--- a/Lib/test/test_mmap.py
+++ b/Lib/test/test_mmap.py
@@ -357,15 +357,22 @@ class MmapTests(unittest.TestCase):
m.move(source, dest, size)
except ValueError:
pass
- self.assertRaises(ValueError, m.move, -1, -1, -1)
- self.assertRaises(ValueError, m.move, -1, -1, 0)
- self.assertRaises(ValueError, m.move, -1, 0, -1)
- self.assertRaises(ValueError, m.move, 0, -1, -1)
- self.assertRaises(ValueError, m.move, -1, 0, 0)
- self.assertRaises(ValueError, m.move, 0, -1, 0)
- self.assertRaises(ValueError, m.move, 0, 0, -1)
+
+ offsets = [(-1, -1, -1), (-1, -1, 0), (-1, 0, -1), (0, -1, -1),
+ (-1, 0, 0), (0, -1, 0), (0, 0, -1)]
+ for source, dest, size in offsets:
+ self.assertRaises(ValueError, m.move, source, dest, size)
+
m.close()
+ m = mmap.mmap(-1, 1) # single byte
+ self.assertRaises(ValueError, m.move, 0, 0, 2)
+ self.assertRaises(ValueError, m.move, 1, 0, 1)
+ self.assertRaises(ValueError, m.move, 0, 1, 1)
+ m.move(0, 0, 1)
+ m.move(0, 0, 0)
+
+
def test_anonymous(self):
# anonymous mmap.mmap(-1, PAGE)
m = mmap.mmap(-1, PAGESIZE)
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index 0136c5e..91e0432 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -660,6 +660,48 @@ if sys.platform != 'win32':
class Win32ErrorTests(unittest.TestCase):
pass
+ class PosixUidGidTests(unittest.TestCase):
+ if hasattr(os, 'setuid'):
+ def test_setuid(self):
+ if os.getuid() != 0:
+ self.assertRaises(os.error, os.setuid, 0)
+ self.assertRaises(OverflowError, os.setuid, 1<<32)
+
+ if hasattr(os, 'setgid'):
+ def test_setgid(self):
+ if os.getuid() != 0:
+ self.assertRaises(os.error, os.setgid, 0)
+ self.assertRaises(OverflowError, os.setgid, 1<<32)
+
+ if hasattr(os, 'seteuid'):
+ def test_seteuid(self):
+ if os.getuid() != 0:
+ self.assertRaises(os.error, os.seteuid, 0)
+ self.assertRaises(OverflowError, os.seteuid, 1<<32)
+
+ if hasattr(os, 'setegid'):
+ def test_setegid(self):
+ if os.getuid() != 0:
+ self.assertRaises(os.error, os.setegid, 0)
+ self.assertRaises(OverflowError, os.setegid, 1<<32)
+
+ if hasattr(os, 'setreuid'):
+ def test_setreuid(self):
+ if os.getuid() != 0:
+ self.assertRaises(os.error, os.setreuid, 0, 0)
+ self.assertRaises(OverflowError, os.setreuid, 1<<32, 0)
+ self.assertRaises(OverflowError, os.setreuid, 0, 1<<32)
+
+ if hasattr(os, 'setregid'):
+ def test_setregid(self):
+ if os.getuid() != 0:
+ self.assertRaises(os.error, os.setregid, 0, 0)
+ self.assertRaises(OverflowError, os.setregid, 1<<32, 0)
+ self.assertRaises(OverflowError, os.setregid, 0, 1<<32)
+else:
+ class PosixUidGidTests(unittest.TestCase):
+ pass
+
def test_main():
support.run_unittest(
FileTests,
@@ -671,7 +713,8 @@ def test_main():
URandomTests,
ExecTests,
Win32ErrorTests,
- TestInvalidFD
+ TestInvalidFD,
+ PosixUidGidTests
)
if __name__ == "__main__":
diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py
index 3676e9f..7de94e7 100644
--- a/Lib/test/test_posixpath.py
+++ b/Lib/test/test_posixpath.py
@@ -419,6 +419,11 @@ class PosixPathTest(unittest.TestCase):
self.assert_(isinstance(posixpath.expanduser(b"~root/"), bytes))
self.assert_(isinstance(posixpath.expanduser(b"~foo/"), bytes))
+ orig_home = os.environ['HOME']
+ os.environ['HOME'] = '/'
+ self.assertEqual(posixpath.expanduser("~"), "/")
+ os.environ['HOME'] = orig_home
+
self.assertRaises(TypeError, posixpath.expanduser)
def test_expandvars(self):
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index 474d855..201f490 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -344,6 +344,8 @@ class SysModuleTest(unittest.TestCase):
self.assertEqual(len(sys.int_info), 2)
self.assert_(sys.int_info.bits_per_digit % 5 == 0)
self.assert_(sys.int_info.sizeof_digit >= 1)
+ self.assertEqual(type(sys.int_info.bits_per_digit), int)
+ self.assertEqual(type(sys.int_info.sizeof_digit), int)
self.assert_(isinstance(sys.hexversion, int))
self.assert_(isinstance(sys.maxsize, int))
self.assert_(isinstance(sys.maxunicode, int))
@@ -622,9 +624,9 @@ class SizeofTest(unittest.TestCase):
check(1, size(vh) + self.longdigit)
check(-1, size(vh) + self.longdigit)
PyLong_BASE = 2**sys.int_info.bits_per_digit
- check(PyLong_BASE, size(vh) + 2*self.longdigit)
- check(PyLong_BASE**2-1, size(vh) + 2*self.longdigit)
- check(PyLong_BASE**2, size(vh) + 3*self.longdigit)
+ check(int(PyLong_BASE), size(vh) + 2*self.longdigit)
+ check(int(PyLong_BASE**2-1), size(vh) + 2*self.longdigit)
+ check(int(PyLong_BASE**2), size(vh) + 3*self.longdigit)
# memory
check(memoryview(b''), size(h + 'P PP2P2i7P'))
# module