]> granicus.if.org Git - python/commitdiff
Issue #16790: add some of the recent issue #16045 int tests to test_long.
authorChris Jerdonek <chris.jerdonek@gmail.com>
Thu, 27 Dec 2012 20:53:29 +0000 (12:53 -0800)
committerChris Jerdonek <chris.jerdonek@gmail.com>
Thu, 27 Dec 2012 20:53:29 +0000 (12:53 -0800)
This patch also provides a simple way to share tests going forward
between test_int and test_long.

Lib/test/test_int.py
Lib/test/test_long.py

index 88627017e5b5c5955e2a913af98d4b9d5d48a6ca..045ef7c76adc86322be6b53859f9f3016ec2e988 100644 (file)
@@ -45,7 +45,25 @@ if have_unicode:
         (unichr(0x200), ValueError),
 ]
 
-class IntTestCases(unittest.TestCase):
+class IntLongCommonTests(object):
+
+    """Mixin of test cases to share between both test_int and test_long."""
+
+    # Change to int or long in the TestCase subclass.
+    ntype = None
+
+    def test_no_args(self):
+        self.assertEqual(self.ntype(), 0)
+
+    def test_keyword_args(self):
+        # Test invoking constructor using keyword arguments.
+        self.assertEqual(self.ntype(x=1.2), 1)
+        self.assertEqual(self.ntype('100', base=2), 4)
+        self.assertEqual(self.ntype(x='100', base=2), 4)
+
+class IntTestCases(IntLongCommonTests, unittest.TestCase):
+
+    ntype = int
 
     def test_basic(self):
         self.assertEqual(int(314), 314)
@@ -316,15 +334,6 @@ class IntTestCases(unittest.TestCase):
         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.
index 58cfc3a2a334da26180fb8d8bff97b6368b39a79..f0847e7ab4374b95d46b828ac7dae5b740ce36f7 100644 (file)
@@ -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,8 +79,9 @@ if test_support.have_unicode:
         (unichr(0x200), ValueError),
 ]
 
+class LongTest(test_int.IntLongCommonTests, unittest.TestCase):
 
-class LongTest(unittest.TestCase):
+    ntype = long
 
     # Get quasi-random long consisting of ndigits digits (in base BASE).
     # quasi == the most-significant digit will not be 0, and the number