|
1 | 1 | import os |
2 | | -import unittest |
| 2 | +from collections.abc import Generator |
3 | 3 | from unittest.mock import patch |
4 | 4 |
|
| 5 | +import pytest |
| 6 | + |
5 | 7 | import pystac |
6 | 8 | from tests.utils import TestCases |
7 | 9 |
|
8 | 10 |
|
9 | | -class VersionTest(unittest.TestCase): |
10 | | - def setUp(self) -> None: |
11 | | - pystac.version.STACVersion._override_version = None |
12 | | - |
13 | | - def test_override_stac_version_with_environ(self) -> None: |
14 | | - override_version = "1.0.0-gamma.2" |
15 | | - with patch.dict(os.environ, {"PYSTAC_STAC_VERSION_OVERRIDE": override_version}): |
16 | | - cat = TestCases.case_1() |
17 | | - d = cat.to_dict() |
18 | | - self.assertEqual(d["stac_version"], override_version) |
19 | | - |
20 | | - def test_override_stac_version_with_call(self) -> None: |
21 | | - override_version = "1.0.0-delta.2" |
22 | | - pystac.set_stac_version(override_version) |
| 11 | +def test_override_stac_version_with_environ() -> None: |
| 12 | + override_version = "1.0.0-gamma.2" |
| 13 | + with patch.dict(os.environ, {"PYSTAC_STAC_VERSION_OVERRIDE": override_version}): |
23 | 14 | cat = TestCases.case_1() |
24 | 15 | d = cat.to_dict() |
25 | | - self.assertEqual(d["stac_version"], override_version) |
| 16 | + assert d["stac_version"] == override_version |
| 17 | + |
| 18 | + |
| 19 | +@pytest.fixture |
| 20 | +def override_pystac_version() -> Generator[str]: |
| 21 | + stac_version = pystac.get_stac_version() |
| 22 | + override_version = "1.0.0-delta.2" |
| 23 | + pystac.set_stac_version(override_version) |
| 24 | + yield override_version |
| 25 | + pystac.set_stac_version(stac_version) |
| 26 | + |
| 27 | + |
| 28 | +def test_override_stac_version_with_call(override_pystac_version: str) -> None: |
| 29 | + cat = TestCases.case_1() |
| 30 | + d = cat.to_dict() |
| 31 | + assert d["stac_version"] == override_pystac_version |
0 commit comments