-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b6ffec8
commit 237f73b
Showing
1 changed file
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
from packaging.requirements import Requirement | ||
|
||
from _nebari.config_set import ConfigSetMetadata, read_config_set | ||
|
||
test_version = "2024.12.2" | ||
|
||
|
||
def test_valid_version_requirement(): | ||
metadata = ConfigSetMetadata( | ||
name="test-config", nebari_version=">=2024.12.0,<2025.0.0" | ||
) | ||
assert metadata.nebari_version.specifier.contains(test_version) | ||
|
||
|
||
def test_invalid_version_requirement(): | ||
with pytest.raises(ValueError) as exc_info: | ||
csm = ConfigSetMetadata(name="test-config", nebari_version=">=2025.0.0") | ||
csm.check_version(test_version) | ||
assert "Current Nebari version" in str(exc_info.value) | ||
|
||
|
||
def test_valid_version_requirement_with_requirement_object(): | ||
requirement = Requirement("nebari>=2024.12.0") | ||
metadata = ConfigSetMetadata(name="test-config", nebari_version=requirement) | ||
assert metadata.nebari_version.specifier.contains(test_version) | ||
|
||
|
||
def test_invalid_version_requirement_with_requirement_object(): | ||
requirement = Requirement("nebari>=2025.0.0") | ||
with pytest.raises(ValueError) as exc_info: | ||
csm = ConfigSetMetadata(name="test-config", nebari_version=requirement) | ||
csm.check_version(test_version) | ||
assert "Current Nebari version" in str(exc_info.value) | ||
|
||
|
||
def test_read_config_set_valid(tmp_path): | ||
config_set_yaml = """ | ||
metadata: | ||
name: test-config | ||
nebari_version: ">=2024.12.0" | ||
config: | ||
key: value | ||
""" | ||
config_set_filepath = tmp_path / "config_set.yaml" | ||
config_set_filepath.write_text(config_set_yaml) | ||
with patch("_nebari.config_set.__version__", "2024.12.2"): | ||
config_set = read_config_set(str(config_set_filepath)) | ||
assert config_set.metadata.name == "test-config" | ||
assert config_set.config["key"] == "value" | ||
|
||
|
||
def test_read_config_set_invalid_version(tmp_path): | ||
config_set_yaml = """ | ||
metadata: | ||
name: test-config | ||
nebari_version: ">=2025.0.0" | ||
config: | ||
key: value | ||
""" | ||
config_set_filepath = tmp_path / "config_set.yaml" | ||
config_set_filepath.write_text(config_set_yaml) | ||
|
||
with patch("_nebari.config_set.__version__", "2024.12.2"): | ||
with pytest.raises(ValueError) as exc_info: | ||
read_config_set(str(config_set_filepath)) | ||
assert "Current Nebari version" in str(exc_info.value) | ||
|
||
|
||
if __name__ == "__main__": | ||
pytest.main() |