diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8878c11..1ff3d8c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -85,9 +85,10 @@ jobs: - { dep: spacy, testfile: tests/wrappers/spacy_processors_test.py } - { dep: stanza, testfile: tests/wrappers/stanfordnlp_processor_test.py } - { dep: "nltk gpt2", extra: "termcolor>=1.1.0", testfile: examples/gpt2_test.py } - - { dep: elastic, testfile: tests/wrappers/elastic_indexers_test.py } + - { dep: elastic, testfile: tests/wrappers/elastic } - { dep: faiss, testfile: tests/wrappers/faiss_indexers_test.py } - { dep: "huggingface nltk", testfile: tests/wrappers/huggingface } + - { dep: tweepy, testfile: tests/wrappers/twitter_processor_test.py } steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} diff --git a/tests/wrappers/elastic_indexers_test.py b/tests/wrappers/elastic/elastic_indexers_test.py similarity index 100% rename from tests/wrappers/elastic_indexers_test.py rename to tests/wrappers/elastic/elastic_indexers_test.py diff --git a/tests/wrappers/elastic/elastic_processor_test.py b/tests/wrappers/elastic/elastic_processor_test.py new file mode 100644 index 0000000..04ea02e --- /dev/null +++ b/tests/wrappers/elastic/elastic_processor_test.py @@ -0,0 +1,42 @@ +import unittest +from ddt import ddt +from forte.data.multi_pack import MultiPack +from forte.data.readers import MultiPackTerminalReader +from forte.data.data_pack import DataPack +from forte.pipeline import Pipeline +from forte.data.readers import StringReader +from forte.elastic import ElasticSearchProcessor, \ + ElasticSearchPackIndexProcessor, ElasticSearchTextIndexProcessor + + +@ddt +class TestElasticSearchProcessor(unittest.TestCase): + def setUp(self): + self.nlp: Pipeline[MultiPack] = Pipeline() + self.nlp.set_reader(reader=MultiPackTerminalReader()) + + def test_init(self): + self.nlp.add(ElasticSearchProcessor()) + self.nlp.initialize() + + +@ddt +class TestElasticSearchPackIndexProcessor(unittest.TestCase): + def setUp(self): + self.nlp = Pipeline[DataPack]() + self.nlp.set_reader(StringReader()) + + def test_init(self): + self.nlp.add(ElasticSearchPackIndexProcessor()) + self.nlp.initialize() + + +@ddt +class TestElasticSearchTextIndexProcessor(unittest.TestCase): + def setUp(self): + self.nlp = Pipeline[DataPack]() + self.nlp.set_reader(StringReader()) + + def test_init(self): + self.nlp.add(ElasticSearchTextIndexProcessor()) + self.nlp.initialize() \ No newline at end of file diff --git a/tests/wrappers/elastic/elastic_query_creator_test.py b/tests/wrappers/elastic/elastic_query_creator_test.py new file mode 100644 index 0000000..a284a82 --- /dev/null +++ b/tests/wrappers/elastic/elastic_query_creator_test.py @@ -0,0 +1,32 @@ +from ddt import ddt, data +import unittest +from forte.data.caster import MultiPackBoxer +from forte.elastic import ElasticSearchQueryCreator +from forte.data.data_pack import DataPack +from forte.pipeline import Pipeline +from forte.data.readers import StringReader +from forte.data.ontology.top import Query + + +@ddt +class TestElasticSearchQueryCreator(unittest.TestCase): + def setUp(self): + self.nlp = Pipeline[DataPack]() + self.nlp.set_reader(StringReader()) + self.nlp.add(MultiPackBoxer(), config={'pack_name': "query"}) + self.nlp.add(ElasticSearchQueryCreator(), + config={"size": 1, + "field": "content", + "query_pack_name": "query" + }) + self.nlp.initialize() + + @data("test") + def test_process_query(self, query): + m_pack = self.nlp.process_one([query]) + + query_pack = m_pack.get_pack("query") + test_query = query_pack.get_single(Query) + + self.assertEqual({'query': {'match': {'content': query}}, 'size': 1}, + test_query.value) diff --git a/tests/wrappers/spacy_processors_test.py b/tests/wrappers/spacy_processors_test.py index f20c54c..9093d56 100644 --- a/tests/wrappers/spacy_processors_test.py +++ b/tests/wrappers/spacy_processors_test.py @@ -21,7 +21,7 @@ import spacy from spacy.language import Language -from forte.common import ProcessExecutionException, ProcessorConfigError +from forte.common import ProcessorConfigError from forte.data.data_pack import DataPack from forte.data.readers import StringReader from forte.pipeline import Pipeline diff --git a/tests/wrappers/twitter_processor_test.py b/tests/wrappers/twitter_processor_test.py new file mode 100644 index 0000000..c3baf3d --- /dev/null +++ b/tests/wrappers/twitter_processor_test.py @@ -0,0 +1,17 @@ +from ddt import ddt +import unittest +from forte.data.multi_pack import MultiPack +from forte.data.readers import MultiPackTerminalReader +from forte.pipeline import Pipeline +from forte.tweepy import TweetSearchProcessor + + +@ddt +class TestTweetSearchProcessor(unittest.TestCase): + def setUp(self): + self.nlp: Pipeline[MultiPack] = Pipeline() + self.nlp.set_reader(reader=MultiPackTerminalReader()) + + def test_init(self): + self.nlp.add(TweetSearchProcessor()) + self.nlp.initialize() \ No newline at end of file