-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6678b04
commit 49d24f1
Showing
6 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
75
orangecontrib/text/widgets/tests/test_owimportdocuments.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |