Back to index

python3.2  3.2.2
Public Member Functions
test.test_decimal.DecimalImplicitConstructionTest Class Reference

List of all members.

Public Member Functions

def test_implicit_from_None
def test_implicit_from_int
def test_implicit_from_string
def test_implicit_from_float
def test_implicit_from_Decimal
def test_rop

Detailed Description

Unit tests for Implicit Construction cases of Decimal.

Definition at line 605 of file test_decimal.py.


Member Function Documentation

Definition at line 623 of file test_decimal.py.

00623 
00624     def test_implicit_from_Decimal(self):
00625         self.assertEqual(Decimal(5) + Decimal(45), Decimal(50))

Here is the call graph for this function:

Definition at line 620 of file test_decimal.py.

00620 
00621     def test_implicit_from_float(self):
00622         self.assertRaises(TypeError, eval, 'Decimal(5) + 2.2', globals())

Here is the call graph for this function:

Definition at line 611 of file test_decimal.py.

00611 
00612     def test_implicit_from_int(self):
00613         #normal
00614         self.assertEqual(str(Decimal(5) + 45), '50')
00615         #exceeding precision
00616         self.assertEqual(Decimal(5) + 123456789000, Decimal(123456789000))

Here is the call graph for this function:

Definition at line 608 of file test_decimal.py.

00608 
00609     def test_implicit_from_None(self):
00610         self.assertRaises(TypeError, eval, 'Decimal(5) + None', globals())

Here is the call graph for this function:

Definition at line 617 of file test_decimal.py.

00617 
00618     def test_implicit_from_string(self):
00619         self.assertRaises(TypeError, eval, 'Decimal(5) + "3"', globals())

Here is the call graph for this function:

Definition at line 626 of file test_decimal.py.

00626 
00627     def test_rop(self):
00628         # Allow other classes to be trained to interact with Decimals
00629         class E:
00630             def __divmod__(self, other):
00631                 return 'divmod ' + str(other)
00632             def __rdivmod__(self, other):
00633                 return str(other) + ' rdivmod'
00634             def __lt__(self, other):
00635                 return 'lt ' + str(other)
00636             def __gt__(self, other):
00637                 return 'gt ' + str(other)
00638             def __le__(self, other):
00639                 return 'le ' + str(other)
00640             def __ge__(self, other):
00641                 return 'ge ' + str(other)
00642             def __eq__(self, other):
00643                 return 'eq ' + str(other)
00644             def __ne__(self, other):
00645                 return 'ne ' + str(other)
00646 
00647         self.assertEqual(divmod(E(), Decimal(10)), 'divmod 10')
00648         self.assertEqual(divmod(Decimal(10), E()), '10 rdivmod')
00649         self.assertEqual(eval('Decimal(10) < E()'), 'gt 10')
00650         self.assertEqual(eval('Decimal(10) > E()'), 'lt 10')
00651         self.assertEqual(eval('Decimal(10) <= E()'), 'ge 10')
00652         self.assertEqual(eval('Decimal(10) >= E()'), 'le 10')
00653         self.assertEqual(eval('Decimal(10) == E()'), 'eq 10')
00654         self.assertEqual(eval('Decimal(10) != E()'), 'ne 10')
00655 
00656         # insert operator methods and then exercise them
00657         oplist = [
00658             ('+', '__add__', '__radd__'),
00659             ('-', '__sub__', '__rsub__'),
00660             ('*', '__mul__', '__rmul__'),
00661             ('/', '__truediv__', '__rtruediv__'),
00662             ('%', '__mod__', '__rmod__'),
00663             ('//', '__floordiv__', '__rfloordiv__'),
00664             ('**', '__pow__', '__rpow__')
00665         ]
00666 
00667         for sym, lop, rop in oplist:
00668             setattr(E, lop, lambda self, other: 'str' + lop + str(other))
00669             setattr(E, rop, lambda self, other: str(other) + rop + 'str')
00670             self.assertEqual(eval('E()' + sym + 'Decimal(10)'),
00671                              'str' + lop + '10')
00672             self.assertEqual(eval('Decimal(10)' + sym + 'E()'),
00673                              '10' + rop + 'str')
00674 

Here is the call graph for this function:


The documentation for this class was generated from the following file: