Skip to content

Commit

Permalink
test: Add a unit test to verify buddy error codes
Browse files Browse the repository at this point in the history
BFW-5773
  • Loading branch information
Tomcus committed Aug 9, 2024
1 parent 76ef834 commit c7e4712
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tests/test_verify_buddy_errors_content.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import unittest
import yaml
from typing import List, Dict

class TestVerifyPruseErrorContentsForBuddy(unittest.TestCase):
def verify_item_in_error(self, error: Dict, item_name: str, can_be_empty:bool = False):
assert item_name in error, f"Missing item {item_name} in error code {error['code']}"
if not can_be_empty:
assert len(error[item_name]) > 0, f"Item {item_name} in error code {error['code']} is empty"

def verify_non_empty_array_item(self, error: Dict, item_name: str, is_optional: bool = False):
assert item_name in error or is_optional, f"Missing item {item_name} in error code {error['code']}"
if (is_optional and item_name in error) or not is_optional:
assert len(error[item_name]) > 0, f"Empty array item {item_name} defined in error code {error['code']}"

def test_buddy_errors(self):
errors = []
with open("./yaml/buddy-error-codes.yaml", "r") as buddy_errors:
errors = yaml.load(buddy_errors, Loader=yaml.Loader)["Errors"]
for error in errors:
assert "code" in error, f"Missing error code code in definition: {error}"
assert error["code"].startswith("XX"), f"Code {error['code']} is missing XX prefix"
self.verify_item_in_error(error, "id")
self.verify_item_in_error(error, "title")
self.verify_item_in_error(error, "text")
self.verify_non_empty_array_item(error, "printers", True)


def test_mmu_errors(self):
errors = []
with open("./yaml/mmu-error-codes.yaml", "r") as mmu_errors:
errors = yaml.load(mmu_errors, Loader=yaml.Loader)["Errors"]
for error in errors:
assert "code" in error, f"Missing error code code in definition: {error}"
assert error["code"].startswith("04"), f"Code {error['code']} is missing 04 prefix"
self.verify_item_in_error(error, "id")
self.verify_item_in_error(error, "title")
self.verify_item_in_error(error, "text")
self.verify_item_in_error(error, "type")
self.verify_non_empty_array_item(error, "action")

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

0 comments on commit c7e4712

Please sign in to comment.