diff options
author | Éric Araujo <merwok@netwok.org> | 2011-07-28 23:08:11 +0200 |
---|---|---|
committer | Éric Araujo <merwok@netwok.org> | 2011-07-28 23:08:11 +0200 |
commit | cf534817adc49b2562d175fabd3e3992d25063fe (patch) | |
tree | d2cb18e71d6b5cc25384146751b00c2172a327b6 /Lib/test | |
parent | 9e1af03fbb2a9fc1472ac866add02c99b0c88b16 (diff) | |
parent | fc662ddda2bfd43b10c0a4f8a814e36445f22515 (diff) | |
download | cpython-git-cf534817adc49b2562d175fabd3e3992d25063fe.tar.gz |
Branch merge
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_codecs.py | 2 | ||||
-rw-r--r-- | Lib/test/test_locale.py | 6 | ||||
-rw-r--r-- | Lib/test/test_posix.py | 4 | ||||
-rw-r--r-- | Lib/test/test_subprocess.py | 58 | ||||
-rw-r--r-- | Lib/test/test_urllib2net.py | 16 |
5 files changed, 81 insertions, 5 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index 6b84023d23..4899a59ef2 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -1234,7 +1234,7 @@ class CodecsModuleTest(unittest.TestCase): def test_lookup_issue1813(self): # Issue #1813: under Turkish locales, lookup of some codecs failed # because 'I' is lowercased as "ı" (dotless i) - oldlocale = locale.getlocale(locale.LC_CTYPE) + oldlocale = locale.setlocale(locale.LC_CTYPE) self.addCleanup(locale.setlocale, locale.LC_CTYPE, oldlocale) try: locale.setlocale(locale.LC_CTYPE, 'tr_TR') diff --git a/Lib/test/test_locale.py b/Lib/test/test_locale.py index 5155923c91..46e228ef8e 100644 --- a/Lib/test/test_locale.py +++ b/Lib/test/test_locale.py @@ -393,16 +393,16 @@ class TestMiscellaneous(unittest.TestCase): def test_getsetlocale_issue1813(self): # Issue #1813: setting and getting the locale under a Turkish locale - oldlocale = locale.getlocale() + oldlocale = locale.setlocale(locale.LC_CTYPE) self.addCleanup(locale.setlocale, locale.LC_CTYPE, oldlocale) try: locale.setlocale(locale.LC_CTYPE, 'tr_TR') except locale.Error: # Unsupported locale on this system self.skipTest('test needs Turkish locale') - loc = locale.getlocale() + loc = locale.getlocale(locale.LC_CTYPE) locale.setlocale(locale.LC_CTYPE, loc) - self.assertEqual(loc, locale.getlocale()) + self.assertEqual(loc, locale.getlocale(locale.LC_CTYPE)) def test_main(): diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index 556305003b..09f04ec348 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -12,10 +12,12 @@ import os import pwd import shutil import stat +import tempfile import unittest import warnings -_DUMMY_SYMLINK = '%s/dummy-symlink' % os.getenv('TMPDIR', '/tmp') +_DUMMY_SYMLINK = os.path.join(tempfile.gettempdir(), + support.TESTFN + '-dummy-symlink') class PosixTester(unittest.TestCase): diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index 3440b45485..8382c720d1 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -1106,6 +1106,64 @@ class POSIXProcessTestCase(BaseTestCase): for fd in temp_fds: os.close(fd) + def check_swap_fds(self, stdin_no, stdout_no, stderr_no): + # open up some temporary files + temps = [mkstemp() for i in range(3)] + temp_fds = [fd for fd, fname in temps] + try: + # unlink the files -- we won't need to reopen them + for fd, fname in temps: + os.unlink(fname) + + # save a copy of the standard file descriptors + saved_fds = [os.dup(fd) for fd in range(3)] + try: + # duplicate the temp files over the standard fd's 0, 1, 2 + for fd, temp_fd in enumerate(temp_fds): + os.dup2(temp_fd, fd) + + # write some data to what will become stdin, and rewind + os.write(stdin_no, b"STDIN") + os.lseek(stdin_no, 0, 0) + + # now use those files in the given order, so that subprocess + # has to rearrange them in the child + p = subprocess.Popen([sys.executable, "-c", + 'import sys; got = sys.stdin.read();' + 'sys.stdout.write("got %s"%got); sys.stderr.write("err")'], + stdin=stdin_no, + stdout=stdout_no, + stderr=stderr_no) + p.wait() + + for fd in temp_fds: + os.lseek(fd, 0, 0) + + out = os.read(stdout_no, 1024) + err = support.strip_python_stderr(os.read(stderr_no, 1024)) + finally: + for std, saved in enumerate(saved_fds): + os.dup2(saved, std) + os.close(saved) + + self.assertEqual(out, b"got STDIN") + self.assertEqual(err, b"err") + + finally: + for fd in temp_fds: + os.close(fd) + + # When duping fds, if there arises a situation where one of the fds is + # either 0, 1 or 2, it is possible that it is overwritten (#12607). + # This tests all combinations of this. + def test_swap_fds(self): + self.check_swap_fds(0, 1, 2) + self.check_swap_fds(0, 2, 1) + self.check_swap_fds(1, 0, 2) + self.check_swap_fds(1, 2, 0) + self.check_swap_fds(2, 0, 1) + self.check_swap_fds(2, 1, 0) + def test_surrogates_error_message(self): def prepare(): raise ValueError("surrogate:\uDCff") diff --git a/Lib/test/test_urllib2net.py b/Lib/test/test_urllib2net.py index a475f56402..cd225c90fd 100644 --- a/Lib/test/test_urllib2net.py +++ b/Lib/test/test_urllib2net.py @@ -174,6 +174,22 @@ class OtherNetworkTests(unittest.TestCase): opener.open(request) self.assertEqual(request.get_header('User-agent'),'Test-Agent') + def test_sites_no_connection_close(self): + # Some sites do not send Connection: close header. + # Verify that those work properly. (#issue12576) + + try: + with urllib.request.urlopen('http://www.imdb.com') as res: + pass + except ValueError as e: + self.fail("urlopen failed for sites not sending Connection:close") + else: + self.assertTrue(res) + + req = urllib.request.urlopen('http://www.imdb.com') + res = req.read() + self.assertTrue(res) + def _test_urls(self, urls, handlers, retry=True): import time import logging |