Skip to content

feat(books): add stats, export, year validation, and partial author search#2

Open
xavierxmorris wants to merge 5 commits into
mainfrom
copilot/human-tick
Open

feat(books): add stats, export, year validation, and partial author search#2
xavierxmorris wants to merge 5 commits into
mainfrom
copilot/human-tick

Conversation

@xavierxmorris

Copy link
Copy Markdown
Owner

Summary

Adds year validation, partial author search, collection statistics, and export utilities to the book-app-project sample — along with comprehensive test coverage.

Changes

Features

  • Year validationadd_book() now rejects years outside 1–next year; parse_year() in utils validates at the UI layer
  • Partial author searchfind_by_author() now uses substring matching (case-insensitive)
  • Year-range search — new find_by_year_range() method on BookCollection
  • Statistics module (stats.py) — 8 pure functions: total_books, read_count, unread_count, read_percentage, year_range, books_per_author, average_year, format_stats_report
  • Export module (export.py) — CSV and JSON export: books_to_csv_string, export_books_to_csv, books_to_dicts, export_books_to_json

Tests

  • test_year_validation.py — domain and UI year validation (19 tests)
  • test_find_by_author_partial.py — partial/case-insensitive author search (21 tests)
  • test_find_by_year_range.py — year-range search coverage
  • test_stats.py — full stats module coverage (43 tests)
  • test_export.py — full export module coverage (19 tests)
  • Updated existing tests (test_books_all.py, test_books_comprehensive.py, test_find_by_author.py, test_get_book_details.py) for new behavior

Documentation

  • Expanded .github/copilot-instructions.md with architecture section, build commands, and known-pattern suppression list

How to Test

python -m pytest samples/book-app-project/tests --ignore=samples/book-app-project/tests/test_books_extended.py -v

John Doe and others added 5 commits March 11, 2026 10:16
Covers all BookCollection methods with edge cases:
- Book dataclass creation and equality
- load_books (empty, missing, corrupted JSON, valid data)
- save_books (round-trip persistence)
- add_book (happy path, multiple, boundary inputs)
- list_books (empty, populated, reference identity)
- find_book_by_title (exact, case-insensitive, not found)
- mark_as_read (happy path, only-target, persistence)
- remove_book (happy path, only-target, persistence)
- find_by_author (exact, case-insensitive, multi-match)
- Integration workflows (full CRUD, persistence round-trip)

49 tests, all passing.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Duplicate book handling (add, find, remove behavior)
- Partial title removal (exact match only, no substring)
- Empty collection searches (all methods graceful)
- File permission errors during save
- Concurrent access with threading

24 tests, all passing.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Year validation:
- add_book() rejects year <= 0 or > current year + 1
- parse_year() validates range with clear error messages
- Raises InvalidBookDataError for invalid years

Partial author search:
- find_by_author() now uses substring matching (in) instead of exact (==)
- Searching 'Herbert' now finds 'Frank Herbert'

Tests:
- 18 new year validation tests (test_year_validation.py)
- 21 new partial author match tests (test_find_by_author_partial.py)
- Updated 4 existing test files for new behavior
- 297 total tests passing

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add statistics functions (total, read/unread count, read percentage,
year range, books per author, average year, formatted report) and
export utilities (CSV string, CSV file, JSON file, dict conversion).

Includes comprehensive test suites: 43 tests for stats, 19 for export,
and year-range search tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant