Skip to content
This repository was archived by the owner on Jan 21, 2021. It is now read-only.

Commit 6958c32

Browse files
author
Thiago C. D'Ávila
authored
Merge pull request #80 from staticdev/float-max-size
Add fractional max size
2 parents 3c8fe55 + ed44cfd commit 6958c32

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Usage
9393
9494
pdf-split-tool --max-size 50 # for 50 megabytes
9595
96-
Note: you can also use --max-size after the path of a specific PDF.
96+
Note: you can also use --max-size after the path of a specific PDF and fractional numbers such as "50.5".
9797

9898

9999
Contributing

src/pdf_split_tool/__main__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""Command-line interface."""
2+
import math
3+
24
import click
35

46
import pdf_split_tool.file_handler
@@ -34,14 +36,14 @@ def _confirm_split_file(filepath: str, max_size_bytes: int) -> None:
3436
@click.option(
3537
"-m",
3638
"--max-size",
37-
type=int,
39+
type=float,
3840
help="Max size in megabytes.",
3941
default=20,
4042
show_default=True,
4143
)
42-
def main(filepath: str, max_size: int) -> None:
44+
def main(filepath: str, max_size: float) -> None:
4345
"""Pdf Split Tool."""
44-
max_size_bytes = max_size * 1024 * 1024 # convert to MB
46+
max_size_bytes = math.floor(max_size * 1024 * 1024) # convert to bytes
4547
if filepath.endswith(".pdf"):
4648
_confirm_split_file(filepath, max_size_bytes)
4749
else:

tests/test_main.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,13 @@ def test_main_uses_specified_filepath(
8181
with open("test.pdf", "w"):
8282
result = runner.invoke(__main__.main, ["test.pdf"])
8383
assert result.exit_code == 0
84+
85+
86+
def test_main_uses_float_max_size(
87+
runner: click.testing.CliRunner, mock_pdf_splitter_pdfsplitter: Mock,
88+
) -> None:
89+
"""It uses the specified filepath."""
90+
with runner.isolated_filesystem():
91+
with open("test.pdf", "w"):
92+
result = runner.invoke(__main__.main, ["-m", "0.5"])
93+
assert result.exit_code == 0

0 commit comments

Comments
 (0)