Skip to content

Commit

Permalink
added unit tests and github workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
ma4nn committed Apr 16, 2024
1 parent d47eec8 commit b70aba7
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 2 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "pip" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
28 changes: 28 additions & 0 deletions .github/workflows/verify-script.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Verify Script

on: [push,workflow_dispatch,pull_request]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.10", "3.11" ]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Analysing the code with pylint
run: |
pylint --errors-only $(find src/ -name "*.py" | xargs)
- name: Running tests
run: |
python -m unittest
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# MoneyMoney Extension: Sum by Bank

This is a Pyton script for the great [MoneyMoney software](https://moneymoney-app.com/) to generate a list with all balances by bank account.
![build status](https://github.com/ma4nn/moneymoney-sum-by-bank/actions/workflows/verify-script.yml/badge.svg)

This is a Python script for the great [MoneyMoney software](https://moneymoney-app.com/) to generate a list with all balances by bank account.
This is useful e.g. to export the total values per bank to a summary Excel document or to monitor certain threshold values per bank.

## Installation
Expand Down
2 changes: 1 addition & 1 deletion moneymoney_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class Account(TypedDict):
name: str
bankCode: str
balance: list[float | str]
balance: list[list[float | str]]
portfolio: bool
group: bool
attributes: dict[str, str]
Expand Down
63 changes: 63 additions & 0 deletions test_moneymoney_sum_by_bank.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env python3
"""
Unit Tests
"""

import unittest
import pandas as pd
from pandas.testing import assert_frame_equal
from moneymoney_api import Account
from moneymoney_sum_by_bank import sum_by_account


class TestSumByBank(unittest.TestCase):

def test_empty(self):
df = sum_by_account([])

assert df.empty is True

def test_single_account(self):
accounts: list[Account] = [
Account(name='Test Bank A', balance=[[1000.00, 'EUR']], portfolio=False, group=False, bankCode='TES1')
]

df_expected = pd.DataFrame([{'bank': 'TES1', 'currency': 'EUR', 'balance': 1000.00}]).set_index(['bank', 'currency'])
df = sum_by_account(accounts)

assert_frame_equal(df_expected, df, check_exact=True)

def test_single_account_no_bank_code(self):
accounts: list[Account] = [
Account(name='Test Bank A', balance=[[1000.00, 'EUR']], portfolio=False, group=False, bankCode='', attributes={'bankIdentifier': 'TES1'})
]

df_expected = pd.DataFrame([{'bank': 'TES1', 'currency': 'EUR', 'balance': 1000.00}]).set_index(['bank', 'currency'])
df = sum_by_account(accounts)

assert_frame_equal(df_expected, df, check_exact=True)

def test_multi_accounts_same_bank(self):
accounts: list[Account] = [
Account(name='Test Bank A', balance=[[1000.00, 'EUR']], portfolio=False, group=False, bankCode='TES1'),
Account(name='Test Bank A', balance=[[490.18, 'EUR']], portfolio=False, group=False, bankCode='TES1')
]

df_expected = pd.DataFrame([{'bank': 'TES1', 'currency': 'EUR', 'balance': 1490.18}]).set_index(['bank', 'currency'])
df = sum_by_account(accounts)

assert_frame_equal(df_expected, df, check_exact=True)

def test_multi_accounts(self):
accounts: list[Account] = [
Account(name='Test Bank A', balance=[[1000.00, 'EUR']], portfolio=False, group=False, bankCode='TES1'),
Account(name='Test Bank A', balance=[[490.18, 'EUR']], portfolio=False, group=False, bankCode='TES1IGNORED'),
Account(name='Test Bank B', balance=[[0.99, 'EUR']], portfolio=False, group=False, bankCode='TES2'),
Account(name='Test Bank C', balance=[[0, 'EUR']], portfolio=False, group=False, bankCode='TES3'),
Account(name='Test Bank B', balance=[[0.9988, 'EUR']], portfolio=False, group=False, bankCode='TES2')
]

df_expected = pd.DataFrame([{'bank': 'TES1', 'currency': 'EUR', 'balance': 1490.18}, {'bank': 'TES2', 'currency': 'EUR', 'balance': 1.9888}, {'bank': 'TES3', 'currency': 'EUR', 'balance': 0}]).set_index(['bank', 'currency'])
df = sum_by_account(accounts)

assert_frame_equal(df_expected, df, check_exact=True)

0 comments on commit b70aba7

Please sign in to comment.