Skip to content

Commit

Permalink
Converted basic tests to pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
thvitt committed Dec 20, 2017
1 parent 53c0891 commit a617550
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 31 deletions.
4 changes: 2 additions & 2 deletions requirements-dev.txt
@@ -1,6 +1,6 @@
-r requirements.txt
nose
nosexcover
pytest
pytest-cov
jupyter
sphinx
git+https://github.com/spatialaudio/nbsphinx#egg=nbsphinx
Expand Down
3 changes: 1 addition & 2 deletions test/doclist_tests.py
Expand Up @@ -3,7 +3,6 @@

from dariah_topics.doclist import PathDocList
from pathlib import Path
from nose.tools import eq_

project_path = Path(__file__).absolute().parent.parent

Expand All @@ -24,7 +23,7 @@ def setup():

def test_pdl_glob():
"""The glob created list should contain the 30 files from grenzboten_sample"""
eq_(len(grenzboten_sample), 30, msg="Not 30 texts: " + str(docs))
assert len(grenzboten_sample) == 30


def test_pdl_list():
Expand Down
4 changes: 2 additions & 2 deletions test/integration_test.py
Expand Up @@ -2,8 +2,8 @@
# -*- coding: utf-8 -*-

from subprocess import check_output, STDOUT, CalledProcessError
from nose.plugins.skip import SkipTest
from pathlib import Path
import pytest
import logging
import re

Expand All @@ -28,7 +28,7 @@ def run_notebook(notebook_name):
message = cellinfo.group(1)
logging.error(message)

@SkipTest
@pytest.mark.skip
def jupyter_lda_test():
run_notebook("IntroducingLda.ipynb")

Expand Down
6 changes: 3 additions & 3 deletions test/mallet_test.py
@@ -1,7 +1,7 @@
from nose.tools import raises
from pytest import raises
from dariah_topics.mallet import Mallet

@raises(FileNotFoundError)
def command_not_found_test():
"""When the mallet executable was not found, raise an exception."""
Mallet(executable="i_am_an_executable_that_does_not_exist")
with raises(FileNotFoundError):
Mallet(executable="i_am_an_executable_that_does_not_exist")
42 changes: 20 additions & 22 deletions test/test_fuzzy_segmenting.py
Expand Up @@ -4,7 +4,6 @@
from dariah_topics.preprocessing import segment_fuzzy, split_paragraphs, \
segment, tokenize
from functools import partial
from nose.tools import eq_
from itertools import chain
from pathlib import Path
import re
Expand Down Expand Up @@ -33,59 +32,58 @@

def test_split_paragraphs_spar():
chunked = split_paragraphs(_DEMO_SPAR)
eq_(len(chunked), 4, msg='not 4 chunks: ' + str(chunked))
assert len(chunked) == 4


def test_split_paragraphs_dpar():
chunked = split_paragraphs(_DEMO_DPAR, sep=r'\n\n')
eq_(len(chunked), 4, msg='not 4 chunks: ' + str(chunked))
assert len(chunked) == 4


def test_split_paragraphs_dpar_re():
chunked = split_paragraphs(_DEMO_DPAR, sep=re.compile(r'\n\n'))
eq_(len(chunked), 4, msg='not 4 chunks: ' + str(chunked))

assert len(chunked) == 4


def test_plain_segments():
"""segment_size chunks, zero tolerance"""
document = ("01234 "*4).split()
segments = list(segment_fuzzy(document, segment_size=5))
eq_(segments, [[['0', '1', '2', '3', '4']],
[['0', '1', '2', '3', '4']],
[['0', '1', '2', '3', '4']],
[['0', '1', '2', '3', '4']]])
assert segments ==[[['0', '1', '2', '3', '4']],
[['0', '1', '2', '3', '4']],
[['0', '1', '2', '3', '4']],
[['0', '1', '2', '3', '4']]]


def test_shorter_segments():
"""shorter segments than chunks, no tolerance"""
document = ("01234 "*4).split()
segments = list(segment_fuzzy(document, segment_size=4))
eq_(segments, [[['0', '1', '2', '3']],
[['4'], ['0', '1', '2']],
[['3', '4'], ['0', '1']],
[['2', '3', '4'], ['0']],
[['1', '2', '3', '4']]])
assert segments == [[['0', '1', '2', '3']],
[['4'], ['0', '1', '2']],
[['3', '4'], ['0', '1']],
[['2', '3', '4'], ['0']],
[['1', '2', '3', '4']]]


def test_tolerance():
"""chunk size within tolerance"""
document = ("01234 "*4).split()
segments = list(segment_fuzzy(document, segment_size=4, tolerance=1))
eq_(segments, [[['0', '1', '2', '3', '4']],
[['0', '1', '2', '3', '4']],
[['0', '1', '2', '3', '4']],
[['0', '1', '2', '3', '4']]])
assert segments == [[['0', '1', '2', '3', '4']],
[['0', '1', '2', '3', '4']],
[['0', '1', '2', '3', '4']],
[['0', '1', '2', '3', '4']]]


def test_tolerance_2():
"""segment size ~ 2*chunk_size"""
document = ("01234 "*4).split()
segments = list(segment_fuzzy(document, segment_size=8, tolerance=2))
eq_(segments, [[['0', '1', '2', '3', '4'],
['0', '1', '2', '3', '4']],
[['0', '1', '2', '3', '4'],
['0', '1', '2', '3', '4']]])
assert segments == [[['0', '1', '2', '3', '4'],
['0', '1', '2', '3', '4']],
[['0', '1', '2', '3', '4'],
['0', '1', '2', '3', '4']]]


def test_overlong_chunk():
Expand Down

0 comments on commit a617550

Please sign in to comment.