diff options
author | Ronny Pfannschmidt <opensource@ronnypfannschmidt.de> | 2022-06-26 23:06:53 +0200 |
---|---|---|
committer | Ronny Pfannschmidt <opensource@ronnypfannschmidt.de> | 2022-06-26 23:06:53 +0200 |
commit | 1d920c7dd3d21000570c68c4cb3af24a9cdfac5e (patch) | |
tree | 10e30b8cb9728d4a6a0d0be149d42ba00be3a972 /testing/test_cli.py | |
parent | 1c00405a0e5075a2330c60a69f72d4c7aad88203 (diff) | |
download | setuptools-scm-1d920c7dd3d21000570c68c4cb3af24a9cdfac5e.tar.gz |
fix #691 - support root in pyproject.toml even for cli
superseeds #702 which served as inspiration
adds integration tests
Diffstat (limited to 'testing/test_cli.py')
-rw-r--r-- | testing/test_cli.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/testing/test_cli.py b/testing/test_cli.py new file mode 100644 index 0000000..0198111 --- /dev/null +++ b/testing/test_cli.py @@ -0,0 +1,50 @@ +from __future__ import annotations + +import io +from contextlib import redirect_stdout + +import pytest + +from .conftest import DebugMode +from .test_git import wd as wd_fixture # NOQA evil fixture reuse +from .wd_wrapper import WorkDir +from setuptools_scm._cli import main + + +PYPROJECT_TOML = "pyproject.toml" +PYPROJECT_SIMPLE = "[tool.setuptools_scm]" +PYPROJECT_ROOT = '[tool.setuptools_scm]\nroot=".."' + + +def get_output(args: list[str]) -> str: + + with redirect_stdout(io.StringIO()) as out: + main(args) + return out.getvalue() + + +def test_cli_find_pyproject( + wd: WorkDir, monkeypatch: pytest.MonkeyPatch, debug_mode: DebugMode +) -> None: + debug_mode.disable() + wd.commit_testfile() + wd.write(PYPROJECT_TOML, PYPROJECT_SIMPLE) + monkeypatch.chdir(wd.cwd) + + out = get_output([]) + assert out.startswith("0.1.dev1+") + + with pytest.raises(SystemExit, match="no version found for"): + get_output(["--root=.."]) + + wd.write(PYPROJECT_TOML, PYPROJECT_ROOT) + with pytest.raises(SystemExit, match="no version found for"): + print(get_output(["-c", PYPROJECT_TOML])) + + with pytest.raises(SystemExit, match="no version found for"): + + get_output(["-c", PYPROJECT_TOML, "--root=.."]) + + with pytest.warns(UserWarning, match="root .. is overridden by the cli arg ."): + out = get_output(["-c", PYPROJECT_TOML, "--root=."]) + assert out.startswith("0.1.dev1+") |