chore: bring the test suite up to ruff's standards
Mostly automatic: empty f-strings, unused imports, formatting. The manual half was duplicated import blocks stranded mid-file and `== None` assertions, which become `is None` here because they compare plain attributes -- unlike the identical rule in filters/book.py, where they build SQL. Two unused variables are the tests never checking the disk in either delete_files direction. Left in place under a noqa so the gap stays visible.
This commit is contained in:
@@ -25,7 +25,9 @@ PDF = DATA_FILES / "Calculus Made Easy - Silvanus Thompson.pdf"
|
||||
def upload(path: Path, name: str | None = None) -> UploadFile:
|
||||
"""An uploaded file carrying the bytes of one of the test fixtures."""
|
||||
return UploadFile(
|
||||
content_type="application/pdf" if path.suffix == ".pdf" else "application/epub+zip",
|
||||
content_type="application/pdf"
|
||||
if path.suffix == ".pdf"
|
||||
else "application/epub+zip",
|
||||
filename=name or path.name,
|
||||
file_data=path.read_bytes(),
|
||||
)
|
||||
@@ -67,7 +69,7 @@ class TestBookServiceCRUD:
|
||||
|
||||
# Add path manually as it won't be generated (not using the create function, but manually inserting into db)
|
||||
book.path = f"{test_library.root_path}/J.R.R Tolkien/The Fellowship of the Ring"
|
||||
await aios.makedirs(book.path) # type: ignore[arg-type]
|
||||
await aios.makedirs(book.path) # type: ignore[arg-type]
|
||||
|
||||
books_service.repository.session.add(book)
|
||||
await books_service.repository.session.commit()
|
||||
@@ -538,9 +540,7 @@ class TestBookPathCollisions:
|
||||
|
||||
assert original.path != forced.path
|
||||
|
||||
paths = {
|
||||
Path(book.path) / book.files[0].path for book in (original, forced)
|
||||
}
|
||||
paths = {Path(book.path) / book.files[0].path for book in (original, forced)}
|
||||
assert len(paths) == 2
|
||||
assert all(path.is_file() for path in paths)
|
||||
|
||||
@@ -581,7 +581,10 @@ class TestBookPathCollisions:
|
||||
# Renamed onto the first book's author and title.
|
||||
await books_service.update_book(
|
||||
second.books[0].id,
|
||||
{"title": original.title, "authors": [author.name for author in original.authors]},
|
||||
{
|
||||
"title": original.title,
|
||||
"authors": [author.name for author in original.authors],
|
||||
},
|
||||
test_library,
|
||||
)
|
||||
|
||||
@@ -743,7 +746,8 @@ class TestDuplicateBooks:
|
||||
)
|
||||
|
||||
matches = await books_service.find_duplicate_books(
|
||||
{"title": "Building Microservices", "authors": ["Newman, Sam;"]}, test_library
|
||||
{"title": "Building Microservices", "authors": ["Newman, Sam;"]},
|
||||
test_library,
|
||||
)
|
||||
|
||||
assert [match.book_id for match in matches] == [stored.id]
|
||||
@@ -834,16 +838,22 @@ class TestDuplicateBooks:
|
||||
"series": "Foundation",
|
||||
}
|
||||
|
||||
assert await books_service.find_duplicate_books(
|
||||
incoming | {"series_position": "2"}, test_library
|
||||
) == []
|
||||
assert (
|
||||
await books_service.find_duplicate_books(
|
||||
incoming | {"series_position": "2"}, test_library
|
||||
)
|
||||
== []
|
||||
)
|
||||
|
||||
# The same volume, written a little differently, still matches.
|
||||
assert len(
|
||||
await books_service.find_duplicate_books(
|
||||
incoming | {"series_position": "1.0"}, test_library
|
||||
assert (
|
||||
len(
|
||||
await books_service.find_duplicate_books(
|
||||
incoming | {"series_position": "1.0"}, test_library
|
||||
)
|
||||
)
|
||||
) == 1
|
||||
== 1
|
||||
)
|
||||
|
||||
async def test_a_book_is_not_its_own_duplicate(
|
||||
self, books_service: BookService, test_library: m.Library
|
||||
@@ -909,7 +919,10 @@ class TestAuthorNames:
|
||||
existing row and then collides with it on the unique index.
|
||||
"""
|
||||
first = await store_book(
|
||||
books_service, test_library, title="Building Microservices", authors=["Sam Newman"]
|
||||
books_service,
|
||||
test_library,
|
||||
title="Building Microservices",
|
||||
authors=["Sam Newman"],
|
||||
)
|
||||
second = await store_book(
|
||||
books_service,
|
||||
@@ -953,7 +966,9 @@ class TestAuthorNames:
|
||||
"Franz Kafka.epub" is not a person.
|
||||
"""
|
||||
result = await books_service.create_many_from_files(
|
||||
BooksCreateFromFiles(files=[upload(EPUB, "Some Unknown Book - Ada Lovelace.epub")]),
|
||||
BooksCreateFromFiles(
|
||||
files=[upload(EPUB, "Some Unknown Book - Ada Lovelace.epub")]
|
||||
),
|
||||
test_library,
|
||||
)
|
||||
|
||||
@@ -1014,7 +1029,10 @@ class TestMergeBooks:
|
||||
) -> None:
|
||||
"""The survivor keeps its own fields unless the caller says otherwise."""
|
||||
keep = await store_book(
|
||||
books_service, test_library, title="Building Microservices", authors=["Sam Newman"]
|
||||
books_service,
|
||||
test_library,
|
||||
title="Building Microservices",
|
||||
authors=["Sam Newman"],
|
||||
)
|
||||
fold = await store_book(
|
||||
books_service,
|
||||
@@ -1030,7 +1048,11 @@ class TestMergeBooks:
|
||||
assert merged.publisher is None
|
||||
|
||||
other = await store_book(
|
||||
books_service, test_library, title="Monolith", authors=["Sam Newman"], edition=3
|
||||
books_service,
|
||||
test_library,
|
||||
title="Monolith",
|
||||
authors=["Sam Newman"],
|
||||
edition=3,
|
||||
)
|
||||
merged = await books_service.merge_books(
|
||||
keep.id, [other.id], test_library, metadata={"edition": 3}
|
||||
@@ -1096,10 +1118,14 @@ class TestMergeBooks:
|
||||
await books_service.merge_books(keep.id, [fold.id], test_library)
|
||||
|
||||
rows = (
|
||||
await books_service.repository.session.execute(
|
||||
select(m.BookProgress).where(m.BookProgress.book_id == keep.id)
|
||||
(
|
||||
await books_service.repository.session.execute(
|
||||
select(m.BookProgress).where(m.BookProgress.book_id == keep.id)
|
||||
)
|
||||
)
|
||||
).scalars().all()
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
|
||||
assert [row.percentage for row in rows] == [0.6]
|
||||
|
||||
@@ -1112,13 +1138,23 @@ class TestMergeBooks:
|
||||
) -> None:
|
||||
"""Both books on one shelf must not leave the survivor linked to it twice."""
|
||||
keep = await store_book(
|
||||
books_service, test_library, title="A", authors=["X"], tags=["Shared", "Only Keep"]
|
||||
books_service,
|
||||
test_library,
|
||||
title="A",
|
||||
authors=["X"],
|
||||
tags=["Shared", "Only Keep"],
|
||||
)
|
||||
fold = await store_book(
|
||||
books_service, test_library, title="B", authors=["X"], tags=["Shared", "Only Fold"]
|
||||
books_service,
|
||||
test_library,
|
||||
title="B",
|
||||
authors=["X"],
|
||||
tags=["Shared", "Only Fold"],
|
||||
)
|
||||
|
||||
shelf = m.BookList(title="Later", user_id=test_user.id, library_id=test_library.id)
|
||||
shelf = m.BookList(
|
||||
title="Later", user_id=test_user.id, library_id=test_library.id
|
||||
)
|
||||
session.add(shelf)
|
||||
await session.commit()
|
||||
session.add_all(
|
||||
@@ -1131,13 +1167,21 @@ class TestMergeBooks:
|
||||
|
||||
merged = await books_service.merge_books(keep.id, [fold.id], test_library)
|
||||
|
||||
assert sorted(tag.name for tag in merged.tags) == ["Only Fold", "Only Keep", "Shared"]
|
||||
assert sorted(tag.name for tag in merged.tags) == [
|
||||
"Only Fold",
|
||||
"Only Keep",
|
||||
"Shared",
|
||||
]
|
||||
|
||||
links = (
|
||||
await books_service.repository.session.execute(
|
||||
select(m.BookListLink).where(m.BookListLink.book_id == keep.id)
|
||||
(
|
||||
await books_service.repository.session.execute(
|
||||
select(m.BookListLink).where(m.BookListLink.book_id == keep.id)
|
||||
)
|
||||
)
|
||||
).scalars().all()
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
assert len(links) == 1
|
||||
|
||||
async def test_an_identifier_moves_only_under_a_name_the_survivor_lacks(
|
||||
|
||||
Reference in New Issue
Block a user