18
18
from sphinx .ext .intersphinx import setup as intersphinx_setup
19
19
from sphinx .ext .intersphinx ._cli import inspect_main
20
20
from sphinx .ext .intersphinx ._load import (
21
- _fetch_inventory ,
21
+ _fetch_inventory_data ,
22
22
_fetch_inventory_group ,
23
23
_get_safe_url ,
24
24
_InvConfig ,
25
+ _load_inventory ,
25
26
_strip_basic_auth ,
26
27
load_mappings ,
27
28
validate_intersphinx_mapping ,
@@ -85,12 +86,15 @@ def test_fetch_inventory_redirection(get_request, InventoryFile, app):
85
86
86
87
# same uri and inv, not redirected
87
88
mocked_get .url = 'https://hostname/' + INVENTORY_FILENAME
88
- _fetch_inventory (
89
- target_uri = 'https://hostname/' ,
89
+ target_uri = 'https://hostname/'
90
+ raw_data , target_uri = _fetch_inventory_data (
91
+ target_uri = target_uri ,
90
92
inv_location = 'https://hostname/' + INVENTORY_FILENAME ,
91
93
config = _InvConfig .from_config (app .config ),
92
94
srcdir = app .srcdir ,
95
+ cache_path = None ,
93
96
)
97
+ _load_inventory (raw_data , target_uri = target_uri )
94
98
assert 'intersphinx inventory has moved' not in app .status .getvalue ()
95
99
assert InventoryFile .loads .call_args [1 ]['uri' ] == 'https://hostname/'
96
100
@@ -99,12 +103,15 @@ def test_fetch_inventory_redirection(get_request, InventoryFile, app):
99
103
app .status .truncate (0 )
100
104
mocked_get .url = 'https://hostname/new/' + INVENTORY_FILENAME
101
105
102
- _fetch_inventory (
103
- target_uri = 'https://hostname/' ,
106
+ target_uri = 'https://hostname/'
107
+ raw_data , target_uri = _fetch_inventory_data (
108
+ target_uri = target_uri ,
104
109
inv_location = 'https://hostname/' + INVENTORY_FILENAME ,
105
110
config = _InvConfig .from_config (app .config ),
106
111
srcdir = app .srcdir ,
112
+ cache_path = None ,
107
113
)
114
+ _load_inventory (raw_data , target_uri = target_uri )
108
115
assert app .status .getvalue () == (
109
116
'intersphinx inventory has moved: '
110
117
'https://hostname/%s -> https://hostname/new/%s\n '
@@ -117,12 +124,15 @@ def test_fetch_inventory_redirection(get_request, InventoryFile, app):
117
124
app .status .truncate (0 )
118
125
mocked_get .url = 'https://hostname/new/' + INVENTORY_FILENAME
119
126
120
- _fetch_inventory (
121
- target_uri = 'https://hostname/' ,
127
+ target_uri = 'https://hostname/'
128
+ raw_data , target_uri = _fetch_inventory_data (
129
+ target_uri = target_uri ,
122
130
inv_location = 'https://hostname/new/' + INVENTORY_FILENAME ,
123
131
config = _InvConfig .from_config (app .config ),
124
132
srcdir = app .srcdir ,
133
+ cache_path = None ,
125
134
)
135
+ _load_inventory (raw_data , target_uri = target_uri )
126
136
assert 'intersphinx inventory has moved' not in app .status .getvalue ()
127
137
assert InventoryFile .loads .call_args [1 ]['uri' ] == 'https://hostname/'
128
138
@@ -131,12 +141,15 @@ def test_fetch_inventory_redirection(get_request, InventoryFile, app):
131
141
app .status .truncate (0 )
132
142
mocked_get .url = 'https://hostname/other/' + INVENTORY_FILENAME
133
143
134
- _fetch_inventory (
135
- target_uri = 'https://hostname/' ,
144
+ target_uri = 'https://hostname/'
145
+ raw_data , target_uri = _fetch_inventory_data (
146
+ target_uri = target_uri ,
136
147
inv_location = 'https://hostname/new/' + INVENTORY_FILENAME ,
137
148
config = _InvConfig .from_config (app .config ),
138
149
srcdir = app .srcdir ,
150
+ cache_path = None ,
139
151
)
152
+ _load_inventory (raw_data , target_uri = target_uri )
140
153
assert app .status .getvalue () == (
141
154
'intersphinx inventory has moved: '
142
155
'https://hostname/new/%s -> https://hostname/other/%s\n '
@@ -774,13 +787,16 @@ def test_intersphinx_cache_limit(app, monkeypatch, cache_limit, expected_expired
774
787
now = 2 * 86400
775
788
monkeypatch .setattr ('time.time' , lambda : now )
776
789
777
- # `_fetch_inventory_group` calls `_fetch_inventory `.
790
+ # `_fetch_inventory_group` calls `_fetch_inventory_data `.
778
791
# We replace it with a mock to test whether it has been called.
779
792
# If it has been called, it means the cache had expired.
780
- mock_fake_inventory = _Inventory ({}) # must be truthy
781
- mock_fetch_inventory = mock .Mock (return_value = mock_fake_inventory )
782
793
monkeypatch .setattr (
783
- 'sphinx.ext.intersphinx._load._fetch_inventory' , mock_fetch_inventory
794
+ 'sphinx.ext.intersphinx._load._fetch_inventory_data' ,
795
+ mock .Mock (return_value = (b'' , '' )),
796
+ )
797
+ mock_fetch_inventory = mock .Mock (return_value = _Inventory ({}))
798
+ monkeypatch .setattr (
799
+ 'sphinx.ext.intersphinx._load._load_inventory' , mock_fetch_inventory
784
800
)
785
801
786
802
for name , (uri , locations ) in app .config .intersphinx_mapping .values ():
@@ -791,8 +807,9 @@ def test_intersphinx_cache_limit(app, monkeypatch, cache_limit, expected_expired
791
807
now = now ,
792
808
config = _InvConfig .from_config (app .config ),
793
809
srcdir = app .srcdir ,
810
+ cache_dir = None ,
794
811
)
795
- # If we hadn't mocked `_fetch_inventory `, it would've made
812
+ # If we hadn't mocked `_fetch_inventory_data `, it would've made
796
813
# a request to `https://example.org/` and found no inventory
797
814
# file. That would've been an error, and `updated` would've been
798
815
# False even if the cache had expired. The mock makes it behave
@@ -826,8 +843,14 @@ def log_message(*args, **kwargs):
826
843
}
827
844
828
845
now = int (time .time ())
829
- # we can use 'srcdir=None' since we are raising in _fetch_inventory
830
- kwds = {'cache' : {}, 'now' : now , 'config' : config , 'srcdir' : None }
846
+ # we can use 'srcdir=None' since we are raising in _fetch_inventory_data
847
+ kwds = {
848
+ 'cache' : {},
849
+ 'now' : now ,
850
+ 'config' : config ,
851
+ 'srcdir' : None ,
852
+ 'cache_dir' : None ,
853
+ }
831
854
# We need an exception with its 'args' attribute set (see error
832
855
# handling in sphinx.ext.intersphinx._load._fetch_inventory_group).
833
856
side_effect = ValueError ('' )
@@ -836,38 +859,44 @@ def log_message(*args, **kwargs):
836
859
name = '1' , target_uri = url1 , locations = (url1 , None )
837
860
)
838
861
with mock .patch (
839
- 'sphinx.ext.intersphinx._load._fetch_inventory' , side_effect = side_effect
862
+ 'sphinx.ext.intersphinx._load._fetch_inventory_data' ,
863
+ side_effect = side_effect ,
840
864
) as mockfn :
841
865
assert not _fetch_inventory_group (project = project1 , ** kwds )
842
866
mockfn .assert_any_call (
843
867
target_uri = url1 ,
844
868
inv_location = url1 ,
845
869
config = config ,
846
870
srcdir = None ,
871
+ cache_path = None ,
847
872
)
848
873
mockfn .assert_any_call (
849
874
target_uri = url1 ,
850
875
inv_location = url1 + '/' + INVENTORY_FILENAME ,
851
876
config = config ,
852
877
srcdir = None ,
878
+ cache_path = None ,
853
879
)
854
880
855
881
project2 = _IntersphinxProject (
856
882
name = '2' , target_uri = url2 , locations = (url2 , None )
857
883
)
858
884
with mock .patch (
859
- 'sphinx.ext.intersphinx._load._fetch_inventory' , side_effect = side_effect
885
+ 'sphinx.ext.intersphinx._load._fetch_inventory_data' ,
886
+ side_effect = side_effect ,
860
887
) as mockfn :
861
888
assert not _fetch_inventory_group (project = project2 , ** kwds )
862
889
mockfn .assert_any_call (
863
890
target_uri = url2 ,
864
891
inv_location = url2 ,
865
892
config = config ,
866
893
srcdir = None ,
894
+ cache_path = None ,
867
895
)
868
896
mockfn .assert_any_call (
869
897
target_uri = url2 ,
870
898
inv_location = url2 + INVENTORY_FILENAME ,
871
899
config = config ,
872
900
srcdir = None ,
901
+ cache_path = None ,
873
902
)
0 commit comments