From ab5ba7918e07e5f3a7c51119e23803c755534a0d Mon Sep 17 00:00:00 2001 From: Ezio Melotti Date: Fri, 19 Apr 2013 05:58:44 +0300 Subject: [PATCH] #17790: test_set now works with unittest test discovery. Patch by Zachary Ware. --- Lib/test/test_set.py | 115 ++++++++++++------------------------------- Misc/NEWS | 3 ++ 2 files changed, 34 insertions(+), 84 deletions(-) diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py index 8e9e5878b25..8f861568a46 100644 --- a/Lib/test/test_set.py +++ b/Lib/test/test_set.py @@ -37,7 +37,7 @@ class HashCountingInt(int): self.hash_count += 1 return int.__hash__(self) -class TestJointOps(unittest.TestCase): +class TestJointOps: # Tests common to both set and frozenset def setUp(self): @@ -361,7 +361,7 @@ class TestJointOps(unittest.TestCase): gc.collect() self.assertTrue(ref() is None, "Cycle was not collected") -class TestSet(TestJointOps): +class TestSet(TestJointOps, unittest.TestCase): thetype = set basetype = set @@ -647,7 +647,7 @@ class TestSetSubclassWithKeywordArgs(TestSet): 'SF bug #1486663 -- this used to erroneously raise a TypeError' SetSubclassWithKeywordArgs(newarg=1) -class TestFrozenSet(TestJointOps): +class TestFrozenSet(TestJointOps, unittest.TestCase): thetype = frozenset basetype = frozenset @@ -748,7 +748,7 @@ empty_set = set() #============================================================================== -class TestBasicOps(unittest.TestCase): +class TestBasicOps: def test_repr(self): if self.repr is not None: @@ -860,7 +860,7 @@ class TestBasicOps(unittest.TestCase): #------------------------------------------------------------------------------ -class TestBasicOpsEmpty(TestBasicOps): +class TestBasicOpsEmpty(TestBasicOps, unittest.TestCase): def setUp(self): self.case = "empty set" self.values = [] @@ -871,7 +871,7 @@ class TestBasicOpsEmpty(TestBasicOps): #------------------------------------------------------------------------------ -class TestBasicOpsSingleton(TestBasicOps): +class TestBasicOpsSingleton(TestBasicOps, unittest.TestCase): def setUp(self): self.case = "unit set (number)" self.values = [3] @@ -888,7 +888,7 @@ class TestBasicOpsSingleton(TestBasicOps): #------------------------------------------------------------------------------ -class TestBasicOpsTuple(TestBasicOps): +class TestBasicOpsTuple(TestBasicOps, unittest.TestCase): def setUp(self): self.case = "unit set (tuple)" self.values = [(0, "zero")] @@ -905,7 +905,7 @@ class TestBasicOpsTuple(TestBasicOps): #------------------------------------------------------------------------------ -class TestBasicOpsTriple(TestBasicOps): +class TestBasicOpsTriple(TestBasicOps, unittest.TestCase): def setUp(self): self.case = "triple set" self.values = [0, "zero", operator.add] @@ -916,7 +916,7 @@ class TestBasicOpsTriple(TestBasicOps): #------------------------------------------------------------------------------ -class TestBasicOpsString(TestBasicOps): +class TestBasicOpsString(TestBasicOps, unittest.TestCase): def setUp(self): self.case = "string set" self.values = ["a", "b", "c"] @@ -929,7 +929,7 @@ class TestBasicOpsString(TestBasicOps): #------------------------------------------------------------------------------ -class TestBasicOpsBytes(TestBasicOps): +class TestBasicOpsBytes(TestBasicOps, unittest.TestCase): def setUp(self): self.case = "string set" self.values = [b"a", b"b", b"c"] @@ -942,7 +942,7 @@ class TestBasicOpsBytes(TestBasicOps): #------------------------------------------------------------------------------ -class TestBasicOpsMixedStringBytes(TestBasicOps): +class TestBasicOpsMixedStringBytes(TestBasicOps, unittest.TestCase): def setUp(self): self._warning_filters = support.check_warnings() self._warning_filters.__enter__() @@ -1241,7 +1241,7 @@ class TestMutate(unittest.TestCase): #============================================================================== -class TestSubsets(unittest.TestCase): +class TestSubsets: case2method = {"<=": "issubset", ">=": "issuperset", @@ -1279,7 +1279,7 @@ class TestSubsets(unittest.TestCase): self.assertEqual(result, expected) #------------------------------------------------------------------------------ -class TestSubsetEqualEmpty(TestSubsets): +class TestSubsetEqualEmpty(TestSubsets, unittest.TestCase): left = set() right = set() name = "both empty" @@ -1287,7 +1287,7 @@ class TestSubsetEqualEmpty(TestSubsets): #------------------------------------------------------------------------------ -class TestSubsetEqualNonEmpty(TestSubsets): +class TestSubsetEqualNonEmpty(TestSubsets, unittest.TestCase): left = set([1, 2]) right = set([1, 2]) name = "equal pair" @@ -1295,7 +1295,7 @@ class TestSubsetEqualNonEmpty(TestSubsets): #------------------------------------------------------------------------------ -class TestSubsetEmptyNonEmpty(TestSubsets): +class TestSubsetEmptyNonEmpty(TestSubsets, unittest.TestCase): left = set() right = set([1, 2]) name = "one empty, one non-empty" @@ -1303,7 +1303,7 @@ class TestSubsetEmptyNonEmpty(TestSubsets): #------------------------------------------------------------------------------ -class TestSubsetPartial(TestSubsets): +class TestSubsetPartial(TestSubsets, unittest.TestCase): left = set([1]) right = set([1, 2]) name = "one a non-empty proper subset of other" @@ -1311,7 +1311,7 @@ class TestSubsetPartial(TestSubsets): #------------------------------------------------------------------------------ -class TestSubsetNonOverlap(TestSubsets): +class TestSubsetNonOverlap(TestSubsets, unittest.TestCase): left = set([1]) right = set([2]) name = "neither empty, neither contains" @@ -1319,7 +1319,7 @@ class TestSubsetNonOverlap(TestSubsets): #============================================================================== -class TestOnlySetsInBinaryOps(unittest.TestCase): +class TestOnlySetsInBinaryOps: def test_eq_ne(self): # Unlike the others, this is testing that == and != *are* allowed. @@ -1435,7 +1435,7 @@ class TestOnlySetsInBinaryOps(unittest.TestCase): #------------------------------------------------------------------------------ -class TestOnlySetsNumeric(TestOnlySetsInBinaryOps): +class TestOnlySetsNumeric(TestOnlySetsInBinaryOps, unittest.TestCase): def setUp(self): self.set = set((1, 2, 3)) self.other = 19 @@ -1443,7 +1443,7 @@ class TestOnlySetsNumeric(TestOnlySetsInBinaryOps): #------------------------------------------------------------------------------ -class TestOnlySetsDict(TestOnlySetsInBinaryOps): +class TestOnlySetsDict(TestOnlySetsInBinaryOps, unittest.TestCase): def setUp(self): self.set = set((1, 2, 3)) self.other = {1:2, 3:4} @@ -1451,7 +1451,7 @@ class TestOnlySetsDict(TestOnlySetsInBinaryOps): #------------------------------------------------------------------------------ -class TestOnlySetsOperator(TestOnlySetsInBinaryOps): +class TestOnlySetsOperator(TestOnlySetsInBinaryOps, unittest.TestCase): def setUp(self): self.set = set((1, 2, 3)) self.other = operator.add @@ -1459,7 +1459,7 @@ class TestOnlySetsOperator(TestOnlySetsInBinaryOps): #------------------------------------------------------------------------------ -class TestOnlySetsTuple(TestOnlySetsInBinaryOps): +class TestOnlySetsTuple(TestOnlySetsInBinaryOps, unittest.TestCase): def setUp(self): self.set = set((1, 2, 3)) self.other = (2, 4, 6) @@ -1467,7 +1467,7 @@ class TestOnlySetsTuple(TestOnlySetsInBinaryOps): #------------------------------------------------------------------------------ -class TestOnlySetsString(TestOnlySetsInBinaryOps): +class TestOnlySetsString(TestOnlySetsInBinaryOps, unittest.TestCase): def setUp(self): self.set = set((1, 2, 3)) self.other = 'abc' @@ -1475,7 +1475,7 @@ class TestOnlySetsString(TestOnlySetsInBinaryOps): #------------------------------------------------------------------------------ -class TestOnlySetsGenerator(TestOnlySetsInBinaryOps): +class TestOnlySetsGenerator(TestOnlySetsInBinaryOps, unittest.TestCase): def setUp(self): def gen(): for i in range(0, 10, 2): @@ -1486,7 +1486,7 @@ class TestOnlySetsGenerator(TestOnlySetsInBinaryOps): #============================================================================== -class TestCopying(unittest.TestCase): +class TestCopying: def test_copy(self): dup = self.set.copy() @@ -1507,31 +1507,31 @@ class TestCopying(unittest.TestCase): #------------------------------------------------------------------------------ -class TestCopyingEmpty(TestCopying): +class TestCopyingEmpty(TestCopying, unittest.TestCase): def setUp(self): self.set = set() #------------------------------------------------------------------------------ -class TestCopyingSingleton(TestCopying): +class TestCopyingSingleton(TestCopying, unittest.TestCase): def setUp(self): self.set = set(["hello"]) #------------------------------------------------------------------------------ -class TestCopyingTriple(TestCopying): +class TestCopyingTriple(TestCopying, unittest.TestCase): def setUp(self): self.set = set(["zero", 0, None]) #------------------------------------------------------------------------------ -class TestCopyingTuple(TestCopying): +class TestCopyingTuple(TestCopying, unittest.TestCase): def setUp(self): self.set = set([(1, 2)]) #------------------------------------------------------------------------------ -class TestCopyingNested(TestCopying): +class TestCopyingNested(TestCopying, unittest.TestCase): def setUp(self): self.set = set([((1, 2), (3, 4))]) @@ -1837,58 +1837,5 @@ class TestGraphs(unittest.TestCase): #============================================================================== -def test_main(verbose=None): - test_classes = ( - TestSet, - TestSetSubclass, - TestSetSubclassWithKeywordArgs, - TestFrozenSet, - TestFrozenSetSubclass, - TestSetOfSets, - TestExceptionPropagation, - TestBasicOpsEmpty, - TestBasicOpsSingleton, - TestBasicOpsTuple, - TestBasicOpsTriple, - TestBasicOpsString, - TestBasicOpsBytes, - TestBasicOpsMixedStringBytes, - TestBinaryOps, - TestUpdateOps, - TestMutate, - TestSubsetEqualEmpty, - TestSubsetEqualNonEmpty, - TestSubsetEmptyNonEmpty, - TestSubsetPartial, - TestSubsetNonOverlap, - TestOnlySetsNumeric, - TestOnlySetsDict, - TestOnlySetsOperator, - TestOnlySetsTuple, - TestOnlySetsString, - TestOnlySetsGenerator, - TestCopyingEmpty, - TestCopyingSingleton, - TestCopyingTriple, - TestCopyingTuple, - TestCopyingNested, - TestIdentities, - TestVariousIteratorArgs, - TestGraphs, - TestWeirdBugs, - ) - - support.run_unittest(*test_classes) - - # verify reference counting - if verbose and hasattr(sys, "gettotalrefcount"): - import gc - counts = [None] * 5 - for i in range(len(counts)): - support.run_unittest(*test_classes) - gc.collect() - counts[i] = sys.gettotalrefcount() - print(counts) - if __name__ == "__main__": - test_main(verbose=True) + unittest.main() diff --git a/Misc/NEWS b/Misc/NEWS index 660e0719b37..a67ce0becb6 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -120,6 +120,9 @@ Tests - Issue #12820: add tests for the xml.dom.minicompat module. Patch by John Chandler and Phil Connell. +- Issue #17790: test_set now works with unittest test discovery. + Patch by Zachary Ware. + - Issue #17789: test_random now works with unittest test discovery. Patch by Zachary Ware.