File: test_options.py

package info (click to toggle)
python-rioxarray 0.22.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,572 kB
  • sloc: python: 8,937; makefile: 85
file content (80 lines) | stat: -rw-r--r-- 2,477 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import pytest

from rioxarray import set_options
from rioxarray._options import CONVENTION, EXPORT_GRID_MAPPING, get_option
from rioxarray.enum import Convention


def test_set_options__contextmanager():
    assert get_option(EXPORT_GRID_MAPPING)
    with set_options(**{EXPORT_GRID_MAPPING: False}):
        assert not get_option(EXPORT_GRID_MAPPING)
    assert get_option(EXPORT_GRID_MAPPING)


def test_set_options__global():
    assert get_option(EXPORT_GRID_MAPPING)
    try:
        set_options(export_grid_mapping=False)
        assert not get_option(EXPORT_GRID_MAPPING)
    finally:
        set_options(export_grid_mapping=True)
    assert get_option(EXPORT_GRID_MAPPING)


def test_set_options__invalid_argument():
    with pytest.raises(
        ValueError,
        match="argument name does_not_exist is not in the set of valid options",
    ):
        with set_options(does_not_exist=False):
            pass


def test_set_options__invalid_value():
    with pytest.raises(
        ValueError,
        match="option 'export_grid_mapping' gave an invalid value: 12345.",
    ):
        with set_options(export_grid_mapping=12345):
            pass


def test_set_options__convention_default():
    """Test that convention defaults to None."""
    assert get_option(CONVENTION) is None


def test_set_options__convention_cf():
    """Test setting convention to CF."""
    assert get_option(CONVENTION) is None
    with set_options(convention=Convention.CF):
        assert get_option(CONVENTION) is Convention.CF
    assert get_option(CONVENTION) is None


def test_set_options__convention_zarr():
    """Test setting convention to Zarr."""
    assert get_option(CONVENTION) is None
    with set_options(convention=Convention.ZARR):
        assert get_option(CONVENTION) is Convention.ZARR
    assert get_option(CONVENTION) is None


def test_set_options__convention_none():
    """Test setting convention back to None."""
    with set_options(convention=Convention.CF):
        assert get_option(CONVENTION) is Convention.CF
        with set_options(convention=None):
            assert get_option(CONVENTION) is None
        assert get_option(CONVENTION) is Convention.CF


def test_set_options__convention_invalid():
    """Test that invalid convention values raise error."""
    with pytest.raises(
        ValueError,
        match="option 'convention' gave an invalid value: 'invalid'.",
    ):
        with set_options(convention="invalid"):
            pass