| 1 | from pathlib import Path |
| 2 | |
| 3 | import pytest |
| 4 | |
| 5 | from linkify_it import LinkifyIt |
| 6 | |
| 7 | from .utils import read_fixture_file |
| 8 | |
| 9 | FIXTURE_PATH = Path(__file__).parent / "fixtures" |
| 10 | |
| 11 | |
| 12 | def dummy(_): |
| 13 | pass |
| 14 | |
| 15 | |
| 16 | @pytest.mark.parametrize( |
| 17 | "number,line,expected", |
| 18 | read_fixture_file(FIXTURE_PATH.joinpath("links.txt")), |
| 19 | ) |
| 20 | def test_links(number, line, expected): |
| 21 | linkifyit = LinkifyIt(options={"fuzzy_ip": True}) |
| 22 | |
| 23 | linkifyit.normalize = dummy |
| 24 | |
| 25 | assert linkifyit.pretest(line) is True |
| 26 | assert linkifyit.test("\n" + line + "\n") is True |
| 27 | assert linkifyit.test(line) is True |
| 28 | assert linkifyit.match(line)[0].url == expected |
| 29 | |
| 30 | |
| 31 | @pytest.mark.parametrize( |
| 32 | "number,line,expected", |
| 33 | read_fixture_file(FIXTURE_PATH.joinpath("not_links.txt")), |
| 34 | ) |
| 35 | def test_not_links(number, line, expected): |
| 36 | linkifyit = LinkifyIt() |
| 37 | |
| 38 | linkifyit.normalize = dummy |
| 39 | |
| 40 | assert linkifyit.test(line) is False |