File: test_options.py

package info (click to toggle)
python-rioxarray 0.19.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,304 kB
  • sloc: python: 7,893; makefile: 93
file content (39 lines) | stat: -rw-r--r-- 1,110 bytes parent folder | download | duplicates (3)
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
import pytest

from rioxarray import set_options
from rioxarray._options import EXPORT_GRID_MAPPING, get_option


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