Skip to content

Instantly share code, notes, and snippets.

@RidaAyed
Last active June 25, 2018 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RidaAyed/465a90d881b2fd676e1daffe715f9f77 to your computer and use it in GitHub Desktop.
Save RidaAyed/465a90d881b2fd676e1daffe715f9f77 to your computer and use it in GitHub Desktop.
$ git clone https://gist.github.com/RidaAyed/465a90d881b2fd676e1daffe715f9f77 && cd 465a90d881b2fd676e1daffe715f9f77/ && bash test_icsv2ledger.sh
#!/usr/bin/env bash
#######################################################################
# Testing icsv2ledger #
#######################################################################
#######################################################################
# Echo console messages a bit more flashy #
#######################################################################
flashy_echo() {
msg="# $* #"
edge=$(echo "$msg" | sed 's/./#/g')
echo "$edge"
echo "$msg"
echo "$edge"
}
#######################################################################
# Start testing #
#######################################################################
flashy_echo "Start testing"
#######################################################################
# Setup test environment: Create directory, download icsv2ledger #
#######################################################################
cd ~
rm test_icsv2ledger -rf
mkdir test_icsv2ledger
cd test_icsv2ledger
git clone https://github.com/quentinsf/icsv2ledger
cd icsv2ledger
#######################################################################
# Create a minimal ledger journal #
#######################################################################
printf "2050/01/01 * Opening Balance \r
Assets:Bank:Current \$ 100\r
Equity:OpeningBalances\n" >> journal.ledger
#######################################################################
# Balance must equal $ 100, journal.ledger is untouched: #
#######################################################################
flashy_echo "Balance must equal $ 100, journal.ledger is untouched:"
####################################################
# Display balance using 'ledger balance' command #
####################################################
ledger -f journal.ledger bal Assets:Bank:Current
##############################
# Create minimal input csv #
##############################
printf "2050/01/02,Spotify,-5\n" > in.csv
#######################################################################
# First run of icsv2ledger. Expect to input (1)payee & (2)account: #
#######################################################################
flashy_echo "Run icsv2ledger. Expect to input (1)payee & (2)account:"
python3 icsv2ledger.py --incremental --skip-lines=0 \
--csv-date-format=%Y/%m/%d --credit 3 \
--debit 0 --desc 2 \
--account Assets:Bank:Current in.csv journal.ledger
#######################################################################
# Balance must equal $ 95, journal.ledger was changed: #
#######################################################################
flashy_echo "Balance must equal $ 95, journal.ledger was changed:"
ledger -f journal.ledger bal Assets:Bank:Current
#######################################################################
# Attempting to import same transaction with icsv2ledger: #
#######################################################################
flashy_echo "Attempting to import same transaction with icsv2ledger:"
python3 icsv2ledger.py --ledger-file=journal.ledger --skip-dupes \
--incremental --skip-lines=0 --csv-date-format=%Y/%m/%d \
--credit 3 --debit 0 --desc 2 \
--account Assets:Bank:Current in.csv journal.ledger
#######################################################################
# Final balance must still equal $ 95 #
#######################################################################
flashy_echo "Final balance must still equal $ 95"
ledger -f journal.ledger bal Assets:Bank:Current
#######################################################################
# Testing ended #
#######################################################################
flashy_echo "Testing ended"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment