def test_symlink(self): # Issue 7880 symlink = get_attribute(os, "symlink") def get(python): cmd = [python, '-c', 'import sysconfig; print sysconfig.get_platform()'] p = subprocess.Popen(cmd, stdout=subprocess.PIPE) return p.communicate() real = os.path.realpath(sys.executable) link = os.path.abspath(TESTFN) symlink(real, link) try: self.assertEqual(get(real), get(link)) finally: unlink(link)
import array import unittest from test.test_support import run_unittest, import_module, get_attribute import os, struct fcntl = import_module('fcntl') termios = import_module('termios') get_attribute(termios, 'TIOCGPGRP') #Can't run tests without this feature try: tty = open("/dev/tty", "r") except IOError: raise unittest.SkipTest("Unable to open /dev/tty") else: # Skip if another process is in foreground r = fcntl.ioctl(tty, termios.TIOCGPGRP, " ") tty.close() rpgrp = struct.unpack("i", r)[0] if rpgrp not in (os.getpgrp(), os.getsid(0)): raise unittest.SkipTest("Neither the process group nor the session " "are attached to /dev/tty") del tty, r, rpgrp try: import pty except ImportError: pty = None class IoctlTests(unittest.TestCase): def test_ioctl(self): # If this process has been put into the background, TIOCGPGRP returns
import unittest from test.test_support import run_unittest, import_module, get_attribute import os, struct fcntl = import_module('fcntl') termios = import_module('termios') get_attribute(termios, 'TIOCGPGRP') #Can't run tests without this feature try: tty = open("/dev/tty", "r") tty.close() except IOError: raise unittest.SkipTest("Unable to open /dev/tty") try: import pty except ImportError: pty = None class IoctlTests(unittest.TestCase): def test_ioctl(self): # If this process has been put into the background, TIOCGPGRP returns # the session ID instead of the process group id. ids = (os.getpgrp(), os.getsid(0)) tty = open("/dev/tty", "r") r = fcntl.ioctl(tty, termios.TIOCGPGRP, " ") rpgrp = struct.unpack("i", r)[0] self.assertIn(rpgrp, ids) def test_ioctl_mutate(self): import array buf = array.array('i', [0])
def test_connect_default_port(self): test_support.get_attribute(smtplib, 'SMTP_SSL') with test_support.transient_internet(self.testServer): server = smtplib.SMTP_SSL(self.testServer) server.ehlo() server.quit()
# Ridiculously simple test of the os.startfile function for Windows. # # empty.vbs is an empty file (except for a comment), which does # nothing when run with cscript or wscript. # # A possible improvement would be to have empty.vbs do something that # we can detect here, to make sure that not only the os.startfile() # call succeeded, but also the the script actually has run. import unittest from test import test_support import os from os import path startfile = test_support.get_attribute(os, "startfile") class TestCase(unittest.TestCase): def test_nonexisting(self): self.assertRaises(OSError, startfile, "nonexisting.vbs") def test_nonexisting_u(self): self.assertRaises(OSError, startfile, u"nonexisting.vbs") def test_empty(self): empty = path.join(path.dirname(__file__), "empty.vbs") startfile(empty) startfile(empty, "open") def test_empty_u(self): empty = path.join(path.dirname(__file__), "empty.vbs")
"""This test checks for correct wait4() behavior. """ import os import time import sys from test.fork_wait import ForkWait from test.test_support import run_unittest, reap_children, get_attribute # If either of these do not exist, skip this test. get_attribute(os, 'fork') get_attribute(os, 'wait4') class Wait4Test(ForkWait): def wait_impl(self, cpid): option = os.WNOHANG if sys.platform.startswith('aix'): # Issue #11185: wait4 is broken on AIX and will always return 0 # with WNOHANG. option = 0 for i in range(10): # wait4() shouldn't hang, but some of the buildbots seem to hang # in the forking tests. This is an attempt to fix the problem. spid, status, rusage = os.wait4(cpid, option) if spid == cpid: break time.sleep(1.0) self.assertEqual(spid, cpid) self.assertEqual( status, 0, "cause = %d, exit = %d" % (status & 0xff, status >> 8))
# Ridiculously simple test of the os.startfile function for Windows. # # empty.vbs is an empty file (except for a comment), which does # nothing when run with cscript or wscript. # # A possible improvement would be to have empty.vbs do something that # we can detect here, to make sure that not only the os.startfile() # call succeeded, but also the the script actually has run. import unittest from test import test_support import os from os import path startfile = test_support.get_attribute(os, 'startfile') class TestCase(unittest.TestCase): def test_nonexisting(self): self.assertRaises(OSError, startfile, "nonexisting.vbs") def test_nonexisting_u(self): self.assertRaises(OSError, startfile, u"nonexisting.vbs") def test_empty(self): empty = path.join(path.dirname(__file__), "empty.vbs") startfile(empty) startfile(empty, "open") def test_empty_u(self): empty = path.join(path.dirname(__file__), "empty.vbs")
"""This test checks for correct wait4() behavior. """ import os import time import sys from test.fork_wait import ForkWait from test.test_support import run_unittest, reap_children, get_attribute # If either of these do not exist, skip this test. get_attribute(os, 'fork') get_attribute(os, 'wait4') class Wait4Test(ForkWait): def wait_impl(self, cpid): option = os.WNOHANG if sys.platform.startswith('aix'): # Issue #11185: wait4 is broken on AIX and will always return 0 # with WNOHANG. option = 0 for i in range(10): # wait4() shouldn't hang, but some of the buildbots seem to hang # in the forking tests. This is an attempt to fix the problem. spid, status, rusage = os.wait4(cpid, option) if spid == cpid: break time.sleep(1.0) self.assertEqual(spid, cpid) self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8)) self.assertTrue(rusage)
"""This test checks for correct fork() behavior. """ import imp import os import signal import sys import time from test.fork_wait import ForkWait from test.test_support import run_unittest, reap_children, get_attribute, import_module threading = import_module('threading') #Skip test if fork does not exist. get_attribute(os, 'fork') class ForkTest(ForkWait): def wait_impl(self, cpid): for i in range(10): # waitpid() shouldn't hang, but some of the buildbots seem to hang # in the forking tests. This is an attempt to fix the problem. spid, status = os.waitpid(cpid, os.WNOHANG) if spid == cpid: break time.sleep(1.0) self.assertEqual(spid, cpid) self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8)) def test_import_lock_fork(self):
# Ridiculously simple test of the os.startfile function for Windows. # # empty.vbs is an empty file (except for a comment), which does # nothing when run with cscript or wscript. # # A possible improvement would be to have empty.vbs do something that # we can detect here, to make sure that not only the os.startfile() # call succeeded, but also the the script actually has run. import unittest from test import test_support import os from os import path from time import sleep startfile = test_support.get_attribute(os, 'startfile') class TestCase(unittest.TestCase): def test_nonexisting(self): self.assertRaises(OSError, startfile, "nonexisting.vbs") def test_nonexisting_u(self): self.assertRaises(OSError, startfile, u"nonexisting.vbs") def test_empty(self): empty = path.join(path.dirname(__file__), "empty.vbs") startfile(empty) startfile(empty, "open") # Give the child process some time to exit before we finish. # Otherwise the cleanup code will not be able to delete the cwd,
def test_connect(self): test_support.get_attribute(smtplib, "SMTP_SSL") with test_support.transient_internet(self.testServer): server = smtplib.SMTP_SSL(self.testServer, self.remotePort) server.ehlo() server.quit()
def test_connect(self): test_support.get_attribute(smtplib, 'SMTP_SSL') server = smtplib.SMTP_SSL(self.testServer, self.remotePort) server.ehlo() server.quit()
"""This test checks for correct fork() behavior. """ import imp import os import signal import sys import time from test.fork_wait import ForkWait from test.test_support import run_unittest, reap_children, get_attribute, import_module threading = import_module("threading") # Skip test if fork does not exist. get_attribute(os, "fork") class ForkTest(ForkWait): def wait_impl(self, cpid): for i in range(10): # waitpid() shouldn't hang, but some of the buildbots seem to hang # in the forking tests. This is an attempt to fix the problem. spid, status = os.waitpid(cpid, os.WNOHANG) if spid == cpid: break time.sleep(1.0) self.assertEqual(spid, cpid) self.assertEqual(status, 0, "cause = %d, exit = %d" % (status & 0xFF, status >> 8))
# expected: fail """This test checks for correct fork() behavior. """ import imp import os import signal import sys import time from test.fork_wait import ForkWait from test.test_support import run_unittest, reap_children, get_attribute, import_module threading = import_module('threading') #Skip test if fork does not exist. get_attribute(os, 'fork') class ForkTest(ForkWait): def wait_impl(self, cpid): for i in range(10): # waitpid() shouldn't hang, but some of the buildbots seem to hang # in the forking tests. This is an attempt to fix the problem. spid, status = os.waitpid(cpid, os.WNOHANG) if spid == cpid: break time.sleep(1.0) self.assertEqual(spid, cpid) self.assertEqual( status, 0, "cause = %d, exit = %d" % (status & 0xff, status >> 8))