#17790: test_set now works with unittest test discovery. Patch by Zachary Ware.
diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py
index 8e9e587..8f86156 100644
--- a/Lib/test/test_set.py
+++ b/Lib/test/test_set.py
@@ -37,7 +37,7 @@
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 @@
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 @@
'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 @@
#==============================================================================
-class TestBasicOps(unittest.TestCase):
+class TestBasicOps:
def test_repr(self):
if self.repr is not None:
@@ -860,7 +860,7 @@
#------------------------------------------------------------------------------
-class TestBasicOpsEmpty(TestBasicOps):
+class TestBasicOpsEmpty(TestBasicOps, unittest.TestCase):
def setUp(self):
self.case = "empty set"
self.values = []
@@ -871,7 +871,7 @@
#------------------------------------------------------------------------------
-class TestBasicOpsSingleton(TestBasicOps):
+class TestBasicOpsSingleton(TestBasicOps, unittest.TestCase):
def setUp(self):
self.case = "unit set (number)"
self.values = [3]
@@ -888,7 +888,7 @@
#------------------------------------------------------------------------------
-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 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 TestBasicOpsString(TestBasicOps):
+class TestBasicOpsString(TestBasicOps, unittest.TestCase):
def setUp(self):
self.case = "string set"
self.values = ["a", "b", "c"]
@@ -929,7 +929,7 @@
#------------------------------------------------------------------------------
-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 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 TestSubsets(unittest.TestCase):
+class TestSubsets:
case2method = {"<=": "issubset",
">=": "issuperset",
@@ -1279,7 +1279,7 @@
self.assertEqual(result, expected)
#------------------------------------------------------------------------------
-class TestSubsetEqualEmpty(TestSubsets):
+class TestSubsetEqualEmpty(TestSubsets, unittest.TestCase):
left = set()
right = set()
name = "both empty"
@@ -1287,7 +1287,7 @@
#------------------------------------------------------------------------------
-class TestSubsetEqualNonEmpty(TestSubsets):
+class TestSubsetEqualNonEmpty(TestSubsets, unittest.TestCase):
left = set([1, 2])
right = set([1, 2])
name = "equal pair"
@@ -1295,7 +1295,7 @@
#------------------------------------------------------------------------------
-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 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 TestSubsetNonOverlap(TestSubsets):
+class TestSubsetNonOverlap(TestSubsets, unittest.TestCase):
left = set([1])
right = set([2])
name = "neither empty, neither contains"
@@ -1319,7 +1319,7 @@
#==============================================================================
-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 TestOnlySetsNumeric(TestOnlySetsInBinaryOps):
+class TestOnlySetsNumeric(TestOnlySetsInBinaryOps, unittest.TestCase):
def setUp(self):
self.set = set((1, 2, 3))
self.other = 19
@@ -1443,7 +1443,7 @@
#------------------------------------------------------------------------------
-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 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 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 TestOnlySetsString(TestOnlySetsInBinaryOps):
+class TestOnlySetsString(TestOnlySetsInBinaryOps, unittest.TestCase):
def setUp(self):
self.set = set((1, 2, 3))
self.other = 'abc'
@@ -1475,7 +1475,7 @@
#------------------------------------------------------------------------------
-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 TestCopying(unittest.TestCase):
+class TestCopying:
def test_copy(self):
dup = self.set.copy()
@@ -1507,31 +1507,31 @@
#------------------------------------------------------------------------------
-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 @@
#==============================================================================
-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()