summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_builtin.py
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2008-01-27 23:50:43 (GMT)
committerChristian Heimes <christian@cheimes.de>2008-01-27 23:50:43 (GMT)
commit26855635833fcd3f15786b4a9d4241ded293404c (patch)
tree37e1984aadfd2e688e7105ce112e3559bf93653e /Lib/test/test_builtin.py
parent7b69c6c3afba79518865313e1b41845a6b534fb6 (diff)
downloadcpython-26855635833fcd3f15786b4a9d4241ded293404c.zip
cpython-26855635833fcd3f15786b4a9d4241ded293404c.tar.gz
cpython-26855635833fcd3f15786b4a9d4241ded293404c.tar.bz2
Merged revisions 60364-60378 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r60364 | neal.norwitz | 2008-01-27 19:09:48 +0100 (Sun, 27 Jan 2008) | 4 lines Update the comment and remove the close. If we close we can't flush anymore. We might still need to close after the for loop if flushing 6! times still doesn't cause the signal/exception. ........ r60365 | georg.brandl | 2008-01-27 19:14:43 +0100 (Sun, 27 Jan 2008) | 2 lines Remove effectless expression statement. ........ r60367 | neal.norwitz | 2008-01-27 19:19:04 +0100 (Sun, 27 Jan 2008) | 1 line Try to handle socket.errors properly in is_unavailable ........ r60370 | christian.heimes | 2008-01-27 20:01:45 +0100 (Sun, 27 Jan 2008) | 1 line Change isbasestring function as discussed on the cvs list a while ago ........ r60372 | neal.norwitz | 2008-01-27 21:03:13 +0100 (Sun, 27 Jan 2008) | 3 lines socket.error doesn't have a headers attribute like ProtocolError. Handle that situation where we catch socket.errors. ........ r60375 | georg.brandl | 2008-01-27 21:25:12 +0100 (Sun, 27 Jan 2008) | 2 lines Add refcounting extension to build config. ........ r60377 | jeffrey.yasskin | 2008-01-28 00:08:46 +0100 (Mon, 28 Jan 2008) | 6 lines Moved Rational._binary_float_to_ratio() to float.as_integer_ratio() because it's useful outside of rational numbers. This is my first C code that had to do anything significant. Please be more careful when looking over it. ........ r60378 | christian.heimes | 2008-01-28 00:34:59 +0100 (Mon, 28 Jan 2008) | 1 line Added clear cache methods to clear the internal type lookup cache for ref leak test runs. ........
Diffstat (limited to 'Lib/test/test_builtin.py')
-rw-r--r--Lib/test/test_builtin.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index e6ded81..92c1d00 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -5,7 +5,7 @@ from test.test_support import fcmp, TESTFN, unlink, run_unittest, \
run_with_locale
from operator import neg
-import sys, warnings, random, UserDict, io
+import sys, warnings, random, UserDict, io, rational
warnings.filterwarnings("ignore", "hex../oct.. of negative int",
FutureWarning, __name__)
warnings.filterwarnings("ignore", "integer argument expected",
@@ -592,6 +592,25 @@ class BuiltinTest(unittest.TestCase):
# make sure we can take a subclass of str as a format spec
self.assertEqual(format(0, C('10')), ' 0')
+ def test_floatasratio(self):
+ R = rational.Rational
+ self.assertEqual(R(0, 1),
+ R(*float(0.0).as_integer_ratio()))
+ self.assertEqual(R(5, 2),
+ R(*float(2.5).as_integer_ratio()))
+ self.assertEqual(R(1, 2),
+ R(*float(0.5).as_integer_ratio()))
+ self.assertEqual(R(4728779608739021, 2251799813685248),
+ R(*float(2.1).as_integer_ratio()))
+ self.assertEqual(R(-4728779608739021, 2251799813685248),
+ R(*float(-2.1).as_integer_ratio()))
+ self.assertEqual(R(-2100, 1),
+ R(*float(-2100.0).as_integer_ratio()))
+
+ self.assertRaises(OverflowError, float('inf').as_integer_ratio)
+ self.assertRaises(OverflowError, float('-inf').as_integer_ratio)
+ self.assertRaises(ValueError, float('nan').as_integer_ratio)
+
def test_getattr(self):
import sys
self.assert_(getattr(sys, 'stdout') is sys.stdout)