diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_ioctl.py | 10 | ||||
-rw-r--r-- | Lib/test/test_urllib2_localnet.py | 24 |
2 files changed, 33 insertions, 1 deletions
diff --git a/Lib/test/test_ioctl.py b/Lib/test/test_ioctl.py index 7fc9c08..51da6a3 100644 --- a/Lib/test/test_ioctl.py +++ b/Lib/test/test_ioctl.py @@ -7,9 +7,17 @@ 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") +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 diff --git a/Lib/test/test_urllib2_localnet.py b/Lib/test/test_urllib2_localnet.py index ef2614bc..5d8a484 100644 --- a/Lib/test/test_urllib2_localnet.py +++ b/Lib/test/test_urllib2_localnet.py @@ -501,6 +501,30 @@ class TestUrlopen(BaseTestCase): # parameterize the framework with a mock resolver. urllib2.urlopen, "http://sadflkjsasf.i.nvali.d./") + def test_iteration(self): + expected_response = "pycon 2008..." + handler = self.start_server([(200, [], expected_response)]) + try: + data = urllib2.urlopen("http://localhost:%s" % handler.port) + for line in data: + self.assertEqual(line, expected_response) + finally: + self.server.stop() + + def ztest_line_iteration(self): + lines = ["We\n", "got\n", "here\n", "verylong " * 8192 + "\n"] + expected_response = "".join(lines) + handler = self.start_server([(200, [], expected_response)]) + try: + data = urllib2.urlopen("http://localhost:%s" % handler.port) + for index, line in enumerate(data): + self.assertEqual(line, lines[index], + "Fetched line number %s doesn't match expected:\n" + " Expected length was %s, got %s" % + (index, len(lines[index]), len(line))) + finally: + self.server.stop() + self.assertEqual(index + 1, len(lines)) def test_main(): # We will NOT depend on the network resource flag |