Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ajdapretnar committed Oct 30, 2020
1 parent 602f778 commit e07ac66
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 6 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ recursive-include orangecontrib/text/tests *.txt *.json
recursive-include orangecontrib/text/tutorials *.ows
recursive-include orangecontrib/text/widgets/icons *.svg *.png *.ai
recursive-include orangecontrib/text/widgets/resources *.js *.css *.html
recursive-include orangecontrib/text/widgets/tests/data
include orangecontrib/text/widgets/tests/bow-test
recursive-include scripts *.sh *.py

Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a test txt_ž file
1 change: 0 additions & 1 deletion orangecontrib/text/widgets/tests/data/good/sample_txt.txt

This file was deleted.

5 changes: 5 additions & 0 deletions orangecontrib/text/widgets/tests/data/sentiment/neg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
bad
ugly
sad
random
quasi
5 changes: 5 additions & 0 deletions orangecontrib/text/widgets/tests/data/sentiment/pos.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
good
nice
great
human
user
Empty file.
Empty file.
10 changes: 5 additions & 5 deletions orangecontrib/text/widgets/tests/test_owimportdocuments.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
class TestOWImportDocuments(WidgetTest):
def setUp(self) -> None:
self.widget: OWImportDocuments = self.create_widget(OWImportDocuments)
path = os.path.join(os.path.dirname(__file__), "data")
path = os.path.join(os.path.dirname(__file__), "data/documents")
self.widget.setCurrentPath(path)
self.widget.reload()
self.wait_until_finished()

def test_current_path(self):
path = os.path.join(os.path.dirname(__file__), "data")
path = os.path.join(os.path.dirname(__file__), "data/documents")
self.assertEqual(path, self.widget.currentPath)

def test_no_skipped(self):
path = os.path.join(os.path.dirname(__file__), "data", "good")
path = os.path.join(os.path.dirname(__file__), "data/documents", "good")
self.widget.setCurrentPath(path)
self.widget.reload()
self.wait_until_finished()
Expand All @@ -30,14 +30,14 @@ def test_output(self):
self.assertEqual(3, len(output.domain.metas))
names = output.get_column_view("name")[0]
self.assertListEqual(
["sample_docx", "sample_odt", "sample_pdf", "sample_txt"],
["sample_docx", "sample_odt", "sample_pdf", "sample_txt_ž"],
sorted(names.tolist()),
)
texts = output.get_column_view("content")[0]
self.assertListEqual(
[
f"This is a test {x} file"
for x in ["docx", "odt", "pdf", "txt"]
for x in ["docx", "odt", "pdf", "txt_ž"]
],
sorted([x.strip() for x in texts.tolist()]),
)
Expand Down
15 changes: 15 additions & 0 deletions orangecontrib/text/widgets/tests/test_owsentimentanalysis.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import os
import numpy as np

from unittest import mock, skip
from unittest.mock import patch

Expand Down Expand Up @@ -39,6 +42,18 @@ def test_output(self):
out_corpus = self.get_output(self.widget.Outputs.corpus)
self.assertEqual(len(out_corpus.domain), len(self.corpus.domain) + 1)

# test custom files
self.widget.pos_file = os.path.join(os.path.dirname(__file__),
"data/sentiment/pos.txt")
self.widget.neg_file = os.path.join(os.path.dirname(__file__),
"data/sentiment/neg.txt")
self.widget.custom_list.click()
out_corpus = self.get_output(self.widget.Outputs.corpus)
self.assertEqual(len(out_corpus.domain), len(self.corpus.domain) + 1)
res = np.array([[0], [10], [16.66666667], [12.5], [11.11111111],
[-14.28571429], [0], [-10], [0]])
np.testing.assert_array_almost_equal(out_corpus.X, res, decimal=8)

def test_language_changed(self):
"""Test if output changes on language change"""
self.send_signal(self.widget.Inputs.corpus, self.corpus)
Expand Down

0 comments on commit e07ac66

Please sign in to comment.