from dqc_wrapper.utils.utils_pdf import *
from dqc_wrapper.unit_tests.conftest import dirs
from reportlab.pdfgen import canvas
from reportlab.pdfgen.textobject import PDFTextObject
from pathlib import Path


def test_save_pdf_report():
    res = save_pdf_report('test', 'test.ini', dirs.log_file)
    assert Path(res).exists()
    Path(res).unlink()


def test_filter_config():
    res = filter_config(Path(dirs.test_dir, '..', 'conf', 'conf_test00_1.ini'), 'general')
    assert 'input' in res


def test_filter_page():
    res = filter_page('test', 'test 1 \n sdf 2 ')
    assert 'test' in res


def test_init_page():
    c = canvas.Canvas('test.pdf')
    res = init_page(c, 12)
    assert type(res) == PDFTextObject


def test_write_page():
    c = canvas.Canvas('test.pdf')
    res = write_page(c, PDFTextObject(c), PDFTextObject(c), 'test', 15)
    assert type(res[0]) == PDFTextObject and type(res[1]) == PDFTextObject