Skip to content

Commit

Permalink
Merge pull request #40 from EncryptEx/FEAT/unit-tests
Browse files Browse the repository at this point in the history
FEAT: Added unit tests to language JSON files
  • Loading branch information
EncryptEx authored Aug 24, 2023
2 parents ca27920 + 69e9b0d commit b62889a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Run tests

on: push

jobs:
run-tests:
runs-on: ubuntu-latest

steps:
- name: Checkout into Repository
uses: actions/checkout@v3

- name: Setup Python and cache req
uses: actions/setup-python@v4
with:
python-version: 3.10.4

- name: Run Tests
run: python tests.py
shell: sh
30 changes: 30 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# unit test

import unittest
import json
from os import listdir
from os.path import isfile, join

def jsonToDict(filename):
with open(filename) as f_in:
return(json.load(f_in))


jsonRequiredLines = ["help_description", "help_moderation_title", "user", "reason", "help_automod_title", "help_automod_description", "help_chatmod_title", "help_chatmod_description", "help_various_title", "help_various_description", "help_links_title", "help_links_description", "help_commands_title", "help_commands_description", "footer_executed_by", "hello_command", "error_deliver_msg", "automod_warn_title", "automod_warn_description", "automod_warn_footer", "automod_warn_reason", "automod_count_title", "automod_count_description", "automod_removed_title", "automod_removed_description", "automod_nothappy_title", "automod_nothappy_description", "error_404", "error_403", "whois_title", "whois_description", "error_self_ban", "punishment_default_reason", "unpunishment_default_reason", "ban_msg", "ban_title", "ban_description", "error_ban_perm", "error_self_kick", "kick_msg", "error_kick_perm", "kick_title", "kick_description", "error_self_warn", "warn_msg", "warn_title", "warn_description", "warn_no_warns", "seewarns_title", "unwarn_no_warns", "unwarn_description_msg", "unwarn_wrong_selection", "unwarn_msg", "unwarn_title", "unwarn_description", "unwarn_count_with_success", "clearwarns_msg", "clearwarns_description", "clearwarns_title", "error_automod_syntax", "automod_success_action", "error_automod", "modified", "removed", "setdelay_title", "setdelay_description", "mute_title", "mute_description", "mute_msg", "unmute_msg", "unmute_title", "unmute_description", "lock_title", "lock_description", "unlock_title", "unlock_description", "suggest_success", "hammer_invite", "hammer_link", "enabled", "disabled", "settings_module", "error_settings_syntax", "settings_title", "settings_description", "settings_enable_automod", "settings_disable_automod", "autmod_status"]

class HammerTest (unittest.TestCase):

def test_lanugages(self):
langFiles = [f for f in listdir("./langs") if isfile(join("./langs", f))]
for languageFile in langFiles:
filename = languageFile.split(".")[0]
dictionary = jsonToDict("./langs/"+languageFile)
self.assertEqual(len(dictionary.items()),88, "There's a missing line in the language json file: "+filename)
for k,v in dictionary.items():
self.assertTrue(k in jsonRequiredLines, "The line "+k+" is wrong spelled "+filename)




if __name__ == "__main__":
unittest.main()

0 comments on commit b62889a

Please sign in to comment.