# Path: diffoscope/comparators/directory.py
# def compare_directories(path1, path2, source=None):
#     return FilesystemDirectory(path1).compare(FilesystemDirectory(path2))
# 
# Path: diffoscope/comparators/utils/specialize.py
# def specialize(file):
#     for cls in ComparatorManager().classes:
#         if isinstance(file, cls):
#             return file
# 
#         # Does this file class match?
#         flag = False
#         if hasattr(cls, 'recognizes'):
#             with profile('recognizes', file):
#                 flag = cls.recognizes(file)
#         else:
#             re_tests = [(x, y) for x, y in (
#                 (cls.RE_FILE_TYPE, file.magic_file_type),
#                 (cls.RE_FILE_EXTENSION, file.name),
#             ) if x]
# 
#             # If neither are defined, it's *not* a match.
#             if re_tests:
#                 flag = all(x.search(y) for x, y in re_tests)
# 
#         if not flag:
#             continue
# 
#         # Found a match; perform type magic
#         logger.debug("Using %s for %s", cls.__name__, file.name)
#         new_cls = type(cls.__name__, (cls, type(file)), {})
#         file.__class__ = new_cls
# 
#         return file
# 
#     logger.debug("Unidentified file. Magic says: %s", file.magic_file_type)
# 
#     return file


import os
import shutil
import pytest
from diffoscope.comparators.binary import FilesystemFile
from diffoscope.comparators.directory import compare_directories
from diffoscope.comparators.utils.specialize import specialize
from utils.data import data, get_data
    assert differences[0].source1 == 'dir'
    assert differences[0].details[0].source1 == 'text'
    expected_diff = get_data('text_ascii_expected_diff')
    assert differences[0].details[0].unified_diff == expected_diff

def test_stat(differences):
    assert 'stat' in differences[0].details[0].details[0].source1


def test_compare_to_file(tmpdir):
    path = str(tmpdir.join('file'))

    with open(path, 'w') as f:
        f.write("content")

    a = specialize(FilesystemFile(str(tmpdir.mkdir('dir'))))
    b = specialize(FilesystemFile(path))

    assert a.compare(b).unified_diff == get_data('test_directory_file_diff')

def test_compare_to_device(tmpdir):
    a = specialize(FilesystemFile(str(tmpdir.mkdir('dir'))))
    b = specialize(FilesystemFile('/dev/null'))

    assert a.compare(b).unified_diff == get_data('test_directory_device_diff')

def test_compare_to_symlink(tmpdir):
    path = str(tmpdir.join('src'))
    os.symlink('/etc/passwd', path)


# Path: diffoscope/comparators/directory.py
# def compare_directories(path1, path2, source=None):
#     return FilesystemDirectory(path1).compare(FilesystemDirectory(path2))
# 
# Path: diffoscope/comparators/utils/specialize.py
# def specialize(file):
#     for cls in ComparatorManager().classes:
#         if isinstance(file, cls):
#             return file
# 
#         # Does this file class match?
#         flag = False
#         if hasattr(cls, 'recognizes'):
#             with profile('recognizes', file):
#                 flag = cls.recognizes(file)
#         else:
#             re_tests = [(x, y) for x, y in (
#                 (cls.RE_FILE_TYPE, file.magic_file_type),
#                 (cls.RE_FILE_EXTENSION, file.name),
#             ) if x]
# 
#             # If neither are defined, it's *not* a match.
#             if re_tests:
#                 flag = all(x.search(y) for x, y in re_tests)
# 
#         if not flag:
#             continue
# 
#         # Found a match; perform type magic
#         logger.debug("Using %s for %s", cls.__name__, file.name)
#         new_cls = type(cls.__name__, (cls, type(file)), {})
#         file.__class__ = new_cls
# 
#         return file
# 
#     logger.debug("Unidentified file. Magic says: %s", file.magic_file_type)
# 
#     return file


# Path: tests/comparators/test_directory.py
import os
import shutil
import pytest
from diffoscope.comparators.binary import FilesystemFile
from diffoscope.comparators.directory import compare_directories
from diffoscope.comparators.utils.specialize import specialize
from utils.data import data, get_data

    assert differences[0].source1 == 'dir'
    assert differences[0].details[0].source1 == 'text'
    expected_diff = get_data('text_ascii_expected_diff')
    assert differences[0].details[0].unified_diff == expected_diff

def test_stat(differences):
    assert 'stat' in differences[0].details[0].details[0].source1


def test_compare_to_file(tmpdir):
    path = str(tmpdir.join('file'))

    with open(path, 'w') as f:
        f.write("content")

    a = specialize(FilesystemFile(str(tmpdir.mkdir('dir'))))
    b = specialize(FilesystemFile(path))

    assert a.compare(b).unified_diff == get_data('test_directory_file_diff')

def test_compare_to_device(tmpdir):
    a = specialize(FilesystemFile(str(tmpdir.mkdir('dir'))))
    b = specialize(FilesystemFile('/dev/null'))

    assert a.compare(b).unified_diff == get_data('test_directory_device_diff')

def test_compare_to_symlink(tmpdir):
    path = str(tmpdir.join('src'))
    os.symlink('/etc/passwd', path)


    a = specialize(FilesystemFile(str(tmpdir.mkdir('dir'))))