diff --git a/weasyprint/tests/test_pdf.py b/weasyprint/tests/test_pdf.py
index 7429f235..c4cf4104 100644
--- a/weasyprint/tests/test_pdf.py
+++ b/weasyprint/tests/test_pdf.py
@@ -19,13 +19,9 @@ from ..urls import path2url
from .testing_utils import (
FakeHTML, assert_no_logs, capture_logs, resource_filename)
-# Top of the page is 297mm ~= 842pt
-TOP = 842
-# Right of the page is 210mm ~= 595pt
-RIGHT = 595
-
-# TODO: fix tests
-pdf = None
+# Top and right positions in points
+TOP = 297 * 72 / 25.4
+RIGHT = 210 * 72 / 25.4
def assert_rect_almost_equal(rect, values):
@@ -225,8 +221,7 @@ def test_links_none():
@assert_no_logs
def test_links():
- fileobj = io.BytesIO()
- FakeHTML(string='''
+ pdf = FakeHTML(string='''
a
- ''', base_url=None).write_pdf(target=fileobj)
- pdf_file = pdf.PDFFile(fileobj)
- annots = pdf_file.pages[0].get_indirect_dict_array('Annots', pdf_file)[0]
- dest = annots.get_value('Dest', '(.*)')
- assert dest == b'(lipsum)'
- names = (
- pdf_file.catalog
- .get_indirect_dict('Names', pdf_file)
- .get_indirect_dict('Dests', pdf_file)
- .byte_string).decode('ascii')
- assert_rect_almost_equal(
- re.search(
- '\\(lipsum\\) \\[\\d+ \\d+ R /XYZ (\\d+ \\d+ \\d+)]', names
- ).group(1),
- (0, TOP - 15, 0))
- assert_rect_almost_equal(
- annots.get_value('Rect', '(.*)'), (0, TOP - 15, RIGHT, TOP))
+ ''', base_url=None).write_pdf()
+ assert b'/Dest (lipsum)' in pdf
assert len(logs) == 1
+ link = re.search(
+ b'\\(lipsum\\) \\[ \\d+ 0 R /XYZ ([\\d\\.]+ [\\d\\.]+ [\\d\\.]+) ]',
+ pdf).group(1)
+ assert [float(number) for number in link.split()] == [0, TOP - 15, 0]
+ rect = re.search(
+ b'/Rect \\[ ([\\d\\.]+ [\\d\\.]+ [\\d\\.]+ [\\d\\.]+) \\]',
+ pdf).group(1)
+ assert [float(number) for number in rect.split()] == [
+ 0, TOP, RIGHT, TOP - 15]
assert 'ERROR: No anchor #missing for internal URI reference' in logs[0]