# 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/formatters.py
# class BaseFormatter(object):
#     def can_format(self, value):
#         raise NotImplementedError()
# 
#     def format(self, value, indent, formatter):
#         raise NotImplementedError()
# 
#     def get_imports(self):
#         return ()
# 
#     def assert_value_matches_snapshot(
#         self, test, test_value, snapshot_value, formatter
#     ):
#         test.assert_equals(formatter.normalize(test_value), snapshot_value)
# 
#     def store(self, test, value):
#         return value
# 
#     def normalize(self, value, formatter):
#         return value


import os
import shutil
import filecmp
from .formatter import Formatter
from .formatters import BaseFormatter
        relative_snapshot_filename = os.path.relpath(
            snapshot_file, test.module.snapshot_dir
        )
        return FileSnapshot(relative_snapshot_filename)

    def get_imports(self):
        return (("snapshottest.file", "FileSnapshot"),)

    def format(self, value, indent, formatter):
        return repr(value)

    def assert_value_matches_snapshot(
        self, test, test_value, snapshot_value, formatter
    ):
        snapshot_path = os.path.join(test.module.snapshot_dir, snapshot_value.path)
        files_identical = filecmp.cmp(test_value.path, snapshot_path, shallow=False)
        assert files_identical, "Stored file differs from test file"

    @staticmethod
    def get_file_snapshot_dir(test):
        """
        Get the directory for storing file snapshots for `test`.
        Snapshot files are stored under:
            snapshots/snap_<test_module_name>/
        Right next to where the snapshot module is stored:
            snapshots/snap_<snapshot_module_name>.py
        """
        return os.path.join(test.module.snapshot_dir, test.module.module)



# 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/formatters.py
# class BaseFormatter(object):
#     def can_format(self, value):
#         raise NotImplementedError()
# 
#     def format(self, value, indent, formatter):
#         raise NotImplementedError()
# 
#     def get_imports(self):
#         return ()
# 
#     def assert_value_matches_snapshot(
#         self, test, test_value, snapshot_value, formatter
#     ):
#         test.assert_equals(formatter.normalize(test_value), snapshot_value)
# 
#     def store(self, test, value):
#         return value
# 
#     def normalize(self, value, formatter):
#         return value


# Path: snapshottest/file.py
import os
import shutil
import filecmp
from .formatter import Formatter
from .formatters import BaseFormatter

        relative_snapshot_filename = os.path.relpath(
            snapshot_file, test.module.snapshot_dir
        )
        return FileSnapshot(relative_snapshot_filename)

    def get_imports(self):
        return (("snapshottest.file", "FileSnapshot"),)

    def format(self, value, indent, formatter):
        return repr(value)

    def assert_value_matches_snapshot(
        self, test, test_value, snapshot_value, formatter
    ):
        snapshot_path = os.path.join(test.module.snapshot_dir, snapshot_value.path)
        files_identical = filecmp.cmp(test_value.path, snapshot_path, shallow=False)
        assert files_identical, "Stored file differs from test file"

    @staticmethod
    def get_file_snapshot_dir(test):
        """
        Get the directory for storing file snapshots for `test`.
        Snapshot files are stored under:
            snapshots/snap_<test_module_name>/
        Right next to where the snapshot module is stored:
            snapshots/snap_<snapshot_module_name>.py
        """
        return os.path.join(test.module.snapshot_dir, test.module.module)



Formatter.register_formatter(FileSnapshotFormatter())