Last active
June 25, 2018 13:55
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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