DzmitrySha/python-project-lvl2

View on GitHub
gendiff/formatter.py

Summary

Maintainability
A
0 mins
Test Coverage
B
83%
"""Formatter module - formatting the tree with the selected formatter"""

from gendiff.formatters import format_stylish, format_plain, format_json


def formatting(tree: dict, format_name="stylish") -> str:
    """Formatting the tree with the selected formatter."""
    formats = {
        "stylish": format_stylish,
        "plain": format_plain,
        "json": format_json,
    }
    if format_name in formats:
        return formats[format_name](tree)

    raise ValueError(f'Unknown format: {format_name}')