Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testcase for processor import check #54

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
42 changes: 42 additions & 0 deletions tests/wrappers/elastic/elastic_processor_test.py
Original file line number Diff line number Diff line change
@@ -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()
32 changes: 32 additions & 0 deletions tests/wrappers/elastic/elastic_query_creator_test.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion tests/wrappers/spacy_processors_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions tests/wrappers/twitter_processor_test.py
Original file line number Diff line number Diff line change
@@ -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()