Skip to content

R35-T053: Add oracle validation suite and modular refactor for Expense Tracker/expense.py - #111

Open
GhodaseSM wants to merge 2 commits into
S-AI-Projects:mainfrom
GhodaseSM:R35-T053
Open

GhodaseSM wants to merge 2 commits into
S-AI-Projects:mainfrom
GhodaseSM:R35-T053

Conversation

@GhodaseSM

Copy link
Copy Markdown

Fix(Expense Tracker): Modularize expense tracker, add oracle validation suite, and safe headless import

Summary

Refactors Expense Tracker/expense.py to decouple SQLite database setup and Tkinter GUI layout from module root, enables headless and test environment execution without _tkinter crashes, adds an independent oracle validation test suite with 22 boundary/domain inputs, and introduces a focused verification runner.

Description

Previously, Expense Tracker/expense.py executed database creation on disk (Expense Tracker.db), instantiated root = Tk(), and blocked in root.mainloop() unconditionally at module root. This prevented automated testing and caused crashes on headless environments or Python versions without Tkinter support.

The changes are as follows:

  • Module Encapsulation: Guarded Tkinter GUI initialization and SQLite connection under if __name__ == '__main__': main() to allow safe headless imports without _tkinter crashes or side-effects.
  • Dependency Injection: Updated list_all_expenses(conn=None, tree=None) to support passing custom/in-memory connections and mock tree widgets, while retaining 100% backward compatibility with global variables and returning the fetched rows for programmatic assertions.
  • Modular Utilities: Added init_db(db_path) and create_gui(conn, cur) to decouple database setup and widget instantiation.
  • Independent Oracle & Equivalence Checking: Designed an independent oracle specification comparing expected multiset records against table contents while ignoring SQL-unspecified row ordering.
  • Comprehensive Unit Tests: Added Expense Tracker/tests/test_expense.py containing 18 unit tests covering:
    • Stale row deletion and table mutation behavior.
    • Safe import without side effects.
    • All 22 enumerated oracle inputs (zero amounts, negative refunds, floating precision, special characters, Unicode/emojis, empty/whitespace strings, diverse payment modes, date formats, and volume tests).
    • Search, filter by date, column sort (ASC/DESC), add expense, remove expense, remove all, verbal preview, and CSV export.
  • Focused Runner: Added work/R35-T053/check.py and saved execution artifacts in work/R35-T053/.

Checks

in the repository

[✓] Made no changes that degrades the functioning of the repository
[✓] Gave each commit a better title (unlike updated README.md)

in the PR

[✓] Followed the format of the pull_request_template
[✓] Made the Pull Request in a small level (for the creator's welfare)
[✓] Tested the changes you made: python3 -m unittest Expense Tracker/tests/test_expense.py (18 tests, all passing)


Note for upstream release: The task runner directory work/R35-T053/ can be removed on a later upstream branch via:

git rm -r work/R35-T053/
git commit -m "chore: remove work/R35-T053 runner artifacts for upstream release"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant