cpython: 81fa901162f9 (original) (raw)

--- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -1,18 +1,21 @@ """Unit tests for collections.py.""" -import unittest, doctest, operator -from test.support import TESTFN, forget, unlink, import_fresh_module -import contextlib +import collections +import copy +import doctest import inspect +import keyword +import operator +import pickle +from random import choice, randrange +import re +import string +import sys from test import support +import types +import unittest + from collections import namedtuple, Counter, OrderedDict, _count_elements -from test import mapping_tests -import pickle, copy -from random import randrange, shuffle -import keyword -import re -import sys -import types from collections import UserDict, UserString, UserList from collections import ChainMap from collections import deque @@ -313,8 +316,7 @@ class TestNamedTuple(unittest.TestCase): # n = 5000 n = 254 # SyntaxError: more than 255 arguments:

@@ -1621,702 +1623,13 @@ class TestCounter(unittest.TestCase): ################################################################################ -### OrderedDict -################################################################################ - -py_coll = import_fresh_module('collections', blocked=['_collections']) -c_coll = import_fresh_module('collections', fresh=['_collections']) - - -@contextlib.contextmanager -def replaced_module(name, replacement):

- - -class OrderedDictTests: -

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

- - -class PurePythonOrderedDictTests(OrderedDictTests, unittest.TestCase): -

- - -@unittest.skipUnless(c_coll, 'requires the C version of the collections module') -class CPythonOrderedDictTests(OrderedDictTests, unittest.TestCase): -

-

-

- - -class PurePythonOrderedDictSubclassTests(PurePythonOrderedDictTests): -

- - -class CPythonOrderedDictSubclassTests(CPythonOrderedDictTests): -

- - -class PurePythonGeneralMappingTests(mapping_tests.BasicTestMappingProtocol): -

-

- - -@unittest.skipUnless(c_coll, 'requires the C version of the collections module') -class CPythonGeneralMappingTests(mapping_tests.BasicTestMappingProtocol): -

-

- - -class PurePythonSubclassMappingTests(mapping_tests.BasicTestMappingProtocol): -

-

- - -@unittest.skipUnless(c_coll, 'requires the C version of the collections module') -class CPythonSubclassMappingTests(mapping_tests.BasicTestMappingProtocol): -

-

- - -################################################################################

Run tests

################################################################################ -import doctest, collections - def test_main(verbose=None): NamedTupleDocs = doctest.DocTestSuite(module=collections) test_classes = [TestNamedTuple, NamedTupleDocs, TestOneTrickPonyABCs, TestCollectionABCs, TestCounter, TestChainMap,

copy from Lib/test/test_collections.py copy to Lib/test/test_ordered_dict.py --- a/Lib/test/test_collections.py +++ b/Lib/test/test_ordered_dict.py @@ -1,1631 +1,15 @@ -"""Unit tests for collections.py.""" - -import unittest, doctest, operator -from test.support import TESTFN, forget, unlink, import_fresh_module import contextlib -import inspect -from test import support -from collections import namedtuple, Counter, OrderedDict, _count_elements -from test import mapping_tests -import pickle, copy +import copy +import pickle from random import randrange, shuffle -import keyword -import re import sys -import types -from collections import UserDict, UserString, UserList -from collections import ChainMap -from collections import deque -from collections.abc import Awaitable, Coroutine, AsyncIterator, AsyncIterable -from collections.abc import Hashable, Iterable, Iterator, Generator -from collections.abc import Sized, Container, Callable -from collections.abc import Set, MutableSet -from collections.abc import Mapping, MutableMapping, KeysView, ItemsView -from collections.abc import Sequence, MutableSequence -from collections.abc import ByteString - - -class TestUserObjects(unittest.TestCase):

-

-

- - -################################################################################ -### ChainMap (helper class for configparser and the string module) -################################################################################ - -class TestChainMap(unittest.TestCase): -

-

-

-

-

-

-

-

-

-

-

-

- - -################################################################################ -### Named Tuples -################################################################################ - -TestNT = namedtuple('TestNT', 'x y z') # type used for pickle tests - -class TestNamedTuple(unittest.TestCase): -

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

- -

-

-

+import unittest +from collections.abc import MutableMapping +from test import mapping_tests, support -################################################################################ -### Abstract Base Classes -################################################################################ - -class ABCTestCase(unittest.TestCase): -

-

-

-

-

-

-

-

-

- -class TestOneTrickPonyABCs(ABCTestCase): -

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

- -class WithSet(MutableSet): -

-

-

-

-

-

- -class TestCollectionABCs(ABCTestCase): -

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

- -################################################################################ -### Counter -################################################################################ - -class CounterSubclassWithSetItem(Counter):

- -class CounterSubclassWithGet(Counter):

- -class TestCounter(unittest.TestCase): -

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

- - -################################################################################ -### OrderedDict -################################################################################ - -py_coll = import_fresh_module('collections', blocked=['_collections']) -c_coll = import_fresh_module('collections', fresh=['_collections']) +py_coll = support.import_fresh_module('collections', blocked=['_collections']) +c_coll = support.import_fresh_module('collections', fresh=['_collections']) @contextlib.contextmanager @@ -2203,6 +587,7 @@ class OrderedDictTests: self.assertNotIn('NULL', repr(od)) def test_dict_update(self):

@@ -2302,26 +687,5 @@ class CPythonSubclassMappingTests(mappin self.assertRaises(KeyError, d.popitem) -################################################################################ -### Run tests -################################################################################ - -import doctest, collections - -def test_main(verbose=None):

- - if name == "main":

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -419,6 +419,9 @@ Documentation Tests ----- +- Issue #25616: Tests for OrderedDict are extracted from test_collections