Skip to content

Commit

Permalink
adding docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
PhillypHenning committed Mar 17, 2023
1 parent a3d6e7d commit 97f5369
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions scripts/tests/unit/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@


class TestGetConfigList(unittest.TestCase):
"""Test parser.py get_config_list function"""

def setUp(self):
self.root_dir = os.getcwd()

def test_get_config_list_valid_inputs(self):
"""Test parser.py get_config_list function with valid inputs"""
config_file = "example.config.yaml"
schema_file = "example.schema.yaml"
cli_config_list, options_config_list = get_config_list(
Expand All @@ -33,20 +36,18 @@ def test_get_config_list_valid_inputs(self):
self.assertIsInstance(options_config_list, list)

def test_get_config_list_invalid_file(self):
"""Test parser.py get_config_list function with invalid inputs"""
config_file = "invalid_config.yml"
schema_file = "invalid_schema.yml"
with self.assertRaises(FileNotFoundError):
get_config_list(config_file, schema_file)

# def test_get_config_list_missing_required_config(self):
# config_file = "config.yml"
# schema_file = "schema.yml"
# with self.assertRaises(SystemExit):
# get_config_list(config_file, schema_file)


class TestConvertYamlToDict(unittest.TestCase):
"""Test parser.py convert_yaml_to_dict function"""

def test_convert_yaml_to_dict_with_null_values(self):
"""Test parser.py convert_yaml_to_dict function with null values replacement"""
# Setup
inc_yaml = {"testKey1": "testValue1", "testKey2": None}
null_replacement = "nullReplacement"
Expand All @@ -59,6 +60,7 @@ def test_convert_yaml_to_dict_with_null_values(self):
self.assertEqual(result.testKey0, "nullReplacement")

def test_convert_yaml_to_dict_without_null_values(self):
"""Test parser.py convert_yaml_to_dict function without null values replacement"""
# Setup
inc_yaml = {"testKey1": "testValue1", "testKey2": None}

Expand All @@ -69,11 +71,10 @@ def test_convert_yaml_to_dict_without_null_values(self):
self.assertEqual(result.testKey1, "testValue1")
self.assertEqual(result.testKey2, None)

# test_convert_yaml_to_dict_with_invalid_dict
# Function not needed. DefaultMunch handles incorrect typing


class TestParseYamlKeysToList(unittest.TestCase):
"""Test parser.py parse_yaml_keys_to_list function"""

def setUp(self):
self.valid_schema = {
"terraform": {
Expand Down Expand Up @@ -111,6 +112,7 @@ def setUp(self):
self.root_key = "terraform"

def test_parse_yaml_keys_to_list(self):
"""Test parser.py parse_yaml_keys_to_list function"""
"""
Test parsing yaml keys to list
"""
Expand Down Expand Up @@ -142,6 +144,7 @@ def test_parse_yaml_keys_to_list(self):
self.assertIsInstance(actual_keys_list, list)

def test_parse_yaml_keys_to_list_invalid_rootkey(self):
"""Test parser.py parse_yaml_keys_to_list function with invalid rootkey"""
"""
Test prase_yaml_kwys_to_list with invalid rootkey.
Expecting KeyError
Expand All @@ -150,6 +153,7 @@ def test_parse_yaml_keys_to_list_invalid_rootkey(self):
parse_yaml_keys_to_list(self.valid_schema, "not_a_root_key")

def test_parse_yaml_keys_to_list_invalid_schema(self):
"""Test parser.py parse_yaml_keys_to_list function with invalid schema"""
"""
Test prase_yaml_kwys_to_list with invalid rootkey.
Expecting TypeError
Expand All @@ -159,6 +163,8 @@ def test_parse_yaml_keys_to_list_invalid_schema(self):


class TestGeneratePopulatedSchemaList(unittest.TestCase):
"""Test parser.py generate_populated_schema_list function"""

def setUp(self):
self.valid_schema = {
"terraform": {
Expand Down Expand Up @@ -198,6 +204,7 @@ def setUp(self):
}

def test_generate_populated_schema_list(self):
"""Test parser.py generate_populated_schema_list function"""
schema_properties_list = generate_schema_keys(self.valid_schema)
result = generate_populated_schema_list(
convert_yaml_to_dict(self.valid_schema), schema_properties_list, self.config_yaml
Expand All @@ -221,6 +228,8 @@ def test_generate_populated_schema_list(self):


class TestGenerateSchemaKeys(unittest.TestCase):
"""Test parser.py generate_schema_keys function"""

def test_schema_keys_list_not_empty(self):
"""Test that the generated schema keys list is not empty"""
schema = {
Expand All @@ -239,6 +248,8 @@ def test_schema_keys_list_contains_correct_values(self):


class TestPopulateParsedConfigurations(unittest.TestCase):
"""Test parser.py populate_parsed_configurations function"""

def setUp(self):
self.valid_schema = {
"terraform": {
Expand Down Expand Up @@ -282,6 +293,7 @@ def setUp(self):
)

def test_cli_config_list(self):
"""Test parser.py populate_parsed_configurations function - return cli list"""
cli_config_list = populate_parsed_configurations(self.schema_list)[0]
# for item in cli_config_list:
# print(item)
Expand All @@ -291,17 +303,20 @@ def test_cli_config_list(self):
cli_config_list[2]

def test_options_config_list(self):
"""Test parser.py populate_parsed_configurations function - return options list"""
options_config_list = populate_parsed_configurations(self.schema_list)[1]

self.assertEqual(options_config_list[0].schema_property_type, "options")
with self.assertRaises(IndexError):
options_config_list[1]

def test_missing_required_config_list_empty_list(self):
"""Test parser.py populate_parsed_configurations function - doesn't return required list"""
required_config_list = populate_parsed_configurations(self.schema_list)[2]
self.assertFalse(required_config_list)

def test_missing_required_config_list(self):
"""Test parser.py populate_parsed_configurations function - return required list"""
test_required_schema_value = [
SchemaObject(
"test_config",
Expand Down

0 comments on commit 97f5369

Please sign in to comment.