Skip to content

Commit

Permalink
(#105) Adding tests to pre-processing parser and annotate parser
Browse files Browse the repository at this point in the history
  • Loading branch information
AnHoff committed Jul 3, 2023
1 parent 5c4ca01 commit 0544d89
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
9 changes: 7 additions & 2 deletions tests/parser/test_YAML_parser.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import yaml
from hygia.parser.YAML_parser import YAMLParser

class TestYamlParser():
Expand All @@ -18,7 +19,7 @@ def test_yaml_has_description(self):
assert 'description' in self.yaml
assert self.yaml['description'] == 'DAG de teste'

def test_yaml_has_feature_settings(self):
def test_yaml_has_output_folder(self):
assert 'output_folder' in self.yaml
assert self.yaml['output_folder'] == 'output'

Expand All @@ -29,12 +30,16 @@ def test_yaml_has_feature_settings(self):

def test_yaml_has_nrows(self):
assert 'nrows' in self.yaml

assert isinstance(self.yaml['nrows'], int)

def test_yaml_has_engine(self):
assert 'engine' in self.yaml
assert isinstance(self.yaml['engine'], str)

def test_yaml_has_encoding(self):
assert 'encoding' in self.yaml
assert isinstance(self.yaml['encoding'], str)

def test_yaml_has_separator(self):
assert 'separator' in self.yaml
assert isinstance(self.yaml['separator'], str)
9 changes: 4 additions & 5 deletions tests/parser/test_annotate_parser.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import pytest

from hygia.parser.annotate_data_parser import AnnotateDataParser

class TestAnnotateParser():
class TestAnnotateParser:

def setup_method(self):
self.model_data = [{'input': {'columns': ['street', 'phone'], 'thresholds': {'ksmash_sequence_vowels': 1.0, 'ksmash_sequence_consonants': 1.999, 'ksmash_sequence_special_characters': 2.2499, 'ksmash_numbers': 2.9, 'ksmash_char_frequence': 2.78}}}]
Expand Down Expand Up @@ -33,7 +32,7 @@ def test_parser_annotate_data(self):
assert 'ksmash_sequence_vowels' in thresholds
assert thresholds['ksmash_sequence_vowels'] == 1.0

def test_get_thresholds(self):
def test_get_thresholds_with_input(self):
thresholds = self.parser.get_thresholds(self.model_data[0]['input'])

assert 'ksmash_char_frequence' in thresholds
Expand All @@ -51,7 +50,7 @@ def test_get_thresholds(self):
assert 'ksmash_sequence_vowels' in thresholds
assert thresholds['ksmash_sequence_vowels'] == 1.0

def test_get_keyboard_smash_default_config(self):
def test_get_thresholds_with_input_missing_keys(self):
thresholds = self.parser.get_thresholds({'thresholds': {'ksmash_sequence_vowels': 1.1}})

assert 'ksmash_char_frequence' in thresholds
Expand All @@ -69,7 +68,7 @@ def test_get_keyboard_smash_default_config(self):
assert 'ksmash_sequence_vowels' in thresholds
assert thresholds['ksmash_sequence_vowels'] == 1.1

def test_get_keyboard_smash_default_config(self):
def test_get_thresholds_without_input(self):
thresholds = self.parser.get_thresholds()

assert 'ksmash_char_frequence' in thresholds
Expand Down
39 changes: 39 additions & 0 deletions tests/parser/test_pre_processing_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import pytest
from hygia.parser.pre_processing_parser import PreProcessingParser

class TestPreProcessingParser:

def setup_method(self):
self.columns_name = ['col1', 'col2']
self.parser = PreProcessingParser(self.columns_name)

def test_parse_pre_processing_configs_with_empty_data(self):
data = []
result = self.parser.parse(data)

assert result is None

def test_get_dataframe(self):
aliases = [{'col3': 'new_col3'}, {'col4': 'new_col4'}]
self.parser._get_dataframe(aliases)

assert 'col3' in self.parser.columns_name
assert 'col4' in self.parser.columns_name

def test_get_dataframe_with_empty_aliases(self):
aliases = []
self.parser._get_dataframe(aliases)

assert self.parser.columns_name == self.columns_name

def test_get_dataframe_with_existing_columns(self):
aliases = [{'new_col1': 'col1'}, {'new_col2': 'col2'}]
self.parser._get_dataframe(aliases)

assert self.parser.columns_name == self.columns_name

def test_get_dataframe_with_empty_aliases_and_existing_columns(self):
aliases = []
self.parser._get_dataframe(aliases)

assert self.parser.columns_name == self.columns_name

0 comments on commit 0544d89

Please sign in to comment.