self.hash_count += 1
return int.__hash__(self)
-class TestJointOps(unittest.TestCase):
+class TestJointOps:
# Tests common to both set and frozenset
def setUp(self):
gc.collect()
self.assertTrue(ref() is None, "Cycle was not collected")
-class TestSet(TestJointOps):
+class TestSet(TestJointOps, unittest.TestCase):
thetype = set
basetype = set
'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
#==============================================================================
-class TestBasicOps(unittest.TestCase):
+class TestBasicOps:
def test_repr(self):
if self.repr is not None:
#------------------------------------------------------------------------------
-class TestBasicOpsEmpty(TestBasicOps):
+class TestBasicOpsEmpty(TestBasicOps, unittest.TestCase):
def setUp(self):
self.case = "empty set"
self.values = []
#------------------------------------------------------------------------------
-class TestBasicOpsSingleton(TestBasicOps):
+class TestBasicOpsSingleton(TestBasicOps, unittest.TestCase):
def setUp(self):
self.case = "unit set (number)"
self.values = [3]
#------------------------------------------------------------------------------
-class TestBasicOpsTuple(TestBasicOps):
+class TestBasicOpsTuple(TestBasicOps, unittest.TestCase):
def setUp(self):
self.case = "unit set (tuple)"
self.values = [(0, "zero")]
#------------------------------------------------------------------------------
-class TestBasicOpsTriple(TestBasicOps):
+class TestBasicOpsTriple(TestBasicOps, unittest.TestCase):
def setUp(self):
self.case = "triple set"
self.values = [0, "zero", operator.add]
#------------------------------------------------------------------------------
-class TestBasicOpsString(TestBasicOps):
+class TestBasicOpsString(TestBasicOps, unittest.TestCase):
def setUp(self):
self.case = "string set"
self.values = ["a", "b", "c"]
#------------------------------------------------------------------------------
-class TestBasicOpsBytes(TestBasicOps):
+class TestBasicOpsBytes(TestBasicOps, unittest.TestCase):
def setUp(self):
self.case = "string set"
self.values = [b"a", b"b", b"c"]
#------------------------------------------------------------------------------
-class TestBasicOpsMixedStringBytes(TestBasicOps):
+class TestBasicOpsMixedStringBytes(TestBasicOps, unittest.TestCase):
def setUp(self):
self._warning_filters = support.check_warnings()
self._warning_filters.__enter__()
#==============================================================================
-class TestSubsets(unittest.TestCase):
+class TestSubsets:
case2method = {"<=": "issubset",
">=": "issuperset",
self.assertEqual(result, expected)
#------------------------------------------------------------------------------
-class TestSubsetEqualEmpty(TestSubsets):
+class TestSubsetEqualEmpty(TestSubsets, unittest.TestCase):
left = set()
right = set()
name = "both empty"
#------------------------------------------------------------------------------
-class TestSubsetEqualNonEmpty(TestSubsets):
+class TestSubsetEqualNonEmpty(TestSubsets, unittest.TestCase):
left = set([1, 2])
right = set([1, 2])
name = "equal pair"
#------------------------------------------------------------------------------
-class TestSubsetEmptyNonEmpty(TestSubsets):
+class TestSubsetEmptyNonEmpty(TestSubsets, unittest.TestCase):
left = set()
right = set([1, 2])
name = "one empty, one non-empty"
#------------------------------------------------------------------------------
-class TestSubsetPartial(TestSubsets):
+class TestSubsetPartial(TestSubsets, unittest.TestCase):
left = set([1])
right = set([1, 2])
name = "one a non-empty proper subset of other"
#------------------------------------------------------------------------------
-class TestSubsetNonOverlap(TestSubsets):
+class TestSubsetNonOverlap(TestSubsets, unittest.TestCase):
left = set([1])
right = set([2])
name = "neither empty, neither contains"
#==============================================================================
-class TestOnlySetsInBinaryOps(unittest.TestCase):
+class TestOnlySetsInBinaryOps:
def test_eq_ne(self):
# Unlike the others, this is testing that == and != *are* allowed.
#------------------------------------------------------------------------------
-class TestOnlySetsNumeric(TestOnlySetsInBinaryOps):
+class TestOnlySetsNumeric(TestOnlySetsInBinaryOps, unittest.TestCase):
def setUp(self):
self.set = set((1, 2, 3))
self.other = 19
#------------------------------------------------------------------------------
-class TestOnlySetsDict(TestOnlySetsInBinaryOps):
+class TestOnlySetsDict(TestOnlySetsInBinaryOps, unittest.TestCase):
def setUp(self):
self.set = set((1, 2, 3))
self.other = {1:2, 3:4}
#------------------------------------------------------------------------------
-class TestOnlySetsOperator(TestOnlySetsInBinaryOps):
+class TestOnlySetsOperator(TestOnlySetsInBinaryOps, unittest.TestCase):
def setUp(self):
self.set = set((1, 2, 3))
self.other = operator.add
#------------------------------------------------------------------------------
-class TestOnlySetsTuple(TestOnlySetsInBinaryOps):
+class TestOnlySetsTuple(TestOnlySetsInBinaryOps, unittest.TestCase):
def setUp(self):
self.set = set((1, 2, 3))
self.other = (2, 4, 6)
#------------------------------------------------------------------------------
-class TestOnlySetsString(TestOnlySetsInBinaryOps):
+class TestOnlySetsString(TestOnlySetsInBinaryOps, unittest.TestCase):
def setUp(self):
self.set = set((1, 2, 3))
self.other = 'abc'
#------------------------------------------------------------------------------
-class TestOnlySetsGenerator(TestOnlySetsInBinaryOps):
+class TestOnlySetsGenerator(TestOnlySetsInBinaryOps, unittest.TestCase):
def setUp(self):
def gen():
for i in range(0, 10, 2):
#==============================================================================
-class TestCopying(unittest.TestCase):
+class TestCopying:
def test_copy(self):
dup = self.set.copy()
#------------------------------------------------------------------------------
-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))])
#==============================================================================
-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()