From f91df0465d96affeb101f9892e8e4aaa303192d9 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 13 Feb 2009 02:50:59 +0000 Subject: Merged revisions 69364-69365,69409-69410,69413,69417,69435,69442,69447,69495,69519-69521 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r69364 | kristjan.jonsson | 2009-02-06 04:17:34 -0600 (Fri, 06 Feb 2009) | 1 line Fix a number of Win32ErrorTests error cases. chmod wasn't being tested. 'access' never raises an error. ........ r69365 | armin.rigo | 2009-02-06 05:46:26 -0600 (Fri, 06 Feb 2009) | 2 lines Ivan on IRC in #twisted reported this crasher. ........ r69409 | georg.brandl | 2009-02-07 06:21:17 -0600 (Sat, 07 Feb 2009) | 1 line #5174: fix wrong file closing in example. ........ r69410 | neil.schemenauer | 2009-02-07 08:53:31 -0600 (Sat, 07 Feb 2009) | 4 lines Fix broken test in test_hotshot. Treating the current directory as an empty file is sloppy and non-portable. Use NamedTemporaryFile to make an empty file. ........ r69413 | neil.schemenauer | 2009-02-07 12:35:16 -0600 (Sat, 07 Feb 2009) | 2 lines Add test for issue #999042, explict global statement works. ........ r69417 | benjamin.peterson | 2009-02-07 17:01:19 -0600 (Sat, 07 Feb 2009) | 1 line document individual 2to3 fixers ........ r69435 | benjamin.peterson | 2009-02-08 08:38:13 -0600 (Sun, 08 Feb 2009) | 1 line document numliterals fixer ........ r69442 | benjamin.peterson | 2009-02-08 09:14:57 -0600 (Sun, 08 Feb 2009) | 1 line a few edits and typos ........ r69447 | vinay.sajip | 2009-02-08 13:06:08 -0600 (Sun, 08 Feb 2009) | 2 lines Issue #5170: Fixed Unicode output bug in logging and added test case. This is a regression which did not occur in 2.5. ........ r69495 | kristjan.jonsson | 2009-02-10 07:32:24 -0600 (Tue, 10 Feb 2009) | 1 line Issue 4804. Add a function to test the validity of file descriptors on Windows, and stop using global runtime settings to silence the warnings / assertions. ........ r69519 | gregory.p.smith | 2009-02-11 17:45:25 -0600 (Wed, 11 Feb 2009) | 3 lines Issue #1008086: Fixes socket.inet_aton() to always return 4 bytes even on LP64 platforms (most 64-bit Linux, bsd, unix systems). ........ r69520 | benjamin.peterson | 2009-02-11 21:50:00 -0600 (Wed, 11 Feb 2009) | 1 line os.fsync() should be used to ensure that data is written to disk ........ r69521 | benjamin.peterson | 2009-02-11 22:17:04 -0600 (Wed, 11 Feb 2009) | 1 line no need for this __bases__ trick anymore ........ --- Lib/test/crashers/compiler_recursion.py | 5 +++++ Lib/test/test_logging.py | 27 +++++++++++++++++++++++++-- Lib/test/test_os.py | 12 +++++++----- Lib/test/test_socket.py | 8 ++++++++ 4 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 Lib/test/crashers/compiler_recursion.py (limited to 'Lib/test') diff --git a/Lib/test/crashers/compiler_recursion.py b/Lib/test/crashers/compiler_recursion.py new file mode 100644 index 0000000000..4954bdd8f0 --- /dev/null +++ b/Lib/test/crashers/compiler_recursion.py @@ -0,0 +1,5 @@ +""" +The compiler (>= 2.5) recurses happily. +""" + +compile('()'*9**5, '?', 'exec') diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index c179d1457f..a2ea0dfe49 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2001-2004 by Vinay Sajip. All Rights Reserved. +# Copyright 2001-2009 by Vinay Sajip. All Rights Reserved. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose and without fee is hereby granted, @@ -18,13 +18,14 @@ """Test harness for the logging module. Run all tests. -Copyright (C) 2001-2008 Vinay Sajip. All Rights Reserved. +Copyright (C) 2001-2009 Vinay Sajip. All Rights Reserved. """ import logging import logging.handlers import logging.config +import codecs import copy import pickle import io @@ -860,6 +861,7 @@ class MemoryTest(BaseTest): ('foo', 'DEBUG', '3'), ]) + class EncodingTest(BaseTest): def test_encoding_plain_file(self): # In Python 2.x, a plain file object is treated as having no encoding. @@ -886,6 +888,27 @@ class EncodingTest(BaseTest): if os.path.isfile(fn): os.remove(fn) + def test_encoding_cyrillic_unicode(self): + log = logging.getLogger("test") + #Get a message in Unicode: Do svidanya in Cyrillic (meaning goodbye) + message = '\u0434\u043e \u0441\u0432\u0438\u0434\u0430\u043d\u0438\u044f' + #Ensure it's written in a Cyrillic encoding + writer_class = codecs.getwriter('cp1251') + stream = io.BytesIO() + writer = writer_class(stream, 'strict') + handler = logging.StreamHandler(writer) + log.addHandler(handler) + try: + log.warning(message) + finally: + log.removeHandler(handler) + handler.close() + # check we wrote exactly those bytes, ignoring trailing \n etc + s = stream.getvalue() + #Compare against what the data should be when encoded in CP-1251 + self.assertEqual(s, b'\xe4\xee \xf1\xe2\xe8\xe4\xe0\xed\xe8\xff\n') + + class WarningsTest(BaseTest): def test_warnings(self): logging.captureWarnings(True) diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 51663e16fa..f28f862c76 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -576,16 +576,18 @@ class Win32ErrorTests(unittest.TestCase): self.assertRaises(WindowsError, os.chdir, support.TESTFN) def test_mkdir(self): - self.assertRaises(WindowsError, os.chdir, support.TESTFN) + f = open(test_support.TESTFN, "w") + try: + self.assertRaises(WindowsError, os.mkdir, support.TESTFN) + finally: + f.close() + os.unlink(test_support.TESTFN) def test_utime(self): self.assertRaises(WindowsError, os.utime, support.TESTFN, None) - def test_access(self): - self.assertRaises(WindowsError, os.utime, support.TESTFN, 0) - def test_chmod(self): - self.assertRaises(WindowsError, os.utime, support.TESTFN, 0) + self.assertRaises(WindowsError, os.chmod, support.TESTFN, 0) class TestInvalidFD(unittest.TestCase): singles = ["fchdir", "dup", "fdopen", "fdatasync", "fstat", diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 429ec6f978..e8a9fc42ac 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -398,6 +398,14 @@ class GeneralModuleTests(unittest.TestCase): # Check that setting it to an invalid type raises TypeError self.assertRaises(TypeError, socket.setdefaulttimeout, "spam") + def testIPv4_inet_aton_fourbytes(self): + if not hasattr(socket, 'inet_aton'): + return # No inet_aton, nothing to check + # Test that issue1008086 and issue767150 are fixed. + # It must return 4 bytes. + self.assertEquals(b'\x00'*4, socket.inet_aton('0.0.0.0')) + self.assertEquals(b'\xff'*4, socket.inet_aton('255.255.255.255')) + def testIPv4toString(self): if not hasattr(socket, 'inet_pton'): return # No inet_pton() on this platform -- cgit v1.2.1