diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py --- a/Lib/test/test_int.py +++ b/Lib/test/test_int.py @@ -45,6 +45,26 @@ (unichr(0x200), ValueError), ] +class SharedTestCaseMixin(object): + + """Test cases shared between test_int and test_long.""" + + # Change to int or long in the TestCase subclass. + ntype = None + + def test_no_args(self): + self.assertEquals(self.ntype(), 0) + + def test_keyword_args(self): + # Test invoking int() using keyword arguments. + self.assertEquals(self.ntype(x=1.2), 1) + self.assertEquals(self.ntype('100', base=2), 4) + self.assertEquals(self.ntype(x='100', base=2), 4) + +class IntSharedTestCases(SharedTestCaseMixin, unittest.TestCase): + + ntype = int + class IntTestCases(unittest.TestCase): def test_basic(self): @@ -316,15 +336,6 @@ self.assertEqual(int(float(2**54+10)), 2**54+8) self.assertEqual(int(float(2**54+11)), 2**54+12) - def test_no_args(self): - self.assertEquals(int(), 0) - - def test_keyword_args(self): - # Test invoking int() using keyword arguments. - self.assertEquals(int(x=1.2), 1) - self.assertEquals(int('100', base=2), 4) - self.assertEquals(int(x='100', base=2), 4) - def test_valid_non_numeric_input_types_for_x(self): # Test possible valid non-numeric types for x, including subclasses # of the allowed built-in types. @@ -454,7 +465,7 @@ ((base, trunc_result_base),)) def test_main(): - run_unittest(IntTestCases) + run_unittest(__name__) if __name__ == "__main__": test_main() diff --git a/Lib/test/test_long.py b/Lib/test/test_long.py --- a/Lib/test/test_long.py +++ b/Lib/test/test_long.py @@ -1,10 +1,11 @@ import unittest -from test import test_support import sys import random import math +from test import test_int, test_support + # Used for lazy formatting of failure messages class Frm(object): def __init__(self, format, *args): @@ -78,6 +79,9 @@ (unichr(0x200), ValueError), ] +class LongSharedTestCases(test_int.SharedTestCaseMixin, unittest.TestCase): + + ntype = long class LongTest(unittest.TestCase): @@ -908,7 +912,7 @@ def test_main(): - test_support.run_unittest(LongTest) + test_support.run_unittest(__name__) if __name__ == "__main__": test_main()