@@ -105,3 +105,43 @@ def test_expand_globs_without_changing_directory() -> None:
105105 )
106106 for path in list (glob (os .path .abspath ("." ) + "/*.md" )):
107107 assert path in handler ._paths
108+
109+
110+ @pytest .mark .parametrize (
111+ ("expect_change" , "extension" ),
112+ [
113+ (True , "extension.py" ),
114+ (True , "extension.py:SomeExtension" ),
115+ (True , "path/to/extension.py" ),
116+ (True , "path/to/extension.py:SomeExtension" ),
117+ (True , {"extension.py" : {"option" : "value" }}),
118+ (True , {"extension.py:SomeExtension" : {"option" : "value" }}),
119+ (True , {"path/to/extension.py" : {"option" : "value" }}),
120+ (True , {"path/to/extension.py:SomeExtension" : {"option" : "value" }}),
121+ (False , "/absolute/path/to/extension.py" ),
122+ (False , "/absolute/path/to/extension.py:SomeExtension" ),
123+ (False , {"/absolute/path/to/extension.py" : {"option" : "value" }}),
124+ (False , {"/absolute/path/to/extension.py:SomeExtension" : {"option" : "value" }}),
125+ (False , "dot.notation.path.to.extension" ),
126+ (False , "dot.notation.path.to.pyextension" ),
127+ (False , {"dot.notation.path.to.extension" : {"option" : "value" }}),
128+ (False , {"dot.notation.path.to.pyextension" : {"option" : "value" }}),
129+ ],
130+ )
131+ def test_extension_paths (tmp_path : Path , expect_change : bool , extension : str | dict ) -> None :
132+ """Assert extension paths are resolved relative to config file."""
133+ handler = get_handler (
134+ theme = "material" ,
135+ config_file_path = str (tmp_path .joinpath ("mkdocs.yml" )),
136+ )
137+ normalized = handler .normalize_extension_paths ([extension ])[0 ]
138+ if expect_change :
139+ if isinstance (normalized , str ) and isinstance (extension , str ):
140+ assert normalized == str (tmp_path .joinpath (extension ))
141+ elif isinstance (normalized , dict ) and isinstance (extension , dict ):
142+ pth , options = next (iter (extension .items ()))
143+ assert normalized == {str (tmp_path .joinpath (pth )): options }
144+ else :
145+ raise ValueError ("Normalization must not change extension items type" )
146+ else :
147+ assert normalized == extension
0 commit comments