Skip to content

Commit

Permalink
Fix test_update_offsets.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas-C committed Feb 7, 2025
1 parent 6b90a7d commit ac8b923
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pdfly/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def update_offsets(
resolve_path=True,
),
],
file_out: Path = typer.Option(..., "-o", "--output"), # noqa
file_out: Annotated[Path, typer.Option("-o", "--output")] = None,
encoding: str = typer.Option(
"ISO-8859-1",
help="Encoding used to read and write the files, e.g. UTF-8.",
Expand Down
Binary file modified resources/file-with-invalid-offsets.pdf
Binary file not shown.
11 changes: 4 additions & 7 deletions tests/test_update_offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,25 @@

def test_update_offsets(capsys, tmp_path: Path) -> None:
# Arrange
input = str(RESOURCES_ROOT / "file-with-invalid-offsets.pdf")
input = RESOURCES_ROOT / "file-with-invalid-offsets.pdf"
file_expected = str(RESOURCES_ROOT / "file-with-fixed-offsets.pdf")
output = tmp_path / "file-with-offsets-out.pdf"
assert not output.exists()

# Act
exit_code = run_cli(
[
"update-offsets",
str(input),
str(output),
]
)

# Assert
captured = capsys.readouterr()
assert exit_code == 0, captured
assert not captured.err
assert re.search(r"Wrote\s+" + re.escape(str(output)), captured.out)
assert output.exists()
assert re.search(r"Wrote\s+" + re.escape(str(input)), captured.out)
with open(file_expected, encoding="iso-8859-1") as file_exp:
lines_exp = file_exp.readlines()
with open(output, encoding="iso-8859-1") as file_act:
with input.open(encoding="iso-8859-1") as file_act:
lines_act = file_act.readlines()
assert len(lines_exp) == len(
lines_act
Expand Down Expand Up @@ -92,6 +88,7 @@ def test_update_offsets_on_all_reference_files(
"--encoding",
"iso-8859-1",
input_pdf_filepath,
"-o",
str(output_pdf_filepath),
]
)
Expand Down

0 comments on commit ac8b923

Please sign in to comment.