Skip to content

Commit

Permalink
OWImportDocuments: add unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
PrimozGodec committed Aug 31, 2020
1 parent 6678b04 commit 49d24f1
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 0 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions orangecontrib/text/widgets/tests/data/sample_txt.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a test txt file
75 changes: 75 additions & 0 deletions orangecontrib/text/widgets/tests/test_owimportdocuments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import os
import unittest

from Orange.widgets.tests.base import WidgetTest
from orangecontrib.text.widgets.owimportdocuments import OWImportDocuments


class TestOWImportDocuments(WidgetTest):
def setUp(self) -> None:
self.widget: OWImportDocuments = self.create_widget(OWImportDocuments)
path = os.path.join(os.path.dirname(__file__), "data")
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")
self.assertEqual(path, self.widget.currentPath)

def test_output(self):
output = self.get_output(self.widget.Outputs.data)
self.assertEqual(4, len(output))
self.assertEqual(3, len(output.domain.metas))
names = output.get_column_view("name")[0]
self.assertListEqual(
["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"]
],
sorted([x.strip() for x in texts.tolist()]),
)
self.assertEqual("content", output.text_features[0].name)

skipped_output = self.get_output(self.widget.Outputs.skipped_documents)
self.assertEqual(1, len(skipped_output))
self.assertEqual(2, len(skipped_output.domain.metas))
names = skipped_output.get_column_view("name")[0]
self.assertListEqual(
["sample_pdf_corrupted.pdf"],
sorted(names.tolist()),
)

def test_could_not_be_read_warning(self):
"""
sample_pdf_corrupted.pdf is corrupted file and cannot be loaded
correctly - widget must show the warning
"""
self.assertTrue(self.widget.Warning.read_error.is_shown())
self.assertEqual(
"One file couldn't be read.",
str(self.widget.Warning.read_error),
)

def test_send_report(self):
self.widget.send_report()

def test_info_box(self):
self.assertEqual(
"4 documents, 1 skipped", self.widget.info_area.text()
)

# empty widget
self.widget: OWImportDocuments = self.create_widget(OWImportDocuments)
self.assertEqual(
"No document set selected", self.widget.info_area.text()
)


if __name__ == "__main__":
unittest.main()

0 comments on commit 49d24f1

Please sign in to comment.