# coding: utf-8

import io
import cairo  # pycairo
import cairocffi

from pycairo_to_cairocffi import _UNSAFE_pycairo_context_to_cairocffi
from cairocffi_to_pycairo import _UNSAFE_cairocffi_context_to_pycairo
import pango_example


def test():
    cairocffi_context = cairocffi.Context(cairocffi.PDFSurface(None, 10, 20))
    cairocffi_context.scale(2, 3)
    pycairo_context = _UNSAFE_cairocffi_context_to_pycairo(cairocffi_context)
    cairocffi_context2 = _UNSAFE_pycairo_context_to_cairocffi(pycairo_context)
    assert tuple(cairocffi_context.get_matrix()) == (2, 0, 0, 3, 0, 0)
    assert tuple(cairocffi_context2.get_matrix()) == (2, 0, 0, 3, 0, 0)
    assert tuple(pycairo_context.get_matrix()) == (2, 0, 0, 3, 0, 0)
    assert cairocffi_context2._pointer == cairocffi_context._pointer

    file_obj = io.BytesIO()
    # Mostly test that this runs without raising.
    pango_example.write_example_pdf(file_obj)
    assert file_obj.getvalue().startswith(b'%PDF')


if __name__ == '__main__':
    test()

[((15, 22, 15, 77), 'cairocffi_to_pycairo._UNSAFE_cairocffi_context_to_pycairo', '_UNSAFE_cairocffi_context_to_pycairo', ({(15, 59, 15, 76): 'cairocffi_context'}, {}), '(cairocffi_context)', False, 'from cairocffi_to_pycairo import _UNSAFE_cairocffi_context_to_pycairo\n'), ((16, 25, 16, 78), 'pycairo_to_cairocffi._UNSAFE_pycairo_context_to_cairocffi', '_UNSAFE_pycairo_context_to_cairocffi', ({(16, 62, 16, 77): 'pycairo_context'}, {}), '(pycairo_context)', False, 'from pycairo_to_cairocffi import _UNSAFE_pycairo_context_to_cairocffi\n'), ((22, 15, 22, 27), 'io.BytesIO', 'io.BytesIO', ({}, {}), '()', False, 'import io\n'), ((24, 4, 24, 45), 'pango_example.write_example_pdf', 'pango_example.write_example_pdf', ({(24, 36, 24, 44): 'file_obj'}, {}), '(file_obj)', False, 'import pango_example\n'), ((13, 42, 13, 76), 'cairocffi.PDFSurface', 'cairocffi.PDFSurface', ({(13, 63, 13, 67): 'None', (13, 69, 13, 71): '10', (13, 73, 13, 75): '20'}, {}), '(None, 10, 20)', False, 'import cairocffi\n')]