@@ -42,6 +42,12 @@ def reference_check(app, *args, **kwds):
4242 return missing_reference (app , app .env , node , contnode )
4343
4444
45+ def set_config (app , mapping ):
46+ app .config .intersphinx_mapping = mapping
47+ app .config .intersphinx_cache_limit = 0
48+ app .config .intersphinx_disabled_domains = []
49+
50+
4551@mock .patch ('sphinx.ext.intersphinx.InventoryFile' )
4652@mock .patch ('sphinx.ext.intersphinx._read_from_url' )
4753def test_fetch_inventory_redirection (_read_from_url , InventoryFile , app , status , warning ):
@@ -90,13 +96,12 @@ def test_fetch_inventory_redirection(_read_from_url, InventoryFile, app, status,
9096def test_missing_reference (tempdir , app , status , warning ):
9197 inv_file = tempdir / 'inventory'
9298 inv_file .write_bytes (inventory_v2 )
93- app . config . intersphinx_mapping = {
99+ set_config ( app , {
94100 'https://docs.python.org/' : inv_file ,
95101 'py3k' : ('https://docs.python.org/py3k/' , inv_file ),
96102 'py3krel' : ('py3k' , inv_file ), # relative path
97103 'py3krelparent' : ('../../py3k' , inv_file ), # relative path, parent dir
98- }
99- app .config .intersphinx_cache_limit = 0
104+ })
100105
101106 # load the inventory and check if it's done correctly
102107 normalize_intersphinx_mapping (app , app .config )
@@ -169,10 +174,9 @@ def test_missing_reference(tempdir, app, status, warning):
169174def test_missing_reference_pydomain (tempdir , app , status , warning ):
170175 inv_file = tempdir / 'inventory'
171176 inv_file .write_bytes (inventory_v2 )
172- app . config . intersphinx_mapping = {
177+ set_config ( app , {
173178 'https://docs.python.org/' : inv_file ,
174- }
175- app .config .intersphinx_cache_limit = 0
179+ })
176180
177181 # load the inventory and check if it's done correctly
178182 normalize_intersphinx_mapping (app , app .config )
@@ -210,10 +214,9 @@ def test_missing_reference_pydomain(tempdir, app, status, warning):
210214def test_missing_reference_stddomain (tempdir , app , status , warning ):
211215 inv_file = tempdir / 'inventory'
212216 inv_file .write_bytes (inventory_v2 )
213- app . config . intersphinx_mapping = {
217+ set_config ( app , {
214218 'cmd' : ('https://docs.python.org/' , inv_file ),
215- }
216- app .config .intersphinx_cache_limit = 0
219+ })
217220
218221 # load the inventory and check if it's done correctly
219222 normalize_intersphinx_mapping (app , app .config )
@@ -242,10 +245,9 @@ def test_missing_reference_stddomain(tempdir, app, status, warning):
242245def test_missing_reference_cppdomain (tempdir , app , status , warning ):
243246 inv_file = tempdir / 'inventory'
244247 inv_file .write_bytes (inventory_v2 )
245- app . config . intersphinx_mapping = {
248+ set_config ( app , {
246249 'https://docs.python.org/' : inv_file ,
247- }
248- app .config .intersphinx_cache_limit = 0
250+ })
249251
250252 # load the inventory and check if it's done correctly
251253 normalize_intersphinx_mapping (app , app .config )
@@ -269,10 +271,9 @@ def test_missing_reference_cppdomain(tempdir, app, status, warning):
269271def test_missing_reference_jsdomain (tempdir , app , status , warning ):
270272 inv_file = tempdir / 'inventory'
271273 inv_file .write_bytes (inventory_v2 )
272- app . config . intersphinx_mapping = {
274+ set_config ( app , {
273275 'https://docs.python.org/' : inv_file ,
274- }
275- app .config .intersphinx_cache_limit = 0
276+ })
276277
277278 # load the inventory and check if it's done correctly
278279 normalize_intersphinx_mapping (app , app .config )
@@ -291,14 +292,63 @@ def test_missing_reference_jsdomain(tempdir, app, status, warning):
291292 assert rn .astext () == 'baz()'
292293
293294
295+ def test_missing_reference_disabled_domain (tempdir , app , status , warning ):
296+ inv_file = tempdir / 'inventory'
297+ inv_file .write_bytes (inventory_v2 )
298+ set_config (app , {
299+ 'inv' : ('https://docs.python.org/' , inv_file ),
300+ })
301+
302+ # load the inventory and check if it's done correctly
303+ normalize_intersphinx_mapping (app , app .config )
304+ load_mappings (app )
305+
306+ def case (std_without , std_with , py_without , py_with ):
307+ def assert_ (rn , expected ):
308+ if expected is None :
309+ assert rn is None
310+ else :
311+ assert rn .astext () == expected
312+
313+ kwargs = {}
314+
315+ node , contnode = fake_node ('std' , 'doc' , 'docname' , 'docname' , ** kwargs )
316+ rn = missing_reference (app , app .env , node , contnode )
317+ assert_ (rn , std_without )
318+
319+ node , contnode = fake_node ('std' , 'doc' , 'inv:docname' , 'docname' , ** kwargs )
320+ rn = missing_reference (app , app .env , node , contnode )
321+ assert_ (rn , std_with )
322+
323+ # an arbitrary ref in another domain
324+ node , contnode = fake_node ('py' , 'func' , 'module1.func' , 'func()' , ** kwargs )
325+ rn = missing_reference (app , app .env , node , contnode )
326+ assert_ (rn , py_without )
327+
328+ node , contnode = fake_node ('py' , 'func' , 'inv:module1.func' , 'func()' , ** kwargs )
329+ rn = missing_reference (app , app .env , node , contnode )
330+ assert_ (rn , py_with )
331+
332+ # the base case, everything should resolve
333+ assert app .config .intersphinx_disabled_domains == []
334+ case ('docname' , 'docname' , 'func()' , 'func()' )
335+
336+ # disabled one domain
337+ app .config .intersphinx_disabled_domains = ['std' ]
338+ case (None , 'docname' , 'func()' , 'func()' )
339+
340+ # disabled all domains
341+ app .config .intersphinx_disabled_domains = ['all' ]
342+ case (None , 'docname' , None , 'func()' )
343+
344+
294345@pytest .mark .xfail (os .name != 'posix' , reason = "Path separator mismatch issue" )
295346def test_inventory_not_having_version (tempdir , app , status , warning ):
296347 inv_file = tempdir / 'inventory'
297348 inv_file .write_bytes (inventory_v2_not_having_version )
298- app . config . intersphinx_mapping = {
349+ set_config ( app , {
299350 'https://docs.python.org/' : inv_file ,
300- }
301- app .config .intersphinx_cache_limit = 0
351+ })
302352
303353 # load the inventory and check if it's done correctly
304354 normalize_intersphinx_mapping (app , app .config )
@@ -318,16 +368,15 @@ def test_load_mappings_warnings(tempdir, app, status, warning):
318368 """
319369 inv_file = tempdir / 'inventory'
320370 inv_file .write_bytes (inventory_v2 )
321- app . config . intersphinx_mapping = {
371+ set_config ( app , {
322372 'https://docs.python.org/' : inv_file ,
323373 'py3k' : ('https://docs.python.org/py3k/' , inv_file ),
324374 'repoze.workflow' : ('http://docs.repoze.org/workflow/' , inv_file ),
325375 'django-taggit' : ('http://django-taggit.readthedocs.org/en/latest/' ,
326376 inv_file ),
327377 12345 : ('http://www.sphinx-doc.org/en/stable/' , inv_file ),
328- }
378+ })
329379
330- app .config .intersphinx_cache_limit = 0
331380 # load the inventory and check if it's done correctly
332381 normalize_intersphinx_mapping (app , app .config )
333382 load_mappings (app )
@@ -337,7 +386,7 @@ def test_load_mappings_warnings(tempdir, app, status, warning):
337386def test_load_mappings_fallback (tempdir , app , status , warning ):
338387 inv_file = tempdir / 'inventory'
339388 inv_file .write_bytes (inventory_v2 )
340- app . config . intersphinx_cache_limit = 0
389+ set_config ( app , {})
341390
342391 # connect to invalid path
343392 app .config .intersphinx_mapping = {
0 commit comments