<s> import pandas as pd <EOL> import pytest <EOL> from pandas . util import testing as pdt <EOL> from . . import accounts <EOL> @ pytest . fixture ( scope = '<STR_LIT>' ) <EOL> def acc_name ( ) : <EOL> return '<STR_LIT:test>' <EOL> @ pytest . fixture ( scope = '<STR_LIT>' ) <EOL> def acc_bal ( ) : <EOL> return <NUM_LIT:1000> <EOL> @ pytest . fixture <EOL> def acc ( acc_name , acc_bal ) : <EOL> return accounts . Account ( acc_name , acc_bal ) <EOL> def test_init ( acc , acc_name ) : <EOL> assert acc . name == acc_name <EOL> assert acc . balance == <NUM_LIT:1000> <EOL> assert acc . transactions == [ ] <EOL> def test_add_transaction ( acc , acc_bal ) : <EOL> amount = - <NUM_LIT:50> <EOL> subaccount = ( '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' ) <EOL> metadata = { '<STR_LIT>' : '<STR_LIT>' } <EOL> acc . add_transaction ( amount , subaccount , metadata ) <EOL> assert len ( acc . transactions ) == <NUM_LIT:1> <EOL> assert acc . balance == acc_bal + amount <EOL> t = acc . transactions [ - <NUM_LIT:1> ] <EOL> assert isinstance ( t , accounts . Transaction ) <EOL> assert t . amount == amount <EOL> assert t . subaccount == subaccount <EOL> assert t . metadata == metadata <EOL> def test_add_transactions ( acc , acc_bal ) : <EOL> t1 = accounts . Transaction ( <NUM_LIT:200> , ( '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' ) , None ) <EOL> t2 = ( - <NUM_LIT:50> , None , { '<STR_LIT:to>' : '<STR_LIT>' } ) <EOL> t3 = ( - <NUM_LIT:100> , ( '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' ) , '<STR_LIT>' ) <EOL> t4 = ( <NUM_LIT> , None , None ) <EOL> acc . add_transactions ( ( t1 , t2 , t3 , t4 ) ) <EOL> assert len ( acc . transactions ) == <NUM_LIT:4> <EOL> assert acc . balance == acc_bal + t1 [ <NUM_LIT:0> ] + t2 [ <NUM_LIT:0> ] + t3 [ <NUM_LIT:0> ] + t4 [ <NUM_LIT:0> ] <EOL> assert acc . total_transactions ( ) == t1 [ <NUM_LIT:0> ] + t2 [ <NUM_LIT:0> ] + t3 [ <NUM_LIT:0> ] + t4 [ <NUM_LIT:0> ] <EOL> assert acc . total_transactions_by_subacct ( ( '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' ) ) == t1 [ <NUM_LIT:0> ] + t3 [ <NUM_LIT:0> ] <EOL> assert acc . total_transactions_by_subacct ( None ) == t2 [ <NUM_LIT:0> ] + t4 [ <NUM_LIT:0> ] <EOL> assert list ( acc . all_subaccounts ( ) ) == [ ( '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' ) , None ] <EOL> assert list ( acc . iter_subaccounts ( ) ) == [ <EOL> ( ( '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' ) , t1 [ <NUM_LIT:0> ] + t3 [ <NUM_LIT:0> ] ) , <EOL> ( None , t2 [ <NUM_LIT:0> ] + t4 [ <NUM_LIT:0> ] ) ] <EOL> def test_column_names_from_metadata ( ) : <EOL> cnfm = accounts . _column_names_from_metadata <EOL> assert cnfm ( [ ] ) == [ ] <EOL> assert cnfm ( [ { '<STR_LIT:a>' : <NUM_LIT:1> , '<STR_LIT:b>' : <NUM_LIT:2> } ] ) == [ '<STR_LIT:a>' , '<STR_LIT:b>' ] <EOL> assert cnfm ( [ { '<STR_LIT:a>' : <NUM_LIT:1> } , { '<STR_LIT:b>' : <NUM_LIT:2> } ] ) == [ '<STR_LIT:a>' , '<STR_LIT:b>' ] <EOL> assert cnfm ( [ { '<STR_LIT:a>' : <NUM_LIT:1> , '<STR_LIT:b>' : <NUM_LIT:2> } , { '<STR_LIT:a>' : <NUM_LIT:3> , '<STR_LIT:b>' : <NUM_LIT:4> } ] ) == [ '<STR_LIT:a>' , '<STR_LIT:b>' ] <EOL> def test_to_frame ( acc , acc_bal ) : <EOL> t1 = accounts . Transaction ( <NUM_LIT:200> , ( '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' ) , None ) <EOL> t2 = ( - <NUM_LIT:50> , None , { '<STR_LIT:to>' : '<STR_LIT>' } ) <EOL> acc . add_transactions ( ( t1 , t2 ) ) <EOL> expected = pd . DataFrame ( <EOL> [ [ <NUM_LIT:200> , ( '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' ) , None ] , <EOL> [ - <NUM_LIT:50> , None , '<STR_LIT>' ] ] , <EOL> columns = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:to>' ] ) <EOL> df = acc . to_frame ( ) <EOL> pdt . assert_frame_equal ( df , expected ) </s>
