def testFromDecimal(self):
    self.assertRaises(TypeError, F.from_decimal, (3 + 4j))
    self.assertEqual(F(10, 1), F.from_decimal(10))
    self.assertEqual(F(0), F.from_decimal(Decimal('-0')))
    self.assertEqual(F(5, 10), F.from_decimal(Decimal('0.5')))
    self.assertEqual(F(5, 1000), F.from_decimal(Decimal('5e-3')))
    self.assertEqual(F(5000), F.from_decimal(Decimal('5e3')))
    self.assertEqual((1 - F(1, (10 ** 30))), F.from_decimal(Decimal(('0.' + ('9' * 30)))))
    self.assertRaisesMessage(OverflowError, 'cannot convert Infinity to integer ratio', F.from_decimal, Decimal('inf'))
    self.assertRaisesMessage(OverflowError, 'cannot convert Infinity to integer ratio', F.from_decimal, Decimal('-inf'))
    self.assertRaisesMessage(ValueError, 'cannot convert NaN to integer ratio', F.from_decimal, Decimal('nan'))
    self.assertRaisesMessage(ValueError, 'cannot convert NaN to integer ratio', F.from_decimal, Decimal('snan'))
def testFromDecimal(self):
    self.assertRaises(TypeError, F.from_decimal, (3 + 4j))
    self.assertEqual(F(10, 1), F.from_decimal(10))
    self.assertEqual(F(0), F.from_decimal(Decimal('-0')))
    self.assertEqual(F(5, 10), F.from_decimal(Decimal('0.5')))
    self.assertEqual(F(5, 1000), F.from_decimal(Decimal('5e-3')))
    self.assertEqual(F(5000), F.from_decimal(Decimal('5e3')))
    self.assertEqual((1 - F(1, (10 ** 30))), F.from_decimal(Decimal(('0.' + ('9' * 30)))))
    self.assertRaisesMessage(OverflowError, 'cannot convert Infinity to integer ratio', F.from_decimal, Decimal('inf'))
    self.assertRaisesMessage(OverflowError, 'cannot convert Infinity to integer ratio', F.from_decimal, Decimal('-inf'))
    self.assertRaisesMessage(ValueError, 'cannot convert NaN to integer ratio', F.from_decimal, Decimal('nan'))
    self.assertRaisesMessage(ValueError, 'cannot convert NaN to integer ratio', F.from_decimal, Decimal('snan'))