-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add a unit test to verify buddy error codes
BFW-5773
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |