Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit tests for StringSubstitutionFilter
- Loading branch information
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
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,18 @@ | ||
# Config file for unit testing StringSubstitutionFilter. | ||
|
||
[etl] | ||
chains = input_string_file|string_sub_filter|packet_buffer|output_std | ||
|
||
[input_string_file] | ||
class = inputs.fileinput.StringFileInput | ||
file_path = tests/data/stringfileinput_formatargs.txt | ||
|
||
[string_sub_filter] | ||
class = filters.stringfilter.StringSubstitutionFilter | ||
format_args = greeting:Hello name:NLExtract | ||
|
||
[packet_buffer] | ||
class = filters.packetbuffer.PacketBuffer | ||
|
||
[output_std] | ||
class = outputs.standardoutput.StandardOutput |
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,38 @@ | ||
import os | ||
|
||
from stetl.etl import ETL | ||
from stetl.filters.packetbuffer import PacketBuffer | ||
from stetl.filters.stringfilter import StringSubstitutionFilter | ||
from tests.stetl_test_case import StetlTestCase | ||
|
||
class StringSubstitutionFilterTest(StetlTestCase): | ||
"""Unit tests for StringSubstitutionFilter""" | ||
|
||
def setUp(self): | ||
super(StringSubstitutionFilterTest, self).setUp() | ||
|
||
# Initialize Stetl | ||
curr_dir = os.path.dirname(os.path.realpath(__file__)) | ||
cfg_dict = {'config_file': os.path.join(curr_dir, 'configs/stringsubstitutionfilter.cfg')} | ||
self.etl = ETL(cfg_dict) | ||
|
||
def test_class(self): | ||
chain = StetlTestCase.get_chain(self.etl) | ||
section = StetlTestCase.get_section(chain, 1) | ||
class_name = self.etl.configdict.get(section, 'class') | ||
|
||
self.assertEqual('filters.stringfilter.StringSubstitutionFilter', class_name) | ||
|
||
def test_instance(self): | ||
chain = StetlTestCase.get_chain(self.etl) | ||
|
||
self.assertTrue(isinstance(chain.get_by_index(1), StringSubstitutionFilter)) | ||
|
||
def test_execute(self): | ||
chain = StetlTestCase.get_chain(self.etl) | ||
chain.run() | ||
|
||
buffer_filter = chain.get_by_class(PacketBuffer) | ||
packet_list = buffer_filter.packet_list | ||
|
||
self.assertEqual(packet_list[0].data, 'Hello NLExtract!') |