From e07ac66e8fe7bc9647241a515d92af7b012a33d4 Mon Sep 17 00:00:00 2001 From: Ajda Pretnar Date: Mon, 14 Sep 2020 15:43:38 +0200 Subject: [PATCH] Tests --- MANIFEST.in | 1 + orangecontrib/text/widgets/tests/bow-test | 0 .../corrupted/sample_pdf_corrupted.pdf | Bin .../data/{ => documents}/good/sample_docx.docx | Bin .../data/{ => documents}/good/sample_odt.odt | Bin .../data/{ => documents}/good/sample_pdf.pdf | Bin .../data/documents/good/sample_txt_\305\276.txt" | 1 + .../text/widgets/tests/data/good/sample_txt.txt | 1 - .../text/widgets/tests/data/sentiment/neg.txt | 5 +++++ .../text/widgets/tests/data/sentiment/pos.txt | 5 +++++ orangecontrib/text/widgets/tests/neg.txt | 0 orangecontrib/text/widgets/tests/pos.txt | 0 .../text/widgets/tests/test_owimportdocuments.py | 10 +++++----- .../widgets/tests/test_owsentimentanalysis.py | 15 +++++++++++++++ 14 files changed, 32 insertions(+), 6 deletions(-) delete mode 100644 orangecontrib/text/widgets/tests/bow-test rename orangecontrib/text/widgets/tests/data/{ => documents}/corrupted/sample_pdf_corrupted.pdf (100%) rename orangecontrib/text/widgets/tests/data/{ => documents}/good/sample_docx.docx (100%) rename orangecontrib/text/widgets/tests/data/{ => documents}/good/sample_odt.odt (100%) rename orangecontrib/text/widgets/tests/data/{ => documents}/good/sample_pdf.pdf (100%) create mode 100644 "orangecontrib/text/widgets/tests/data/documents/good/sample_txt_\305\276.txt" delete mode 100644 orangecontrib/text/widgets/tests/data/good/sample_txt.txt create mode 100644 orangecontrib/text/widgets/tests/data/sentiment/neg.txt create mode 100644 orangecontrib/text/widgets/tests/data/sentiment/pos.txt delete mode 100644 orangecontrib/text/widgets/tests/neg.txt delete mode 100644 orangecontrib/text/widgets/tests/pos.txt diff --git a/MANIFEST.in b/MANIFEST.in index 818829182..609845b9d 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -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 diff --git a/orangecontrib/text/widgets/tests/bow-test b/orangecontrib/text/widgets/tests/bow-test deleted file mode 100644 index e69de29bb..000000000 diff --git a/orangecontrib/text/widgets/tests/data/corrupted/sample_pdf_corrupted.pdf b/orangecontrib/text/widgets/tests/data/documents/corrupted/sample_pdf_corrupted.pdf similarity index 100% rename from orangecontrib/text/widgets/tests/data/corrupted/sample_pdf_corrupted.pdf rename to orangecontrib/text/widgets/tests/data/documents/corrupted/sample_pdf_corrupted.pdf diff --git a/orangecontrib/text/widgets/tests/data/good/sample_docx.docx b/orangecontrib/text/widgets/tests/data/documents/good/sample_docx.docx similarity index 100% rename from orangecontrib/text/widgets/tests/data/good/sample_docx.docx rename to orangecontrib/text/widgets/tests/data/documents/good/sample_docx.docx diff --git a/orangecontrib/text/widgets/tests/data/good/sample_odt.odt b/orangecontrib/text/widgets/tests/data/documents/good/sample_odt.odt similarity index 100% rename from orangecontrib/text/widgets/tests/data/good/sample_odt.odt rename to orangecontrib/text/widgets/tests/data/documents/good/sample_odt.odt diff --git a/orangecontrib/text/widgets/tests/data/good/sample_pdf.pdf b/orangecontrib/text/widgets/tests/data/documents/good/sample_pdf.pdf similarity index 100% rename from orangecontrib/text/widgets/tests/data/good/sample_pdf.pdf rename to orangecontrib/text/widgets/tests/data/documents/good/sample_pdf.pdf diff --git "a/orangecontrib/text/widgets/tests/data/documents/good/sample_txt_\305\276.txt" "b/orangecontrib/text/widgets/tests/data/documents/good/sample_txt_\305\276.txt" new file mode 100644 index 000000000..bebea4019 --- /dev/null +++ "b/orangecontrib/text/widgets/tests/data/documents/good/sample_txt_\305\276.txt" @@ -0,0 +1 @@ +This is a test txt_ž file \ No newline at end of file diff --git a/orangecontrib/text/widgets/tests/data/good/sample_txt.txt b/orangecontrib/text/widgets/tests/data/good/sample_txt.txt deleted file mode 100644 index 2e500dafc..000000000 --- a/orangecontrib/text/widgets/tests/data/good/sample_txt.txt +++ /dev/null @@ -1 +0,0 @@ -This is a test txt file \ No newline at end of file diff --git a/orangecontrib/text/widgets/tests/data/sentiment/neg.txt b/orangecontrib/text/widgets/tests/data/sentiment/neg.txt new file mode 100644 index 000000000..2d1a9c1a5 --- /dev/null +++ b/orangecontrib/text/widgets/tests/data/sentiment/neg.txt @@ -0,0 +1,5 @@ +bad +ugly +sad +random +quasi \ No newline at end of file diff --git a/orangecontrib/text/widgets/tests/data/sentiment/pos.txt b/orangecontrib/text/widgets/tests/data/sentiment/pos.txt new file mode 100644 index 000000000..3872e3e50 --- /dev/null +++ b/orangecontrib/text/widgets/tests/data/sentiment/pos.txt @@ -0,0 +1,5 @@ +good +nice +great +human +user \ No newline at end of file diff --git a/orangecontrib/text/widgets/tests/neg.txt b/orangecontrib/text/widgets/tests/neg.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/orangecontrib/text/widgets/tests/pos.txt b/orangecontrib/text/widgets/tests/pos.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/orangecontrib/text/widgets/tests/test_owimportdocuments.py b/orangecontrib/text/widgets/tests/test_owimportdocuments.py index 4c5ab5c2e..98f74759c 100644 --- a/orangecontrib/text/widgets/tests/test_owimportdocuments.py +++ b/orangecontrib/text/widgets/tests/test_owimportdocuments.py @@ -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() @@ -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()]), ) diff --git a/orangecontrib/text/widgets/tests/test_owsentimentanalysis.py b/orangecontrib/text/widgets/tests/test_owsentimentanalysis.py index ba2480387..7dfc7dfe3 100644 --- a/orangecontrib/text/widgets/tests/test_owsentimentanalysis.py +++ b/orangecontrib/text/widgets/tests/test_owsentimentanalysis.py @@ -1,3 +1,6 @@ +import os +import numpy as np + from unittest import mock, skip from unittest.mock import patch @@ -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)