MCPcopy Index your code
hub / github.com/python/cpython / testImmutable

Method testImmutable

Lib/test/test_fractions.py:521–535  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

519 self.assertRaisesRegex(ValueError, msg, F, '1.1e' + '0' * (maxdigits+1))
520
521 def testImmutable(self):
522 r = F(7, 3)
523 r.__init__(2, 15)
524 self.assertEqual((7, 3), _components(r))
525
526 self.assertRaises(AttributeError, setattr, r, 'numerator', 12)
527 self.assertRaises(AttributeError, setattr, r, 'denominator', 6)
528 self.assertEqual((7, 3), _components(r))
529
530 # But if you _really_ need to:
531 r._numerator = 4
532 r._denominator = 2
533 self.assertEqual((4, 2), _components(r))
534 # Which breaks some important operations:
535 self.assertNotEqual(F(4, 2), r)
536
537 def testFromFloat(self):
538 self.assertRaises(TypeError, F.from_float, 3+4j)

Callers

nothing calls this directly

Calls 6

__init__Method · 0.95
_componentsFunction · 0.85
assertNotEqualMethod · 0.80
FClass · 0.70
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected