Skip to content

Commit

Permalink
Add python scripts for checking missing triggers and effects
Browse files Browse the repository at this point in the history
  • Loading branch information
Pelmen323 committed Jun 25, 2024
1 parent 1de306c commit 552f2ea
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/test_check_missing_effects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import re
import glob
import json

path_to_config = "Config\\"
path_to_documentation = "Config\\script_documentation.json"

# 1 Extract effects from documentation
documentation_dict = json.load(open(path_to_documentation))
list_with_effects_documentation = [i for i in documentation_dict['effects'].keys()]


# 2 Extract effects from config files
list_with_effects_config = []
effect_pattern = r'alias\[effect:(.*?)\]'
for filename in glob.iglob(path_to_config + "**/*.cwt", recursive=True):
with open(filename, 'r') as text_file:
config_file = text_file.read()

if 'alias[effect:' in config_file:
pattern_matches = re.findall(effect_pattern, config_file)
if len(pattern_matches) > 0:
for match in pattern_matches:
list_with_effects_config.append(match)

# 3 Perform a comparison
list_with_effects_config = set(list_with_effects_config)
results_missing_effects = [i for i in list_with_effects_documentation if i not in list_with_effects_config]

if len(results_missing_effects) > 0:
for i in results_missing_effects:
print(f'- [] - {i}')
raise Exception("There are effects in documentation file that are not present in .cwt files")
33 changes: 33 additions & 0 deletions tests/test_check_missing_triggers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import re
import glob
import json

path_to_config = "Config\\"
path_to_documentation = "Config\\script_documentation.json"

# 1 Extract triggers from documentation
documentation_dict = json.load(open(path_to_documentation))
list_with_triggers_documentation = [i for i in documentation_dict['triggers'].keys()]


# 2 Extract triggers from config files
list_with_triggers_config = []
effect_pattern = r'alias\[trigger:(.*?)\]'
for filename in glob.iglob(path_to_config + "**/*.cwt", recursive=True):
with open(filename, 'r') as text_file:
config_file = text_file.read()

if 'alias[trigger:' in config_file:
pattern_matches = re.findall(effect_pattern, config_file)
if len(pattern_matches) > 0:
for match in pattern_matches:
list_with_triggers_config.append(match)

# 3 Perform a comparison
list_with_triggers_config = set(list_with_triggers_config)
results_missing_triggers = [i for i in list_with_triggers_documentation if i not in list_with_triggers_config]

if len(results_missing_triggers) > 0:
for i in results_missing_triggers:
print(f'- [] - {i}')
raise Exception("There are triggers in documentation file that are not present in .cwt files")

0 comments on commit 552f2ea

Please sign in to comment.