Download tests/test_select.py from soiz1/omegaconf: direct link, hf CLI and curl.
- Browser
- Download file 2.84 kB
-
https://huggingface.co/datasets/soiz1/omegaconf/resolve/main/tests/test_select.py
- Command line
-
hf download hf://datasets/soiz1/omegaconf/tests/test_select.py
-
curl -L -o test_select.py https://huggingface.co/datasets/soiz1/omegaconf/resolve/main/tests/test_select.py
2.84 kB
| import re | |
| from typing import Any, Optional | |
| import pytest | |
| from pytest import raises | |
| from omegaconf import MissingMandatoryValue, OmegaConf | |
| from . import does_not_raise | |
| # type: ignore | |
| def test_select_key_from_empty(struct: Optional[bool]) -> None: | |
| c = OmegaConf.create() | |
| OmegaConf.set_struct(c, struct) | |
| assert OmegaConf.select(c, "not_there") is None | |
| def test_select( | |
| restore_resolvers: Any, cfg: Any, keys: Any, expected: Any, expectation: Any | |
| ) -> None: | |
| if not isinstance(keys, (tuple, list)): | |
| keys = [keys] | |
| if not isinstance(expected, (tuple, list)): | |
| expected = [expected] | |
| OmegaConf.register_resolver("foo", lambda x: f"_{x}_") | |
| c = OmegaConf.create(cfg) | |
| with expectation: | |
| for idx, key in enumerate(keys): | |
| assert OmegaConf.select(c, key) == expected[idx] | |
| def test_select_from_dict() -> None: | |
| c = OmegaConf.create({"missing": "???"}) | |
| with pytest.raises(MissingMandatoryValue): | |
| OmegaConf.select(c, "missing", throw_on_missing=True) | |
| assert OmegaConf.select(c, "missing", throw_on_missing=False) is None | |
| assert OmegaConf.select(c, "missing") is None | |
| def test_select_deprecated() -> None: | |
| c = OmegaConf.create({"foo": "bar"}) | |
| with pytest.warns( | |
| expected_warning=UserWarning, | |
| match=re.escape("select() is deprecated, use OmegaConf.select(). (Since 2.0)"), | |
| ): | |
| c.select("foo") | |