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


def test_line_breaks():
    mock_str = 'a'*300
    res = line_breaks(mock_str)
    assert res.count('\n') == 2


def test_save_txt_report():
    save_txt_report(dirs.txt_file, dirs.txt_file, 'test.pdf')
    assert Path('test.pdf').exists()
    Path('test.pdf').unlink()


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, '..', 'check_tests', '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_init_title():
    c = canvas.Canvas('test.pdf')
    res = init_title(c)
    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
