File tree 2 files changed +24
-1
lines changed
2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change 2
2
3
3
4
4
class set_options (object ):
5
- """Set global state within a controlled context
5
+ """Set options for xarray in a controlled context.
6
6
7
7
Currently, the only supported option is ``display_width``, which has a
8
8
default value of 80.
@@ -24,6 +24,10 @@ class set_options(object):
24
24
>>> xr.set_options(display_width=80)
25
25
"""
26
26
def __init__ (self , ** kwargs ):
27
+ invalid_options = {k for k in kwargs if k not in OPTIONS }
28
+ if invalid_options :
29
+ raise ValueError ('argument names %r are not in the set of valid '
30
+ 'options %r' % (invalid_options , set (OPTIONS )))
27
31
self .old = OPTIONS .copy ()
28
32
OPTIONS .update (kwargs )
29
33
Original file line number Diff line number Diff line change
1
+ import xarray
2
+ import pytest
3
+
4
+ from xarray .core .options import OPTIONS
5
+
6
+
7
+ def test_invalid_option_raises ():
8
+ with pytest .raises (ValueError ):
9
+ xarray .set_options (not_a_valid_options = True )
10
+
11
+
12
+ def test_nested_options ():
13
+ original = OPTIONS ['display_width' ]
14
+ with xarray .set_options (display_width = 1 ):
15
+ assert OPTIONS ['display_width' ] == 1
16
+ with xarray .set_options (display_width = 2 ):
17
+ assert OPTIONS ['display_width' ] == 2
18
+ assert OPTIONS ['display_width' ] == 1
19
+ assert OPTIONS ['display_width' ] == original
You can’t perform that action at this time.
0 commit comments