Skip to content

Feature: Add list unread books command#64

Closed
ishizuka-nkc wants to merge 1 commit intogithub:mainfrom
ishizuka-nkc:feature/list-unread-books
Closed

Feature: Add list unread books command#64
ishizuka-nkc wants to merge 1 commit intogithub:mainfrom
ishizuka-nkc:feature/list-unread-books

Conversation

@ishizuka-nkc
Copy link
Copy Markdown

Summary

Adds a new unread command to the book app CLI that displays only books where read is False.

Changes

books.py

  • Added BookCollection.get_unread_books() -> List[Book] method that returns all unread books using a list comprehension

book_app.py

  • Added handle_list_unread() handler function
  • Registered "unread" command in the COMMANDS dict
  • Updated show_help() to document the new command

tests/test_books.py

  • Added TestGetUnreadBooks class with 19 comprehensive tests covering:
    • Happy path (return type, count, content)
    • Edge cases (empty collection, all read, no side effects)
    • Parametrized combinations of read/unread counts
    • Integration with add_book, mark_as_read, and persistence

Usage

python book_app.py unread

Test Results

128 passed in 4.24s

- Add BookCollection.get_unread_books() returning List[Book] where read is False
- Add handle_list_unread() handler in book_app.py
- Register 'unread' command in COMMANDS dict
- Update show_help() to document the new command
- Add TestGetUnreadBooks with 19 comprehensive tests

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 10, 2026 06:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds CLI support to filter and display unread books in the sample book app, along with supporting collection APIs and expanded test coverage.

Changes:

  • Added BookCollection.get_unread_books() and wired a new unread CLI command to display only unread books.
  • Added search_books() support + search CLI command, and introduced publication year range validation (1–2100).
  • Significantly expanded the test suite for BookCollection behaviors and added tests for utils.get_book_details().

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
samples/book-app-project/books.py Adds year validation, search_books(), and get_unread_books() APIs on BookCollection.
samples/book-app-project/book_app.py Adds unread + search CLI commands, refactors command dispatch via COMMANDS, and updates help output.
samples/book-app-project/tests/test_books.py Reworks/expands collection tests, including persistence, search, and unread behavior.
samples/book-app-project/tests/test_utils.py Adds unit tests for utils.get_book_details() input parsing/normalization behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +36 to 45
if not year_str:
print("\nError: Year cannot be empty.\n")
return

try:
year = int(year_str) if year_str else 0
year = int(year_str)
if year < 1 or year > 2100:
print("\nError: Year must be between 1 and 2100.\n")
return
collection.add_book(title, author, year)
Comment on lines +101 to +109
COMMANDS = {
"list": handle_list,
"unread": handle_list_unread,
"add": handle_add,
"remove": handle_remove,
"find": handle_find,
"search": handle_search,
"help": show_help,
}
@DanWahlin
Copy link
Copy Markdown
Collaborator

Appreciate the PR @ishizuka-nkc. Since changes to the code impact the output generated throughout the course chapters, we're going to leave it "as is" for now (changes to Python would have to be updated across the other languages as well). If we decide to make changes we'll refer back to this though in the future. Thanks again.

@DanWahlin DanWahlin closed this Apr 12, 2026
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.

3 participants