Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1624)

Delta Between Two Patch Sets: Lib/test/test_posix.py

Issue 10812: Add some posix functions
Left Patch Set: Created 2 years, 2 months ago
Right Patch Set: Created 2 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 "Test posix functions" 1 "Test posix functions"
2 2
3 from test import support 3 from test import support
4 4
5 # Skip these tests if there is no posix module. 5 # Skip these tests if there is no posix module.
6 posix = support.import_module('posix') 6 posix = support.import_module('posix')
7 7
8 import errno 8 import errno
9 import sys 9 import sys
10 import time 10 import time
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 posix.fexecve(fp, [sys.executable, '-c', 'pass'], os.environ) 151 posix.fexecve(fp, [sys.executable, '-c', 'pass'], os.environ)
152 else: 152 else:
153 self.assertEqual(os.wait(), (pid, 0)) 153 self.assertEqual(os.wait(), (pid, 0))
154 finally: 154 finally:
155 os.close(fp) 155 os.close(fp)
156 156
157 @unittest.skipUnless(hasattr(posix, 'gethostid'), "test needs posix.gethosti d()") 157 @unittest.skipUnless(hasattr(posix, 'gethostid'), "test needs posix.gethosti d()")
158 def test_gethostid(self): 158 def test_gethostid(self):
159 self.assertTrue(isinstance(posix.gethostid(), int)) 159 self.assertTrue(isinstance(posix.gethostid(), int))
160 160
161 @unittest.skipUnless(hasattr(posix, 'sethostname'), "test needs posix.sethos tname()") 161 @unittest.skipUnless(hasattr(posix, 'sethostid'), "test needs posix.sethosti d()")
162 def test_sethostname(self): 162 def test_sethostid(self):
163 import socket 163 hid = os.gethostid()
164 oldhn = socket.gethostname() 164 try:
165 try: 165 posix.sethostid(2464787)
166 posix.sethostname('new')
167 except OSError as e: 166 except OSError as e:
168 self.assertEqual(e.errno, errno.EPERM) 167 if sys.platform.startswith("freebsd"):
168 self.assertEqual(e.errno, errno.EPERM)
169 else:
170 self.assertEqual(e.errno, errno.EACCES)
169 else: 171 else:
170 # running test as root! 172 # running test as root!
171 self.assertEqual(socket.gethostname(), 'new') 173 self.assertEqual(os.gethostid(), 2464787)
172 posix.sethostname(oldhn) 174 posix.sethostid(hid)
173 175
174 @unittest.skipUnless(hasattr(posix, 'waitid'), "test needs posix.waitid()") 176 @unittest.skipUnless(hasattr(posix, 'waitid'), "test needs posix.waitid()")
175 @unittest.skipUnless(hasattr(os, 'fork'), "test needs os.fork()") 177 @unittest.skipUnless(hasattr(os, 'fork'), "test needs os.fork()")
176 def test_waitid(self): 178 def test_waitid(self):
177 pid = os.fork() 179 pid = os.fork()
178 if pid == 0: 180 if pid == 0:
179 os.chdir(os.path.split(sys.executable)[0]) 181 os.chdir(os.path.split(sys.executable)[0])
180 posix.execve(sys.executable, [sys.executable, '-c', 'pass'], os.envi ron) 182 posix.execve(sys.executable, [sys.executable, '-c', 'pass'], os.envi ron)
181 else: 183 else:
182 res = posix.waitid(posix.P_PID, pid, posix.WEXITED) 184 res = posix.waitid(posix.P_PID, pid, posix.WEXITED)
183 self.assertEqual(pid, res[3]) 185 self.assertEqual(pid, res.si_pid)
184 186
185 @unittest.skipUnless(hasattr(posix, 'lockf'), "test needs posix.lockf()") 187 @unittest.skipUnless(hasattr(posix, 'lockf'), "test needs posix.lockf()")
186 def test_lockf(self): 188 def test_lockf(self):
187 fd = os.open(support.TESTFN, os.O_WRONLY | os.O_CREAT) 189 fd = os.open(support.TESTFN, os.O_WRONLY | os.O_CREAT)
188 try: 190 try:
189 os.write(fd, b'test') 191 os.write(fd, b'test')
190 os.lseek(fd, 0, os.SEEK_SET) 192 os.lseek(fd, 0, os.SEEK_SET)
191 posix.lockf(fd, posix.F_LOCK, 4) 193 posix.lockf(fd, posix.F_LOCK, 4)
192 # section is locked 194 # section is locked
193 posix.lockf(fd, posix.F_ULOCK, 4) 195 posix.lockf(fd, posix.F_ULOCK, 4)
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 for groups in [[0], list(range(16))]: 589 for groups in [[0], list(range(16))]:
588 posix.setgroups(groups) 590 posix.setgroups(groups)
589 self.assertListEqual(groups, posix.getgroups()) 591 self.assertListEqual(groups, posix.getgroups())
590 592
591 593
592 def test_main(): 594 def test_main():
593 support.run_unittest(PosixTester, PosixGroupsTester) 595 support.run_unittest(PosixTester, PosixGroupsTester)
594 596
595 if __name__ == '__main__': 597 if __name__ == '__main__':
596 test_main() 598 test_main()
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld cbc36f91f3f7