summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_fractions.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_fractions.py')
-rw-r--r--Lib/test/test_fractions.py33
1 files changed, 22 insertions, 11 deletions
diff --git a/Lib/test/test_fractions.py b/Lib/test/test_fractions.py
index 2dd528f..1699852 100644
--- a/Lib/test/test_fractions.py
+++ b/Lib/test/test_fractions.py
@@ -8,6 +8,7 @@ import operator
import fractions
import sys
import unittest
+import warnings
from copy import copy, deepcopy
from pickle import dumps, loads
F = fractions.Fraction
@@ -49,7 +50,7 @@ class DummyRational(object):
"""Test comparison of Fraction with a naive rational implementation."""
def __init__(self, num, den):
- g = gcd(num, den)
+ g = math.gcd(num, den)
self.num = num // g
self.den = den // g
@@ -83,16 +84,26 @@ class DummyFraction(fractions.Fraction):
class GcdTest(unittest.TestCase):
def testMisc(self):
- self.assertEqual(0, gcd(0, 0))
- self.assertEqual(1, gcd(1, 0))
- self.assertEqual(-1, gcd(-1, 0))
- self.assertEqual(1, gcd(0, 1))
- self.assertEqual(-1, gcd(0, -1))
- self.assertEqual(1, gcd(7, 1))
- self.assertEqual(-1, gcd(7, -1))
- self.assertEqual(1, gcd(-23, 15))
- self.assertEqual(12, gcd(120, 84))
- self.assertEqual(-12, gcd(84, -120))
+ # fractions.gcd() is deprecated
+ with self.assertWarnsRegex(DeprecationWarning, r'fractions\.gcd'):
+ gcd(1, 1)
+ with warnings.catch_warnings():
+ warnings.filterwarnings('ignore', r'fractions\.gcd',
+ DeprecationWarning)
+ self.assertEqual(0, gcd(0, 0))
+ self.assertEqual(1, gcd(1, 0))
+ self.assertEqual(-1, gcd(-1, 0))
+ self.assertEqual(1, gcd(0, 1))
+ self.assertEqual(-1, gcd(0, -1))
+ self.assertEqual(1, gcd(7, 1))
+ self.assertEqual(-1, gcd(7, -1))
+ self.assertEqual(1, gcd(-23, 15))
+ self.assertEqual(12, gcd(120, 84))
+ self.assertEqual(-12, gcd(84, -120))
+ self.assertEqual(gcd(120.0, 84), 12.0)
+ self.assertEqual(gcd(120, 84.0), 12.0)
+ self.assertEqual(gcd(F(120), F(84)), F(12))
+ self.assertEqual(gcd(F(120, 77), F(84, 55)), F(12, 385))
def _components(r):