# Path: diffoscope/comparators/device.py
# class Device(File):
#     @staticmethod
#     def recognizes(file):
#         return file.is_device()
# 
#     def get_device(self):
#         assert isinstance(self, FilesystemFile)
#         st = os.lstat(self.name)
#         return st.st_mode, os.major(st.st_rdev), os.minor(st.st_rdev)
# 
#     def has_same_content_as(self, other):
#         logger.debug("has_same_content: %s %s", self, other)
#         try:
#             return self.get_device() == other.get_device()
#         except (AttributeError, OSError):
#             # 'other' is not a device, or something.
#             logger.debug("has_same_content: Not a device: %s", other)
#             return False
# 
#     def create_placeholder(self):
#         with get_named_temporary_file(mode='w+', delete=False) as f:
#             f.write(format_device(*self.get_device()))
#             f.flush()
#             return f.name
# 
#     @property
#     def path(self):
#         if not hasattr(self, '_placeholder'):
#             self._placeholder = self.create_placeholder()
#         return self._placeholder
# 
#     def cleanup(self):
#         if hasattr(self, '_placeholder'):
#             os.remove(self._placeholder)
#             del self._placeholder
#         super().cleanup()
# 
#     def compare(self, other, source=None):
#         with open(self.path) as my_content, \
#              open(other.path) as other_content:
#             return Difference.from_text_readers(my_content, other_content, self.name, other.name, source=source, comment="device")
# 
# 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 pytest
from diffoscope.comparators.binary import FilesystemFile
from diffoscope.comparators.device import Device
from diffoscope.comparators.utils.specialize import specialize
from utils.data import load_fixture, get_data, normalize_zeros
from utils.tools import skip_unless_tools_exist
# Copyright © 2017 Chris Lamb <lamby@debian.org>
#
# diffoscope is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# diffoscope is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.





text_ascii1 = load_fixture('text_ascii1')

@pytest.fixture
def devnull():
    return specialize(FilesystemFile('/dev/null'))

@pytest.fixture
def differences(devnull, text_ascii1):
    return devnull.compare_bytes(text_ascii1)

@pytest.fixture

# Path: diffoscope/comparators/device.py
# class Device(File):
#     @staticmethod
#     def recognizes(file):
#         return file.is_device()
# 
#     def get_device(self):
#         assert isinstance(self, FilesystemFile)
#         st = os.lstat(self.name)
#         return st.st_mode, os.major(st.st_rdev), os.minor(st.st_rdev)
# 
#     def has_same_content_as(self, other):
#         logger.debug("has_same_content: %s %s", self, other)
#         try:
#             return self.get_device() == other.get_device()
#         except (AttributeError, OSError):
#             # 'other' is not a device, or something.
#             logger.debug("has_same_content: Not a device: %s", other)
#             return False
# 
#     def create_placeholder(self):
#         with get_named_temporary_file(mode='w+', delete=False) as f:
#             f.write(format_device(*self.get_device()))
#             f.flush()
#             return f.name
# 
#     @property
#     def path(self):
#         if not hasattr(self, '_placeholder'):
#             self._placeholder = self.create_placeholder()
#         return self._placeholder
# 
#     def cleanup(self):
#         if hasattr(self, '_placeholder'):
#             os.remove(self._placeholder)
#             del self._placeholder
#         super().cleanup()
# 
#     def compare(self, other, source=None):
#         with open(self.path) as my_content, \
#              open(other.path) as other_content:
#             return Difference.from_text_readers(my_content, other_content, self.name, other.name, source=source, comment="device")
# 
# 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_device.py
import pytest
from diffoscope.comparators.binary import FilesystemFile
from diffoscope.comparators.device import Device
from diffoscope.comparators.utils.specialize import specialize
from utils.data import load_fixture, get_data, normalize_zeros
from utils.tools import skip_unless_tools_exist

# Copyright © 2017 Chris Lamb <lamby@debian.org>
#
# diffoscope is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# diffoscope is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.





text_ascii1 = load_fixture('text_ascii1')

@pytest.fixture
def devnull():
    return specialize(FilesystemFile('/dev/null'))

@pytest.fixture
def differences(devnull, text_ascii1):
    return devnull.compare_bytes(text_ascii1)

@pytest.fixture

def differences_reverse(text_ascii1, devnull):