

from osp.corpus.syllabus import Syllabus
from osp.test.utils import requires_tika


def test_empty(mock_osp):

    """
    Should return None if the file is empty.
    """

    path = mock_osp.add_file(content='', ftype='plain')
    syllabus = Syllabus(path)

    assert syllabus.text == None


def test_plaintext(mock_osp):

    """
    Should extract text from vanilla text files.
    """

    path = mock_osp.add_file(content='text', ftype='plain')
    syllabus = Syllabus(path)

    assert syllabus.text == 'text'


def test_html(mock_osp):

    """
    Should extract text from HTML files.
    """

    path = mock_osp.add_file(content='<p>text</p>', ftype='html')
    syllabus = Syllabus(path)

    assert syllabus.text == 'text'


def test_pdf(mock_osp):

    """
    Should extract text from PDF files.
    """

    path = mock_osp.add_file(content='text', ftype='pdf')
    syllabus = Syllabus(path)

    assert syllabus.text.strip() == 'text'


@requires_tika
def test_office(mock_osp):

    """
    Should extract text from office files.
    """

    path = mock_osp.add_file(content='text', ftype='docx')
    syllabus = Syllabus(path)

    assert syllabus.text.strip() == 'text'

[((14, 15, 14, 29), 'osp.corpus.syllabus.Syllabus', 'Syllabus', ({(14, 24, 14, 28): 'path'}, {}), '(path)', False, 'from osp.corpus.syllabus import Syllabus\n'), ((26, 15, 26, 29), 'osp.corpus.syllabus.Syllabus', 'Syllabus', ({(26, 24, 26, 28): 'path'}, {}), '(path)', False, 'from osp.corpus.syllabus import Syllabus\n'), ((38, 15, 38, 29), 'osp.corpus.syllabus.Syllabus', 'Syllabus', ({(38, 24, 38, 28): 'path'}, {}), '(path)', False, 'from osp.corpus.syllabus import Syllabus\n'), ((50, 15, 50, 29), 'osp.corpus.syllabus.Syllabus', 'Syllabus', ({(50, 24, 50, 28): 'path'}, {}), '(path)', False, 'from osp.corpus.syllabus import Syllabus\n'), ((63, 15, 63, 29), 'osp.corpus.syllabus.Syllabus', 'Syllabus', ({(63, 24, 63, 28): 'path'}, {}), '(path)', False, 'from osp.corpus.syllabus import Syllabus\n')]