|
| 1 | +from subprocess import CalledProcessError |
| 2 | +from unittest import mock |
| 3 | + |
1 | 4 | import pytest |
2 | 5 | from packaging.version import Version |
3 | 6 | from pydantic import BaseModel |
4 | 7 | from pydantic_core._pydantic_core import ValidationError |
5 | 8 |
|
6 | 9 | from exasol.toolbox.util.dependencies.shared_models import ( |
7 | 10 | VERSION_TYPE, |
| 11 | + LatestTagNotFoundError, |
8 | 12 | Package, |
9 | 13 | PoetryFiles, |
10 | 14 | poetry_files_from_latest_tag, |
@@ -56,11 +60,28 @@ def test_coordinates(): |
56 | 60 | assert dep.coordinates == "numpy:0.1.0" |
57 | 61 |
|
58 | 62 |
|
59 | | -def test_poetry_files_from_latest_tag(): |
60 | | - latest_tag = Git.get_latest_tag() |
61 | | - with poetry_files_from_latest_tag(root_path=PROJECT_CONFIG.root_path) as tmp_dir: |
62 | | - for file in PoetryFiles().files: |
63 | | - assert (tmp_dir / file).is_file() |
| 63 | +class TestPoetryFilesFromLatestTag: |
| 64 | + @staticmethod |
| 65 | + def test_works_as_expected(): |
| 66 | + latest_tag = Git.get_latest_tag() |
| 67 | + with poetry_files_from_latest_tag( |
| 68 | + root_path=PROJECT_CONFIG.root_path |
| 69 | + ) as tmp_dir: |
| 70 | + for file in PoetryFiles().files: |
| 71 | + assert (tmp_dir / file).is_file() |
64 | 72 |
|
65 | | - contents = (tmp_dir / PoetryFiles.pyproject_toml).read_text() |
66 | | - assert f'version = "{latest_tag}"' in contents |
| 73 | + contents = (tmp_dir / PoetryFiles.pyproject_toml).read_text() |
| 74 | + assert f'version = "{latest_tag}"' in contents |
| 75 | + |
| 76 | + @staticmethod |
| 77 | + def test_raises_exception_when_latest_tag_not_found(): |
| 78 | + with pytest.raises(LatestTagNotFoundError): |
| 79 | + with mock.patch.object( |
| 80 | + Git, |
| 81 | + "get_latest_tag", |
| 82 | + side_effect=CalledProcessError( |
| 83 | + cmd="Mocked subprocess error", returncode=1 |
| 84 | + ), |
| 85 | + ): |
| 86 | + with poetry_files_from_latest_tag(root_path=PROJECT_CONFIG.root_path): |
| 87 | + pass |
0 commit comments