Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions layerforge/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ def process_model(
"Only one of scale_factor or target_height can be provided."
)

if layer_height <= 0:
raise click.BadParameter("must be > 0", param_hint="--layer-height")
if scale_factor is not None and scale_factor <= 0:
raise click.BadParameter("must be > 0", param_hint="--scale-factor")
if target_height is not None and target_height <= 0:
raise click.BadParameter("must be > 0", param_hint="--target-height")

shape_context = StrategyContext()
register_shape_strategies(shape_context)
initialize_loaders()
Expand Down
16 changes: 16 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,19 @@ def test_cli_end_to_end_generates_svgs(tmp_path):

assert result.exit_code == 0, result.output
assert sorted(out_dir.glob("slice_*.svg")), "no svg files generated"

def test_cli_invalid_layer_height(monkeypatch):
runner = CliRunner()
result = runner.invoke(
cli,
[
"--stl-file",
"model.stl",
"--layer-height",
"0",
"--output-folder",
"out",
],
)
assert result.exit_code != 0
assert "Invalid value for --layer-height" in result.output
34 changes: 34 additions & 0 deletions tests/test_process_model_validation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import pytest
import click

from layerforge.cli import process_model


def test_process_model_invalid_layer_height(cylinder_stl, tmp_path):
with pytest.raises(click.BadParameter):
process_model(
stl_file=str(cylinder_stl),
layer_height=0,
output_folder=str(tmp_path),
)


def test_process_model_invalid_scale_factor(cylinder_stl, tmp_path):
with pytest.raises(click.BadParameter):
process_model(
stl_file=str(cylinder_stl),
layer_height=1.0,
output_folder=str(tmp_path),
scale_factor=0,
)


def test_process_model_invalid_target_height(cylinder_stl, tmp_path):
with pytest.raises(click.BadParameter):
process_model(
stl_file=str(cylinder_stl),
layer_height=1.0,
output_folder=str(tmp_path),
target_height=0,
)

Loading