Files
lidar_rendu/lidar_pipeline/tests/test_cli.py
Antoine fb892ea9f2 Translate the whole project to English and fix outdated comments and help
Comments, docstrings, logs, CLI help, map UI, legends, PDF sheet, scripts,
compose files and AGENTS.md are now English. Data keys stay unchanged
(relief_oriente, densite_sol, visualisations/, API JSON keys, link params).
Wrong comments and help defaults found along the way are corrected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 23:16:45 +02:00

105 lines
3.9 KiB
Python

"""Tests for CLI argument parsing."""
import pytest
import sys
class TestCLIParsing:
def test_default_args(self):
"""Default arguments are set correctly."""
from lidar_pipeline.cli import main
# We can't easily call main() without files, so test argparse directly
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("input", help="Input directory")
parser.add_argument("-o", "--output", default="/data/output")
parser.add_argument("-r", "--resolution", type=float, default=0.5)
parser.add_argument("-w", "--workers", type=str, default="auto")
parser.add_argument("-f", "--force", action="store_true")
parser.add_argument("--file", nargs="+", type=str, default=None)
parser.add_argument("--keep-tif", action="store_true")
args = parser.parse_args(["./input"])
assert args.input == "./input"
assert args.output == "/data/output"
assert args.resolution == 0.5
assert args.workers == "auto"
assert args.force is False
assert args.file is None
assert args.keep_tif is False
def test_file_flag_single(self):
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--file", nargs="+", type=str, default=None)
args = parser.parse_args(["--file", "test_file"])
assert args.file == ["test_file"]
def test_file_flag_multiple(self):
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--file", nargs="+", type=str, default=None)
args = parser.parse_args(["--file", "file1", "file2", "file3"])
assert args.file == ["file1", "file2", "file3"]
def test_force_flag(self):
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-f", "--force", action="store_true")
args = parser.parse_args(["-f"])
assert args.force is True
def test_resolution_custom(self):
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-r", "--resolution", type=float, default=0.5)
args = parser.parse_args(["-r", "0.2"])
assert args.resolution == 0.2
class TestSetupLogging:
def test_default_logging(self):
"""Default logging shows messages without timestamps."""
import logging
from lidar_pipeline.cli import setup_logging
logger = setup_logging(verbose=False, debug=False)
assert logger.level == logging.INFO
assert len(logger.handlers) == 1
# Format should not include timestamps
fmt = logger.handlers[0].formatter._fmt
assert "%(asctime)s" not in fmt
def test_verbose_logging(self):
"""Verbose logging includes timestamps."""
import logging
from lidar_pipeline.cli import setup_logging
logger = setup_logging(verbose=True, debug=False)
fmt = logger.handlers[0].formatter._fmt
assert "%(asctime)s" in fmt
def test_debug_logging(self):
"""Debug logging includes file:line info."""
import logging
from lidar_pipeline.cli import setup_logging
logger = setup_logging(verbose=False, debug=True)
assert logger.level == logging.DEBUG
fmt = logger.handlers[0].formatter._fmt
assert "%(filename)s" in fmt
assert "%(lineno)d" in fmt
def test_rebuild_index_without_input_arg(tmp_path):
"""--rebuild-index works without the positional input argument.
Regression: input used to be required although --rebuild-index does not
use it (argparse error "the following arguments are required").
"""
import subprocess
r = subprocess.run(
[sys.executable, "-m", "lidar_pipeline", "--rebuild-index",
"-o", str(tmp_path)],
capture_output=True, text=True, timeout=180,
)
assert r.returncode == 0, r.stderr
assert "the following arguments are required" not in r.stderr