11
11
12
12
from mkdocs_autorefs .plugin import AutorefsConfig , AutorefsPlugin
13
13
from mkdocs_autorefs .references import fix_refs
14
+ from tests .helpers import create_page
14
15
15
16
16
17
def test_url_registration () -> None :
17
18
"""Check that URLs can be registered, then obtained."""
18
19
plugin = AutorefsPlugin ()
19
- plugin .register_anchor (identifier = "foo" , page = "foo1.html" , primary = True )
20
+ plugin .register_anchor (identifier = "foo" , page = create_page ( "foo1.html" ) , primary = True )
20
21
plugin .register_url (identifier = "bar" , url = "https://example.org/bar.html" )
21
22
22
23
assert plugin .get_item_url ("foo" ) == ("foo1.html#foo" , None )
@@ -28,7 +29,7 @@ def test_url_registration() -> None:
28
29
def test_url_registration_with_from_url () -> None :
29
30
"""Check that URLs can be registered, then obtained, relative to a page."""
30
31
plugin = AutorefsPlugin ()
31
- plugin .register_anchor (identifier = "foo" , page = "foo1.html" , primary = True )
32
+ plugin .register_anchor (identifier = "foo" , page = create_page ( "foo1.html" ) , primary = True )
32
33
plugin .register_url (identifier = "bar" , url = "https://example.org/bar.html" )
33
34
34
35
assert plugin .get_item_url ("foo" , from_url = "a/b.html" ) == ("../foo1.html#foo" , None )
@@ -41,7 +42,7 @@ def test_url_registration_with_from_url() -> None:
41
42
def test_url_registration_with_fallback () -> None :
42
43
"""Check that URLs can be registered, then obtained through a fallback."""
43
44
plugin = AutorefsPlugin ()
44
- plugin .register_anchor (identifier = "foo" , page = "foo1.html" , primary = True )
45
+ plugin .register_anchor (identifier = "foo" , page = create_page ( "foo1.html" ) , primary = True )
45
46
plugin .register_url (identifier = "bar" , url = "https://example.org/bar.html" )
46
47
47
48
# URL map will be updated with baz -> foo1.html#foo
@@ -60,7 +61,7 @@ def test_url_registration_with_fallback() -> None:
60
61
def test_dont_make_relative_urls_relative_again () -> None :
61
62
"""Check that URLs are not made relative more than once."""
62
63
plugin = AutorefsPlugin ()
63
- plugin .register_anchor (identifier = "foo.bar.baz" , page = "foo/bar/baz.html" , primary = True )
64
+ plugin .register_anchor (identifier = "foo.bar.baz" , page = create_page ( "foo/bar/baz.html" ) , primary = True )
64
65
65
66
for _ in range (2 ):
66
67
assert plugin .get_item_url ("foo.bar.baz" , from_url = "baz/bar/foo.html" ) == (
@@ -96,7 +97,7 @@ def test_find_closest_url(base: str, urls: list[str], expected: str) -> None:
96
97
def test_register_secondary_url () -> None :
97
98
"""Test registering secondary URLs."""
98
99
plugin = AutorefsPlugin ()
99
- plugin .register_anchor (identifier = "foo" , page = "foo.html" , primary = False )
100
+ plugin .register_anchor (identifier = "foo" , page = create_page ( "foo.html" ) , primary = False )
100
101
assert plugin ._secondary_url_map == {"foo" : ["foo.html#foo" ]}
101
102
102
103
@@ -105,8 +106,8 @@ def test_warn_multiple_urls(caplog: pytest.LogCaptureFixture, primary: bool) ->
105
106
"""Warn when multiple URLs are found for the same identifier."""
106
107
plugin = AutorefsPlugin ()
107
108
plugin .config = AutorefsConfig ()
108
- plugin .register_anchor (identifier = "foo" , page = "foo.html" , primary = primary )
109
- plugin .register_anchor (identifier = "foo" , page = "bar.html" , primary = primary )
109
+ plugin .register_anchor (identifier = "foo" , page = create_page ( "foo.html" ) , primary = primary )
110
+ plugin .register_anchor (identifier = "foo" , page = create_page ( "bar.html" ) , primary = primary )
110
111
url_mapper = functools .partial (plugin .get_item_url , from_url = "/hello" )
111
112
# YORE: Bump 2: Replace `, _legacy_refs=False` with `` within line.
112
113
fix_refs ('<autoref identifier="foo">Foo</autoref>' , url_mapper , _legacy_refs = False )
@@ -120,8 +121,8 @@ def test_use_closest_url(caplog: pytest.LogCaptureFixture, primary: bool) -> Non
120
121
plugin = AutorefsPlugin ()
121
122
plugin .config = AutorefsConfig ()
122
123
plugin .config .resolve_closest = True
123
- plugin .register_anchor (identifier = "foo" , page = "foo.html" , primary = primary )
124
- plugin .register_anchor (identifier = "foo" , page = "bar.html" , primary = primary )
124
+ plugin .register_anchor (identifier = "foo" , page = create_page ( "foo.html" ) , primary = primary )
125
+ plugin .register_anchor (identifier = "foo" , page = create_page ( "bar.html" ) , primary = primary )
125
126
url_mapper = functools .partial (plugin .get_item_url , from_url = "/hello" )
126
127
# YORE: Bump 2: Replace `, _legacy_refs=False` with `` within line.
127
128
fix_refs ('<autoref identifier="foo">Foo</autoref>' , url_mapper , _legacy_refs = False )
0 commit comments