added testcases for messages.py
This commit is contained in:
@@ -236,6 +236,25 @@ class Message():
|
||||
tags = set(sorted(data[cls.tags_yaml_key]))
|
||||
return tags
|
||||
|
||||
@classmethod
|
||||
def tags_from_dir(cls: Type[MessageInst],
|
||||
path: pathlib.Path,
|
||||
glob: Optional[str] = None,
|
||||
prefix: Optional[str] = None) -> set[Tag]:
|
||||
"""
|
||||
Return only the tags from message files in the given directory.
|
||||
The files can be filtered using 'glob', the tags by using 'prefix'.
|
||||
"""
|
||||
tags: set[Tag] = set()
|
||||
file_iter = path.glob(glob) if glob else path.iterdir()
|
||||
for file_path in sorted(file_iter):
|
||||
if file_path.is_file():
|
||||
try:
|
||||
tags |= cls.tags_from_file(file_path, prefix)
|
||||
except MessageError as e:
|
||||
print(f"Error processing message in '{file_path}': {str(e)}")
|
||||
return tags
|
||||
|
||||
@classmethod
|
||||
def from_file(cls: Type[MessageInst], file_path: pathlib.Path,
|
||||
mfilter: Optional[MessageFilter] = None) -> Optional[MessageInst]:
|
||||
|
||||
Reference in New Issue
Block a user