From 0544d891a910bfe40fa58a27de134081c98095b5 Mon Sep 17 00:00:00 2001 From: Ana Hoffmann Date: Mon, 3 Jul 2023 13:04:23 -0300 Subject: [PATCH] (#105) Adding tests to pre-processing parser and annotate parser --- tests/parser/test_YAML_parser.py | 9 +++-- tests/parser/test_annotate_parser.py | 9 +++-- tests/parser/test_pre_processing_parser.py | 39 ++++++++++++++++++++++ 3 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 tests/parser/test_pre_processing_parser.py diff --git a/tests/parser/test_YAML_parser.py b/tests/parser/test_YAML_parser.py index 4ec1709f..b60ac948 100644 --- a/tests/parser/test_YAML_parser.py +++ b/tests/parser/test_YAML_parser.py @@ -1,3 +1,4 @@ +import yaml from hygia.parser.YAML_parser import YAMLParser class TestYamlParser(): @@ -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' @@ -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) diff --git a/tests/parser/test_annotate_parser.py b/tests/parser/test_annotate_parser.py index c2da767f..5491987a 100644 --- a/tests/parser/test_annotate_parser.py +++ b/tests/parser/test_annotate_parser.py @@ -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}}}] @@ -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 @@ -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 @@ -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 diff --git a/tests/parser/test_pre_processing_parser.py b/tests/parser/test_pre_processing_parser.py new file mode 100644 index 00000000..ac25e2a7 --- /dev/null +++ b/tests/parser/test_pre_processing_parser.py @@ -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