File: test_url.py

package info (click to toggle)
weasyprint 67.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,896 kB
  • sloc: python: 61,025; makefile: 12
file content (32 lines) | stat: -rw-r--r-- 924 bytes parent folder | download
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
"""Test URLs."""

import re

import pytest

from .testing_utils import FakeHTML, capture_logs, resource_path


@pytest.mark.parametrize(('url', 'base_url'), [
    ('https://weasyprint.org]', resource_path('<inline HTML>')),
    ('https://weasyprint.org]', 'https://weasyprint.org]'),
    ('https://weasyprint.org/', 'https://weasyprint.org]'),
])
def test_malformed_url_link(url, base_url):
    """Test malformed URLs."""
    with capture_logs() as logs:
        pdf = FakeHTML(
            string=f'<p><a href="{url}">My Link</a></p>',
            base_url=base_url).write_pdf()

    assert len(logs) == 1
    assert "Malformed" in logs[0]
    assert "]" in logs[0]

    uris = re.findall(b'/URI \\((.*)\\)', pdf)
    types = re.findall(b'/S (/\\w*)', pdf)
    subtypes = re.findall(b'/Subtype (/\\w*)', pdf)

    assert uris.pop(0) == url.encode()
    assert subtypes.pop(0) == b'/Link'
    assert types.pop(0) == b'/URI'