1+ from typing import Any
12from unittest import TestCase
23
34import pytest
5+ import xarray as xr
46
5- from xrlint .config import Config , ConfigList
6- from xrlint .rule import RuleConfig
7+ from xrlint .config import Config , ConfigList , get_core_config
8+ from xrlint .constants import CORE_PLUGIN_NAME
9+ from xrlint .plugin import Plugin , new_plugin
10+ from xrlint .processor import define_processor , ProcessorOp
11+ from xrlint .result import Message
12+ from xrlint .rule import RuleConfig , Rule
713from xrlint .util .filefilter import FileFilter
814
915
1016# noinspection PyMethodMayBeStatic
1117class ConfigTest (TestCase ):
18+ def test_class_props (self ):
19+ self .assertEqual ("config" , Config .value_name ())
20+ self .assertEqual ("Config | dict | None" , Config .value_type_name ())
21+
1222 def test_defaults (self ):
1323 config = Config ()
1424 self .assertEqual (None , config .name )
@@ -20,6 +30,50 @@ def test_defaults(self):
2030 self .assertEqual (None , config .plugins )
2131 self .assertEqual (None , config .rules )
2232
33+ def test_get_plugin (self ):
34+ config = get_core_config ()
35+ plugin = config .get_plugin (CORE_PLUGIN_NAME )
36+ self .assertIsInstance (plugin , Plugin )
37+
38+ with pytest .raises (ValueError , match = "unknown plugin 'xcube'" ):
39+ config .get_plugin ("xcube" )
40+
41+ def test_get_rule (self ):
42+ config = get_core_config ()
43+ rule = config .get_rule ("flags" )
44+ self .assertIsInstance (rule , Rule )
45+
46+ with pytest .raises (ValueError , match = "unknown rule 'foo'" ):
47+ config .get_rule ("foo" )
48+
49+ def test_get_processor_op (self ):
50+ class MyProc (ProcessorOp ):
51+ def preprocess (
52+ self , file_path : str , opener_options : dict [str , Any ]
53+ ) -> list [tuple [xr .Dataset , str ]]:
54+ pass
55+
56+ def postprocess (
57+ self , messages : list [list [Message ]], file_path : str
58+ ) -> list [Message ]:
59+ pass
60+
61+ processor = define_processor ("myproc" , op_class = MyProc )
62+ config = Config (
63+ plugins = dict (
64+ myplugin = new_plugin ("myplugin" , processors = dict (myproc = processor ))
65+ )
66+ )
67+
68+ processor_op = config .get_processor_op (MyProc ())
69+ self .assertIsInstance (processor_op , MyProc )
70+
71+ processor_op = config .get_processor_op ("myplugin/myproc" )
72+ self .assertIsInstance (processor_op , MyProc )
73+
74+ with pytest .raises (ValueError , match = "unknown processor 'myplugin/myproc2'" ):
75+ config .get_processor_op ("myplugin/myproc2" )
76+
2377 def test_from_value_ok (self ):
2478 self .assertEqual (Config (), Config .from_value (None ))
2579 self .assertEqual (Config (), Config .from_value ({}))
@@ -167,7 +221,7 @@ def test_compute_config(self):
167221
168222 config_list = ConfigList (
169223 [
170- Config (settings = {"a" : 1 , "b" : 1 }),
224+ Config (ignores = [ "**/*.yaml" ], settings = {"a" : 1 , "b" : 1 }),
171225 Config (files = ["**/datacubes/*.zarr" ], settings = {"b" : 2 }),
172226 Config (files = ["**/*.txt" ], settings = {"a" : 2 }),
173227 ]
@@ -185,6 +239,12 @@ def test_compute_config(self):
185239 config_list .compute_config (file_path ),
186240 )
187241
242+ file_path = "s3://wq-services/datacubes/config.yaml"
243+ self .assertEqual (
244+ None ,
245+ config_list .compute_config (file_path ),
246+ )
247+
188248 def test_split_global_filter (self ):
189249 config_list = ConfigList (
190250 [
0 commit comments