|
| 1 | +import pytest |
| 2 | + |
| 3 | +from pep_sphinx_extensions.pep_processor.transforms import pep_headers |
| 4 | + |
| 5 | + |
| 6 | +@pytest.mark.parametrize( |
| 7 | + "test_input, expected", |
| 8 | + [ |
| 9 | + |
| 10 | + ("[email protected]", "https://groups.google.com/g/python-tulip"), |
| 11 | + ("[email protected]", "https://mail.python.org/mailman/listinfo/db-sig"), |
| 12 | + ("[email protected]", "https://mail.python.org/pipermail/import-sig/"), |
| 13 | + ( |
| 14 | + |
| 15 | + "https://mail.python.org/archives/list/[email protected]/", |
| 16 | + ), |
| 17 | + ], |
| 18 | +) |
| 19 | +def test_generate_list_url(test_input, expected): |
| 20 | + out = pep_headers._generate_list_url(test_input) |
| 21 | + |
| 22 | + assert out == expected |
| 23 | + |
| 24 | + |
| 25 | +@pytest.mark.parametrize( |
| 26 | + "test_input, expected", |
| 27 | + [ |
| 28 | + ( |
| 29 | + "https://mail.python.org/pipermail/python-3000/2006-November/004190.html", |
| 30 | + ("Python-3000", "message"), |
| 31 | + ), |
| 32 | + ( |
| 33 | + "https://mail.python.org/archives/list/[email protected]/thread/HW2NFOEMCVCTAFLBLC3V7MLM6ZNMKP42/", |
| 34 | + ("Python-Dev", "thread"), |
| 35 | + ), |
| 36 | + ( |
| 37 | + "https://mail.python.org/mailman3/lists/capi-sig.python.org/", |
| 38 | + ("Capi-SIG", "list"), |
| 39 | + ), |
| 40 | + ( |
| 41 | + "https://mail.python.org/mailman/listinfo/web-sig", |
| 42 | + ("Web-SIG", "list"), |
| 43 | + ), |
| 44 | + ( |
| 45 | + "https://discuss.python.org/t/pep-643-metadata-for-package-source-distributions/5577", |
| 46 | + ("Discourse", "thread"), |
| 47 | + ), |
| 48 | + ( |
| 49 | + "https://discuss.python.org/c/peps/", |
| 50 | + ("PEPs Discourse", "category"), |
| 51 | + ), |
| 52 | + ], |
| 53 | +) |
| 54 | +def test_process_pretty_url(test_input, expected): |
| 55 | + out = pep_headers._process_pretty_url(test_input) |
| 56 | + |
| 57 | + assert out == expected |
| 58 | + |
| 59 | + |
| 60 | +@pytest.mark.parametrize( |
| 61 | + "test_input, expected", |
| 62 | + [ |
| 63 | + ( |
| 64 | + "https://example.com/", |
| 65 | + "https://example.com/ not a link to a recognized domain to prettify", |
| 66 | + ), |
| 67 | + ( |
| 68 | + "https://mail.python.org", |
| 69 | + "https://mail.python.org not a link to a list, message or thread", |
| 70 | + ), |
| 71 | + ( |
| 72 | + "https://discuss.python.org/", |
| 73 | + "https://discuss.python.org not a link to a Discourse thread or category", |
| 74 | + ), |
| 75 | + ], |
| 76 | +) |
| 77 | +def test_process_pretty_url_invalid(test_input, expected): |
| 78 | + with pytest.raises(ValueError, match=expected): |
| 79 | + pep_headers._process_pretty_url(test_input) |
| 80 | + |
| 81 | + |
| 82 | +@pytest.mark.parametrize( |
| 83 | + "test_input, expected", |
| 84 | + [ |
| 85 | + ( |
| 86 | + "https://mail.python.org/pipermail/python-3000/2006-November/004190.html", |
| 87 | + "Python-3000 message", |
| 88 | + ), |
| 89 | + ( |
| 90 | + "https://mail.python.org/archives/list/[email protected]/thread/HW2NFOEMCVCTAFLBLC3V7MLM6ZNMKP42/", |
| 91 | + "Python-Dev thread", |
| 92 | + ), |
| 93 | + ( |
| 94 | + "https://mail.python.org/mailman3/lists/capi-sig.python.org/", |
| 95 | + "Capi-SIG list", |
| 96 | + ), |
| 97 | + ( |
| 98 | + "https://mail.python.org/mailman/listinfo/web-sig", |
| 99 | + "Web-SIG list", |
| 100 | + ), |
| 101 | + ( |
| 102 | + "https://discuss.python.org/t/pep-643-metadata-for-package-source-distributions/5577", |
| 103 | + "Discourse thread", |
| 104 | + ), |
| 105 | + ( |
| 106 | + "https://discuss.python.org/c/peps/", |
| 107 | + "PEPs Discourse category", |
| 108 | + ), |
| 109 | + ], |
| 110 | +) |
| 111 | +def test_make_link_pretty(test_input, expected): |
| 112 | + out = pep_headers._make_link_pretty(test_input) |
| 113 | + |
| 114 | + assert out == expected |
0 commit comments