Skip to content

Commit

Permalink
apply review
Browse files Browse the repository at this point in the history
  • Loading branch information
TannazVhdBMWExt committed Sep 23, 2024
1 parent 04d9c1d commit f844e84
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions lobster/tools/coda/coda.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,35 +88,36 @@ def parse_config_file(file_name: str) -> dict:
or contains not supported values.
"""
if not os.path.isfile(file_name):
raise Exception(f'{file_name} is not an existing file!')
raise ValueError(f'{file_name} is not an existing file!')

with open(file_name, "r") as file:
with open(file_name, "r", encoding='utf-8') as file:
config_dict: dict = json.loads(file.read())

if OUTPUT not in config_dict.keys():
raise Exception(f'Please follow the right config file structure! '
f'Missing attribute "{OUTPUT}"')
raise ValueError(f'Please follow the right config file structure! '
f'Missing attribute "{OUTPUT}"')

output_config_dict = config_dict.get(OUTPUT)

supported_markers = ', '.join(SUPPORTED_REQUIREMENTS)
for output_file, output_file_config_dict in output_config_dict.items():
if MARKERS not in output_file_config_dict.keys():
raise Exception(f'Please follow the right config file structure! '
f'Missing attribute "{MARKERS}" for output file '
f'"{output_file}"')
raise ValueError(f'Please follow the right config file structure! '
f'Missing attribute "{MARKERS}" for output file '
f'"{output_file}"')
if KIND not in output_file_config_dict.keys():
raise Exception(f'Please follow the right config file structure! '
f'Missing attribute "{KIND}" for output file '
f'"{output_file}"')
raise ValueError(f'Please follow the right config file structure! '
f'Missing attribute "{KIND}" for output file '
f'"{output_file}"')

output_file_marker_list = output_file_config_dict.get(MARKERS)
for output_file_marker in output_file_marker_list:
if output_file_marker not in SUPPORTED_REQUIREMENTS:
raise Exception(f'"{output_file_marker}" is not a supported '
f'"{MARKERS}" value '
f'for output file "{output_file}". '
f'Supported values are: "{supported_markers}"')
raise ValueError(f'"{output_file_marker}" is not a supported '
f'"{MARKERS}" value '
f'for output file "{output_file}". '
f'Supported values are: '
f'"{supported_markers}"')

return config_dict

Expand Down Expand Up @@ -162,10 +163,10 @@ def get_test_file_list(file_dir_list: list, extension_list: list) -> list:
if ext in extension_list:
test_file_list.append(os.path.join(path, filename))
else:
raise Exception(f'"{file_dir_entry}" is not a file or directory.')
raise ValueError(f'"{file_dir_entry}" is not a file or directory.')

if len(test_file_list) == 0:
raise Exception(f'"{file_dir_list}" does not contain any test file.')
raise ValueError(f'"{file_dir_list}" does not contain any test file.')

return test_file_list

Expand Down Expand Up @@ -225,7 +226,7 @@ def create_lobster_items_output_dict_from_test_cases(
else:
no_marker_output_file_name = output_file_name

if no_marker_output_file_name not in lobster_items_output_dict.keys():
if no_marker_output_file_name not in lobster_items_output_dict:
lobster_items_output_dict[no_marker_output_file_name] = {}

for test_case in test_case_list:
Expand Down Expand Up @@ -253,7 +254,7 @@ def create_lobster_items_output_dict_from_test_cases(
tracing_target_list = []
tracing_target_kind = output_config_dict.get(KIND)
for marker in output_config_dict.get(MARKERS):
if marker not in map_test_type_to_key_name.keys():
if marker not in map_test_type_to_key_name:
continue

for test_case_marker_value in getattr(
Expand Down Expand Up @@ -382,7 +383,7 @@ def main():
config_dict=config_dict
)

except Exception as exception:
except ValueError as exception:
ap.error(exception)


Expand Down

0 comments on commit f844e84

Please sign in to comment.