# Path: snapshottest/sorted_dict.py
# class SortedDict(OrderedDict):
#     def __init__(self, values):
#         super(SortedDict, self).__init__()
# 
#         try:
#             sorted_items = sorted(values.items())
#         except TypeError:
#             # Enums are not sortable
#             sorted_items = values.items()
#         for key, value in sorted_items:
#             if isinstance(value, dict):
#                 self[key] = SortedDict(value)
#             elif isinstance(value, list):
#                 self[key] = self._sort_list(value)
#             else:
#                 self[key] = value
# 
#     def _sort_list(self, value):
#         def sort(val):
#             if isinstance(val, dict):
#                 return SortedDict(val)
#             elif isinstance(val, list):
#                 return self._sort_list(val)
#             else:
#                 return val
# 
#         return [sort(item) for item in value]
# 
# Path: snapshottest/formatter.py
# class Formatter(object):
#     formatters = default_formatters()
# 
#     def __init__(self, imports=None):
#         self.htchar = " " * 4
#         self.lfchar = "\n"
#         self.indent = 0
#         self.imports = imports
# 
#     def __call__(self, value, **args):
#         return self.format(value, self.indent)
# 
#     def format(self, value, indent):
#         formatter = self.get_formatter(value)
#         for module, import_name in formatter.get_imports():
#             self.imports[module].add(import_name)
#         return formatter.format(value, indent, self)
# 
#     def normalize(self, value):
#         formatter = self.get_formatter(value)
#         return formatter.normalize(value, self)
# 
#     @staticmethod
#     def get_formatter(value):
#         for formatter in Formatter.formatters:
#             if formatter.can_format(value):
#                 return formatter
# 
#         # This should never happen as GenericFormatter is registered by default.
#         raise RuntimeError("No formatter found for value")
# 
#     @staticmethod
#     def register_formatter(formatter):
#         Formatter.formatters.insert(0, formatter)


from termcolor import colored
from fastdiff import compare
from .sorted_dict import SortedDict
from .formatter import Formatter



def format_line(line):
    line = line.rstrip("\n")
    if line.startswith("-"):
        return colored(line, "green", attrs=["bold"])
    elif line.startswith("+"):
        return colored(line, "red", attrs=["bold"])
    elif line.startswith("?"):
        return colored("") + colored(line, "yellow", attrs=["bold"])

    return colored("") + colored(line, "white", attrs=["dark"])


class PrettyDiff(object):
    def __init__(self, obj, snapshottest):
        self.pretty = Formatter()
        self.snapshottest = snapshottest
        if isinstance(obj, dict):

# Path: snapshottest/sorted_dict.py
# class SortedDict(OrderedDict):
#     def __init__(self, values):
#         super(SortedDict, self).__init__()
# 
#         try:
#             sorted_items = sorted(values.items())
#         except TypeError:
#             # Enums are not sortable
#             sorted_items = values.items()
#         for key, value in sorted_items:
#             if isinstance(value, dict):
#                 self[key] = SortedDict(value)
#             elif isinstance(value, list):
#                 self[key] = self._sort_list(value)
#             else:
#                 self[key] = value
# 
#     def _sort_list(self, value):
#         def sort(val):
#             if isinstance(val, dict):
#                 return SortedDict(val)
#             elif isinstance(val, list):
#                 return self._sort_list(val)
#             else:
#                 return val
# 
#         return [sort(item) for item in value]
# 
# Path: snapshottest/formatter.py
# class Formatter(object):
#     formatters = default_formatters()
# 
#     def __init__(self, imports=None):
#         self.htchar = " " * 4
#         self.lfchar = "\n"
#         self.indent = 0
#         self.imports = imports
# 
#     def __call__(self, value, **args):
#         return self.format(value, self.indent)
# 
#     def format(self, value, indent):
#         formatter = self.get_formatter(value)
#         for module, import_name in formatter.get_imports():
#             self.imports[module].add(import_name)
#         return formatter.format(value, indent, self)
# 
#     def normalize(self, value):
#         formatter = self.get_formatter(value)
#         return formatter.normalize(value, self)
# 
#     @staticmethod
#     def get_formatter(value):
#         for formatter in Formatter.formatters:
#             if formatter.can_format(value):
#                 return formatter
# 
#         # This should never happen as GenericFormatter is registered by default.
#         raise RuntimeError("No formatter found for value")
# 
#     @staticmethod
#     def register_formatter(formatter):
#         Formatter.formatters.insert(0, formatter)


# Path: snapshottest/diff.py
from termcolor import colored
from fastdiff import compare
from .sorted_dict import SortedDict
from .formatter import Formatter




def format_line(line):
    line = line.rstrip("\n")
    if line.startswith("-"):
        return colored(line, "green", attrs=["bold"])
    elif line.startswith("+"):
        return colored(line, "red", attrs=["bold"])
    elif line.startswith("?"):
        return colored("") + colored(line, "yellow", attrs=["bold"])

    return colored("") + colored(line, "white", attrs=["dark"])


class PrettyDiff(object):
    def __init__(self, obj, snapshottest):
        self.pretty = Formatter()
        self.snapshottest = snapshottest
        if isinstance(obj, dict):

            obj = SortedDict(obj)