1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
from __future__ import annotations
import pytest
from sphinx.errors import ExtensionError
from sphinxext.rediraffe import create_simple_redirects
def test_create_simple_redirects_empty():
assert create_simple_redirects({}) == {}
def test_create_simple_redirects_no_cycle():
simple_redirects = redirects = {
'a': 'b',
}
assert create_simple_redirects(redirects) == simple_redirects
def test_create_simple_redirects_simple_cycle():
redirects = {
'a': 'b',
'b': 'a',
}
with pytest.raises(ExtensionError):
create_simple_redirects(redirects)
def test_create_simple_redirects_complex_cycles():
redirects = {
'a': 'b',
'b': 'c',
'c': 'd',
'd': 'e',
'e': 'a',
}
with pytest.raises(ExtensionError):
create_simple_redirects(redirects)
def test_create_simple_redirects_multiple_cycles():
redirects = {
'a': 'b',
'b': 'c',
'c': 'd',
'd': 'e',
'e': 'a',
'f': 'g',
'g': 'h',
'h': 'j',
'j': 'g',
}
with pytest.raises(ExtensionError):
create_simple_redirects(redirects)
def test_create_simple_redirects_no_chains():
simple_redirects = redirects = {
'a': 'b',
'c': 'd',
'e': 'f',
}
assert create_simple_redirects(redirects) == simple_redirects
def test_create_simple_redirects_chain():
redirects = {
'a': 'b',
'b': 'c',
'c': 'd',
}
simple_redirects = {
'a': 'd',
'b': 'd',
'c': 'd',
}
assert create_simple_redirects(redirects) == simple_redirects
def test_create_simple_redirects_mixed_chains():
redirects = {
'a': 'b',
'b': 'c',
'c': 'd',
'e': 'f',
'g': 'h',
'h': 'i',
}
simple_redirects = {
'a': 'd',
'b': 'd',
'c': 'd',
'e': 'f',
'g': 'i',
'h': 'i',
}
assert create_simple_redirects(redirects) == simple_redirects
|