

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'

[((246, 260), 'osp.corpus.syllabus.Syllabus', 'Syllabus', (['path'], {}), '(path)\n', (254, 260), False, 'from osp.corpus.syllabus import Syllabus\n'), ((469, 483), 'osp.corpus.syllabus.Syllabus', 'Syllabus', (['path'], {}), '(path)\n', (477, 483), False, 'from osp.corpus.syllabus import Syllabus\n'), ((687, 701), 'osp.corpus.syllabus.Syllabus', 'Syllabus', (['path'], {}), '(path)\n', (695, 701), False, 'from osp.corpus.syllabus import Syllabus\n'), ((895, 909), 'osp.corpus.syllabus.Syllabus', 'Syllabus', (['path'], {}), '(path)\n', (903, 909), False, 'from osp.corpus.syllabus import Syllabus\n'), ((1133, 1147), 'osp.corpus.syllabus.Syllabus', 'Syllabus', (['path'], {}), '(path)\n', (1141, 1147), False, 'from osp.corpus.syllabus import Syllabus\n')]