diff options
| author | Brian Curtin <brian@python.org> | 2011-11-07 14:19:46 -0600 |
|---|---|---|
| committer | Brian Curtin <brian@python.org> | 2011-11-07 14:19:46 -0600 |
| commit | ca0fbc02e9971ead5436473e15320652c1fd97c8 (patch) | |
| tree | 4b54cf71920a50bceed96d6f575ed1cbf0abac17 /Lib/test | |
| parent | c1b65d1831265534cb1613d7bf0ad7643fddb795 (diff) | |
| parent | ca6befb77f007ee74137bcbfc26f3fe1345bd886 (diff) | |
| download | cpython-git-ca0fbc02e9971ead5436473e15320652c1fd97c8.tar.gz | |
branch merge
Diffstat (limited to 'Lib/test')
| -rwxr-xr-x | Lib/test/regrtest.py | 19 | ||||
| -rw-r--r-- | Lib/test/test_fileinput.py | 28 | ||||
| -rw-r--r-- | Lib/test/test_logging.py | 23 | ||||
| -rw-r--r-- | Lib/test/test_unicode_file.py | 10 |
4 files changed, 53 insertions, 27 deletions
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py index bbda525bea..9fe7bbabc7 100755 --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -172,6 +172,7 @@ import io import json import logging import os +import packaging.command import packaging.database import platform import random @@ -967,7 +968,7 @@ class saved_test_environment: 'sys.warnoptions', 'threading._dangling', 'multiprocessing.process._dangling', 'sysconfig._CONFIG_VARS', 'sysconfig._SCHEMES', - 'packaging.database_caches', + 'packaging.command._COMMANDS', 'packaging.database_caches', ) def get_sys_argv(self): @@ -1055,6 +1056,22 @@ class saved_test_environment: # Can't easily revert the logging state pass + def get_packaging_command__COMMANDS(self): + # registry mapping command names to full dotted path or to the actual + # class (resolved on demand); this check only looks at the names, not + # the types of the values (IOW, if a value changes from a string + # (dotted path) to a class it's okay but if a key (i.e. command class) + # is added we complain) + id_ = id(packaging.command._COMMANDS) + keys = set(packaging.command._COMMANDS) + return id_, keys + def restore_packaging_command__COMMANDS(self, saved): + # if command._COMMANDS was bound to another dict obhect, we can't + # restore the previous object and contents, because the get_ method + # above does not return the dict object (to ignore changes in values) + for key in packaging.command._COMMANDS.keys() - saved[1]: + del packaging.command._COMMANDS[key] + def get_packaging_database_caches(self): # caching system used by the PEP 376 implementation # we have one boolean and four dictionaries, initially empty diff --git a/Lib/test/test_fileinput.py b/Lib/test/test_fileinput.py index a96d48a561..1e70641150 100644 --- a/Lib/test/test_fileinput.py +++ b/Lib/test/test_fileinput.py @@ -7,8 +7,7 @@ import sys import re import fileinput import collections -import types -import codecs +import builtins import unittest try: @@ -807,18 +806,8 @@ class Test_hook_compressed(unittest.TestCase): @staticmethod def replace_builtin_open(new_open_func): - builtins_type = type(__builtins__) - if builtins_type is dict: - original_open = __builtins__["open"] - __builtins__["open"] = new_open_func - elif builtins_type is types.ModuleType: - original_open = __builtins__.open - __builtins__.open = new_open_func - else: - raise RuntimeError( - "unknown __builtins__ type: %r (unable to replace open)" % - builtins_type) - + original_open = builtins.open + builtins.open = new_open_func return original_open class Test_hook_encoded(unittest.TestCase): @@ -829,21 +818,22 @@ class Test_hook_encoded(unittest.TestCase): result = fileinput.hook_encoded(encoding) fake_open = InvocationRecorder() - original_open = codecs.open - codecs.open = fake_open + original_open = builtins.open + builtins.open = fake_open try: filename = object() mode = object() open_result = result(filename, mode) finally: - codecs.open = original_open + builtins.open = original_open self.assertEqual(fake_open.invocation_count, 1) - args = fake_open.last_invocation[0] + args, kwargs = fake_open.last_invocation self.assertIs(args[0], filename) self.assertIs(args[1], mode) - self.assertIs(args[2], encoding) + self.assertIs(kwargs.pop('encoding'), encoding) + self.assertFalse(kwargs) def test_main(): run_unittest( diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index ed22d91f0c..25ca0b8553 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -49,6 +49,7 @@ import weakref try: import threading # The following imports are needed only for tests which + # require threading import asynchat import asyncore import errno @@ -95,9 +96,7 @@ class BaseTest(unittest.TestCase): finally: logging._releaseLock() - # Set two unused loggers: one non-ASCII and one Unicode. - # This is to test correct operation when sorting existing - # loggers in the configuration code. See issue 8201. + # Set two unused loggers self.logger1 = logging.getLogger("\xab\xd7\xbb") self.logger2 = logging.getLogger("\u013f\u00d6\u0047") @@ -310,8 +309,6 @@ class BuiltinLevelsTest(BaseTest): ('INF.BADPARENT', 'INFO', '4'), ]) - def test_invalid_name(self): - self.assertRaises(TypeError, logging.getLogger, any) class BasicFilterTest(BaseTest): @@ -3514,6 +3511,22 @@ class LoggerTest(BaseTest): self.addCleanup(setattr, self.logger.manager, 'disable', old_disable) self.assertFalse(self.logger.isEnabledFor(22)) + def test_root_logger_aliases(self): + root = logging.getLogger() + self.assertIs(root, logging.root) + self.assertIs(root, logging.getLogger(None)) + self.assertIs(root, logging.getLogger('')) + self.assertIs(root, logging.getLogger('foo').root) + self.assertIs(root, logging.getLogger('foo.bar').root) + self.assertIs(root, logging.getLogger('foo').parent) + + self.assertIsNot(root, logging.getLogger('\0')) + self.assertIsNot(root, logging.getLogger('foo.bar').parent) + + def test_invalid_names(self): + self.assertRaises(TypeError, logging.getLogger, any) + self.assertRaises(TypeError, logging.getLogger, b'foo') + class BaseFileTest(BaseTest): "Base class for handler tests that write log files" diff --git a/Lib/test/test_unicode_file.py b/Lib/test/test_unicode_file.py index 68bd658a75..45bcf5cbd1 100644 --- a/Lib/test/test_unicode_file.py +++ b/Lib/test/test_unicode_file.py @@ -56,16 +56,20 @@ class TestUnicodeFiles(unittest.TestCase): # Should be able to rename the file using either name. self.assertTrue(os.path.isfile(filename1)) # must exist. os.rename(filename1, filename2 + ".new") - self.assertTrue(os.path.isfile(filename1+".new")) + self.assertFalse(os.path.isfile(filename2)) + self.assertTrue(os.path.isfile(filename1 + '.new')) os.rename(filename1 + ".new", filename2) + self.assertFalse(os.path.isfile(filename1 + '.new')) self.assertTrue(os.path.isfile(filename2)) shutil.copy(filename1, filename2 + ".new") os.unlink(filename1 + ".new") # remove using equiv name. # And a couple of moves, one using each name. shutil.move(filename1, filename2 + ".new") - self.assertTrue(not os.path.exists(filename2)) + self.assertFalse(os.path.exists(filename2)) + self.assertTrue(os.path.exists(filename1 + '.new')) shutil.move(filename1 + ".new", filename2) + self.assertFalse(os.path.exists(filename2 + '.new')) self.assertTrue(os.path.exists(filename1)) # Note - due to the implementation of shutil.move, # it tries a rename first. This only fails on Windows when on @@ -73,7 +77,9 @@ class TestUnicodeFiles(unittest.TestCase): # So we test the shutil.copy2 function, which is the thing most # likely to fail. shutil.copy2(filename1, filename2 + ".new") + self.assertTrue(os.path.isfile(filename1 + '.new')) os.unlink(filename1 + ".new") + self.assertFalse(os.path.exists(filename2 + '.new')) def _do_directory(self, make_name, chdir_name): cwd = os.getcwdb() |
