test_version.py
1 from _pytest.capture import CaptureFixture 2 from pytest_mock import MockerFixture 3 4 from ._utils import run_module 5 from api import version 6 7 8 async def test__get_version(mocker: MockerFixture) -> None: 9 getoutput_patch = mocker.patch("subprocess.getoutput") 10 getoutput_patch.return_value = "2d70111\ndevelop\nv1.0.0" 11 12 result = version.get_version() 13 14 getoutput_patch.assert_called_once_with( 15 "(git rev-parse HEAD && (git symbolic-ref --short HEAD || echo) && git describe --tags --always) " 16 "2> /dev/null || cat VERSION" 17 ) 18 assert result == version.Version(commit="2d70111", branch="develop", description="v1.0.0") 19 20 21 async def test__main(capsys: CaptureFixture[str], mocker: MockerFixture) -> None: 22 getoutput_patch = mocker.patch("subprocess.getoutput") 23 getoutput_patch.return_value = "2d70111\ndevelop\nv1.0.0" 24 25 run_module(version) 26 27 getoutput_patch.assert_called_once_with( 28 "(git rev-parse HEAD && (git symbolic-ref --short HEAD || echo) && git describe --tags --always) " 29 "2> /dev/null | tee VERSION" 30 ) 31 assert capsys.readouterr().out.strip() == getoutput_patch()