test__detect_program_name.py
This file
Path
tests/test_utils/test__detect_program_name.py
27 lines · 762 bytes · Python
Last changed by
Merge stable into main. (#3674)Rowlando13before adoption7925a34
History of this fileTake it
Merge stable into main. (#3674)Rowlando13before adoption7925a34
lines 1–27why, one step back1import pathlib23import pytest45import click678class MockMain:9 __slots__ = "__package__"1011 def __init__(self, package_name):12 self.__package__ = package_name131415@pytest.mark.parametrize(16 ("path", "main", "expected"),17 [18 ("example.py", None, "example.py"),19 (str(pathlib.Path("/foo/bar/example.py")), None, "example.py"),20 ("example", None, "example"),21 (str(pathlib.Path("example/__main__.py")), "example", "python -m example"),22 (str(pathlib.Path("example/cli.py")), "example", "python -m example.cli"),23 (str(pathlib.Path("./example")), "", "example"),24 ],25)26def test_detect_program_name(path, main, expected):27 assert click.utils._detect_program_name(path, _main=MockMain(main)) == expected