summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_rational.py
diff options
context:
space:
mode:
authorJeffrey Yasskin <jyasskin@gmail.com>2008-02-01 07:05:46 (GMT)
committerJeffrey Yasskin <jyasskin@gmail.com>2008-02-01 07:05:46 (GMT)
commitdc2964b0d849389bffde95b8f76fd112049e114f (patch)
tree6b6db21fcc4dbee5a7ea9f87973ea2b694742005 /Lib/test/test_rational.py
parentca2b69f765dd8a7f5c8e5c5346572519a8768ec4 (diff)
downloadcpython-dc2964b0d849389bffde95b8f76fd112049e114f.zip
cpython-dc2964b0d849389bffde95b8f76fd112049e114f.tar.gz
cpython-dc2964b0d849389bffde95b8f76fd112049e114f.tar.bz2
Roll back r60248. It's useful to encourage users not to change Rational
instances.
Diffstat (limited to 'Lib/test/test_rational.py')
-rw-r--r--Lib/test/test_rational.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/test_rational.py b/Lib/test/test_rational.py
index 3c3d1f9..1c37874 100644
--- a/Lib/test/test_rational.py
+++ b/Lib/test/test_rational.py
@@ -119,6 +119,17 @@ class RationalTest(unittest.TestCase):
r.__init__(2, 15)
self.assertEquals((7, 3), _components(r))
+ self.assertRaises(AttributeError, setattr, r, 'numerator', 12)
+ self.assertRaises(AttributeError, setattr, r, 'denominator', 6)
+ self.assertEquals((7, 3), _components(r))
+
+ # But if you _really_ need to:
+ r._numerator = 4
+ r._denominator = 2
+ self.assertEquals((4, 2), _components(r))
+ # Which breaks some important operations:
+ self.assertNotEquals(R(4, 2), r)
+
def testFromFloat(self):
self.assertRaisesMessage(
TypeError, "Rational.from_float() only takes floats, not 3 (int)",