# 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 codecs
from diffoscope.comparators.binary import FilesystemFile
from diffoscope.comparators.utils.specialize import specialize
from utils.data import data, load_fixture, get_data
from utils.nonexisting import assert_non_existing
    difference = ascii1.compare(ascii1)
    assert difference is None

def test_difference_in_ascii(ascii1, ascii2):
    difference = ascii1.compare(ascii2)
    assert difference is not None
    expected_diff = get_data('text_ascii_expected_diff')
    assert difference.unified_diff == expected_diff
    assert not difference.comments
    assert len(difference.details) == 0

unicode1 = load_fixture('text_unicode1')
unicode2 = load_fixture('text_unicode2')

def test_difference_in_unicode(unicode1, unicode2):
    difference = unicode1.compare(unicode2)
    expected_diff = codecs.open(data('text_unicode_expected_diff'), encoding='utf-8').read()
    assert difference.unified_diff == expected_diff

iso8859 = load_fixture('text_iso8859')

def test_difference_between_iso88591_and_unicode(iso8859, unicode1):
    difference = iso8859.compare(unicode1)
    expected_diff = codecs.open(data('text_iso8859_expected_diff'), encoding='utf-8').read()
    assert difference.unified_diff == expected_diff

def test_difference_between_iso88591_and_unicode_only(iso8859, tmpdir):
    utf8_path = str(tmpdir.join('utf8'))
    with open(utf8_path, 'wb') as f:
        f.write(codecs.open(data('text_iso8859'), encoding='iso8859-1').read().encode('utf-8'))

# 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_text.py
import codecs
from diffoscope.comparators.binary import FilesystemFile
from diffoscope.comparators.utils.specialize import specialize
from utils.data import data, load_fixture, get_data
from utils.nonexisting import assert_non_existing

    difference = ascii1.compare(ascii1)
    assert difference is None

def test_difference_in_ascii(ascii1, ascii2):
    difference = ascii1.compare(ascii2)
    assert difference is not None
    expected_diff = get_data('text_ascii_expected_diff')
    assert difference.unified_diff == expected_diff
    assert not difference.comments
    assert len(difference.details) == 0

unicode1 = load_fixture('text_unicode1')
unicode2 = load_fixture('text_unicode2')

def test_difference_in_unicode(unicode1, unicode2):
    difference = unicode1.compare(unicode2)
    expected_diff = codecs.open(data('text_unicode_expected_diff'), encoding='utf-8').read()
    assert difference.unified_diff == expected_diff

iso8859 = load_fixture('text_iso8859')

def test_difference_between_iso88591_and_unicode(iso8859, unicode1):
    difference = iso8859.compare(unicode1)
    expected_diff = codecs.open(data('text_iso8859_expected_diff'), encoding='utf-8').read()
    assert difference.unified_diff == expected_diff

def test_difference_between_iso88591_and_unicode_only(iso8859, tmpdir):
    utf8_path = str(tmpdir.join('utf8'))
    with open(utf8_path, 'wb') as f:
        f.write(codecs.open(data('text_iso8859'), encoding='iso8859-1').read().encode('utf-8'))

    utf8 = specialize(FilesystemFile(utf8_path))