From f92bd8cd2a3d9c4a792f81085ec3feeb2513cf5a Mon Sep 17 00:00:00 2001 From: Adam Lewis <23342526+Adam-D-Lewis@users.noreply.github.com> Date: Mon, 30 Dec 2024 10:30:34 -0600 Subject: [PATCH] update tests --- src/_nebari/config_set.py | 13 ++++++------- tests/tests_unit/test_config_set.py | 27 ++++++++++++++++----------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/_nebari/config_set.py b/src/_nebari/config_set.py index 6adc7bd3fc..c9017d2f37 100644 --- a/src/_nebari/config_set.py +++ b/src/_nebari/config_set.py @@ -1,7 +1,7 @@ import pathlib from typing import Optional -from packaging.requirements import Requirement +from packaging.requirements import SpecifierSet from pydantic import BaseModel, ConfigDict, field_validator from _nebari._version import __version__ @@ -12,22 +12,21 @@ class ConfigSetMetadata(BaseModel): model_config: ConfigDict = ConfigDict(extra="allow", arbitrary_types_allowed=True) name: str # for use with guided init description: Optional[str] = None - nebari_version: str | Requirement + nebari_version: str | SpecifierSet @field_validator("nebari_version") @classmethod def validate_version_requirement(cls, version_req): if isinstance(version_req, str): - version_req = Requirement(f"nebari{version_req}") - version_req.specifier.prereleases = True + version_req = SpecifierSet(version_req, prereleases=True) return version_req def check_version(self, version): - if version not in self.nebari_version.specifier: + if version not in self.nebari_version: raise ValueError( - f"Current Nebari version {__version__} is not compatible with " - f'required version {self.nebari_version.specifier} for "{self.name}" config set.' + f'Nebari version "{version}" is not compatible with ' + f'version requirement {self.nebari_version} for "{self.name}" config set.' ) diff --git a/tests/tests_unit/test_config_set.py b/tests/tests_unit/test_config_set.py index 9ad9633ac8..2f280829f2 100644 --- a/tests/tests_unit/test_config_set.py +++ b/tests/tests_unit/test_config_set.py @@ -1,26 +1,31 @@ from unittest.mock import patch import pytest -from packaging.requirements import Requirement +from packaging.requirements import SpecifierSet from _nebari.config_set import ConfigSetMetadata, read_config_set test_version = "2024.12.2" -test_version = "2024.12.2" - - @pytest.mark.parametrize( - "version_input,should_pass", + "version_input,test_version,should_pass", [ - (">=2024.12.0,<2025.0.0", True), - (Requirement("nebari>=2024.12.0,<2025.0.0"), True), - (">=2025.0.0", False), - (Requirement("nebari>=2025.0.0"), False), + # Standard version tests + (">=2024.12.0,<2025.0.0", "2024.12.2", True), + (SpecifierSet(">=2024.12.0,<2025.0.0", prereleases=True), "2024.12.2", True), + # Pre-release version requirement tests + (">=2024.12.0rc1,<2025.0.0", "2024.12.0rc1", True), + (SpecifierSet(">=2024.12.0rc1", prereleases=True), "2024.12.0rc2", True), + # Pre-release test version against standard requirement + (">=2024.12.0,<2025.0.0", "2024.12.1rc1", True), + (SpecifierSet(">=2024.12.0,<2025.0.0", prereleases=True), "2024.12.1rc1", True), + # Failing cases + (">=2025.0.0", "2024.12.2rc1", False), + (SpecifierSet(">=2025.0.0rc1", prereleases=True), "2024.12.2", False), ], ) -def test_version_requirement(version_input, should_pass): +def test_version_requirement(version_input, test_version, should_pass): metadata = ConfigSetMetadata(name="test-config", nebari_version=version_input) if should_pass: @@ -28,7 +33,7 @@ def test_version_requirement(version_input, should_pass): else: with pytest.raises(ValueError) as exc_info: metadata.check_version(test_version) - assert "Current Nebari version" in str(exc_info.value) + assert "Nebari version" in str(exc_info.value) def test_valid_version_requirement_with_requirement_object():