def test_from_string__with_everything(self): pos = from_string( '20 HOOL {532.43 # 20.00 USD, "e4dc1a361022", 2014-06-15}') cost = Cost(D('533.43'), 'USD', datetime.date(2014, 6, 15), "e4dc1a361022") self.assertEqual(Position(A("20 HOOL"), cost), pos)
def test_constructors(self): Position(A('123.45 USD'), None) Position(A('123.45 USD'), Cost('74.00', 'CAD', None, None)) Position(A('123.45 USD'), Cost('74.00', 'CAD', date(2013, 2, 3), None)) Position(Amount(D('123.45'), None), None) Position(Amount(None, 'USD'), None)
def test_from_string__with_compound_cost(self): pos = from_string('1.1 HOOL {500.00 # 11.00 USD}') self.assertEqual( Position(A("1.1 HOOL"), Cost(D('510.00'), 'USD', None, None)), pos)
def test_from_string__with_label(self): pos = from_string('2.2 HOOL {"78c3f7f1315b"}') self.assertEqual( Position(A("2.2 HOOL"), Cost(None, None, None, "78c3f7f1315b")), pos)
def test_from_string__with_cost_and_date(self): pos = from_string('2.2 HOOL {532.43 USD, 2014-06-15}') cost = Cost(D('532.43'), 'USD', datetime.date(2014, 6, 15), None) self.assertEqual(Position(A("2.2 HOOL"), cost), pos)
def test_precision(self): # Some display context. dcontext = display_context.DisplayContext() dcontext.update(D('111'), 'JPY') dcontext.update(D('1.111'), 'RGAGX') dcontext.update(D('1.11'), 'USD') dformat = dcontext.build() # Input data. itypes = [('number', Decimal), ('amount', amount.Amount), ('position', position.Position), ('inventory', inventory.Inventory)] irows = [[ D(amt.split()[0]), A(amt), position.from_string(amt), inventory.from_string(amt) ] for amt in [ '123.45678909876 JPY', '1.67321232123 RGAGX', '5.67345434543 USD' ]] # First check with no explicit quantization. atypes, arows = numberify.numberify_results(itypes, irows) erows = [[ D('123.45678909876'), None, None, D('123.45678909876'), None, None, D('123.45678909876'), None, None, D('123.45678909876') ], [ D('1.67321232123'), None, D('1.67321232123'), None, None, D('1.67321232123'), None, None, D('1.67321232123'), None ], [ D('5.67345434543'), D('5.67345434543'), None, None, D('5.67345434543'), None, None, D('5.67345434543'), None, None ]] self.assertEqual(erows, arows) # Then compare with quantization. atypes, arows = numberify.numberify_results(itypes, irows, dformat) erows = [[ D('123.45678909876'), None, None, D('123'), None, None, D('123'), None, None, D('123') ], [ D('1.67321232123'), None, D('1.673'), None, None, D('1.673'), None, None, D('1.673'), None ], [ D('5.67345434543'), D('5.67'), None, None, D('5.67'), None, None, D('5.67'), None, None ]] self.assertEqual(erows, arows)
def test_amount(self): itypes = [('pos', amount.Amount)] irows = [(A(string), ) for string in self.input_amounts] atypes, arows = numberify.numberify_results(itypes, irows) self.assertEqual(self.expected_types, atypes) self.assertEqual(self.expected_rows, arows)