def test_non_str_arguments_to_source1_source2(): for x in ((None, 'str'), ('str', None)): a = io.StringIO('a') b = io.StringIO('b') with pytest.raises(TypeError): Difference.from_text_readers(a, b, *x)
def test_too_much_input_for_diff(monkeypatch): monkeypatch.setattr(Config, 'max_diff_input_lines', 20) too_long_text_a = StringIO("a\n" * 21) too_long_text_b = StringIO("b\n" * 21) difference = Difference.from_text_readers(too_long_text_a, too_long_text_b, 'a', 'b') assert '[ Too much input for diff ]' in difference.unified_diff
def compare_details(self, other, source=None): differences = [] differences.append(Difference.from_text_readers(list_libarchive(self.path), list_libarchive(other.path), self.path, other.path, source="file list")) differences.extend(_compare_elf_data(self.path, other.path)) return differences
def compare(self, other, source=None): my_encoding = self.encoding or 'utf-8' other_encoding = other.encoding or 'utf-8' try: with codecs.open(self.path, 'r', encoding=my_encoding) as my_content, \ codecs.open(other.path, 'r', encoding=other_encoding) as other_content: difference = Difference.from_text_readers( my_content, other_content, self.name, other.name, source) # Check if difference is only in line order. if difference and order_only_difference( difference.unified_diff): difference.add_comment("ordering differences only") if my_encoding != other_encoding: if difference is None: difference = Difference(None, self.path, other.path, source) difference.add_details([ Difference.from_text(my_encoding, other_encoding, None, None, source='encoding') ]) return difference except (LookupError, UnicodeDecodeError): # unknown or misdetected encoding return self.compare_bytes(other, source)
def test_too_long_diff_block_lines(monkeypatch): monkeypatch.setattr(Config, 'max_diff_block_lines', 10) too_long_text_a = StringIO("a\n" * 21) too_long_text_b = StringIO("b\n" * 21) difference = Difference.from_text_readers(too_long_text_a, too_long_text_b, 'a', 'b') assert '[ 11 lines removed ]' in difference.unified_diff
def test_too_much_input_for_diff(monkeypatch): monkeypatch.setattr(Config(), 'max_diff_input_lines', 20) too_long_text_a = io.StringIO("a\n" * 21) too_long_text_b = io.StringIO("b\n" * 21) difference = Difference.from_text_readers(too_long_text_a, too_long_text_b, 'a', 'b') assert '[ Too much input for diff ' in difference.unified_diff assert_algebraic_properties(difference, 290)
def compare_details(self, other, source=None): return [ Difference.from_text_readers(list_libarchive(self.path), list_libarchive(other.path), self.path, other.path, source="file list") ]
def test_too_long_diff_block_lines(monkeypatch): monkeypatch.setattr(Config(), 'enforce_constraints', False) monkeypatch.setattr(Config(), 'max_diff_block_lines_saved', 10) too_long_text_a = io.StringIO("a\n" * 21) too_long_text_b = io.StringIO("b\n" * 21) difference = Difference.from_text_readers(too_long_text_a, too_long_text_b, 'a', 'b') assert '[ 11 lines removed ]' in difference.unified_diff
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="symlink")
def compare_details(self, other, source=None): differences = [] differences.append( Difference.from_text_readers(list_libarchive(self.path), list_libarchive(other.path), self.path, other.path, source="file list")) differences.extend(_compare_elf_data(self.path, other.path)) return differences
def compare_details(self, other, source=None): return [ compare_files(self, other, source='md5sums', diff_content_only=True), Difference.from_text_readers(self.strip_checksum(self.path), self.strip_checksum(other.path), self.path, other.path, source="line order") ]
def compare_details(self, other, source=None): return [ Difference.from_command(ArSymbolTableDumper, self.path, other.path), Difference.from_text_readers( list_libarchive(self.path), list_libarchive(other.path), self.path, other.path, source="file list", ), ]
def compare_details(self, other, source=None): return [ Difference(None, self.path, other.path, source="md5sums", comment="Files in package differ"), Difference.from_text_readers(self.strip_checksum(self.path), self.strip_checksum(other.path), self.path, other.path, source="line order") ]
def compare(self, other, source=None): my_encoding = self.encoding or 'utf-8' other_encoding = other.encoding or 'utf-8' try: with codecs.open(self.path, 'r', encoding=my_encoding) as my_content, \ codecs.open(other.path, 'r', encoding=other_encoding) as other_content: difference = Difference.from_text_readers(my_content, other_content, self.name, other.name, source) if my_encoding != other_encoding: if difference is None: difference = Difference(None, self.path, other.path, source) difference.add_details([Difference.from_text(my_encoding, other_encoding, None, None, source='encoding')]) return difference except (LookupError, UnicodeDecodeError): # unknown or misdetected encoding return self.compare_bytes(other, source)
def test_too_much_input_for_diff(monkeypatch): monkeypatch.setattr(Config, "max_diff_input_lines", 20) too_long_text_a = StringIO("a\n" * 21) too_long_text_b = StringIO("b\n" * 21) difference = Difference.from_text_readers(too_long_text_a, too_long_text_b, "a", "b") assert "[ Too much input for diff " in difference.unified_diff
def compare(self, other, source=None): logger.debug('my_content %s', self.path) 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="symlink")
def compare_details(self, other, source=None): return [Difference.from_text_readers(list_libarchive(self.path), list_libarchive(other.path), self.path, other.path, source="file list")]
def compare_details(self, other, source=None): return [Difference(None, self.path, other.path, source="md5sums", comment="Files in package differ"), Difference.from_text_readers(self.strip_checksum(self.path), self.strip_checksum(other.path), self.path, other.path, source="line order")]
The command line `ar` tool is not used any more so remove it from the required tools. --- diffoscope/comparators/elf.py.orig 2016-01-31 06:32:02 UTC +++ diffoscope/comparators/elf.py @@ -24,8 +24,9 @@ import subprocess from diffoscope import tool_required, OutputParsingError from diffoscope import logger from diffoscope.comparators.binary import File +from diffoscope.comparators.libarchive import list_libarchive from diffoscope.comparators.deb import DebFile, get_build_id_map -from diffoscope.comparators.utils import get_ar_content, Command, Container +from diffoscope.comparators.utils import Command, Container from diffoscope.difference import Difference @@ -415,10 +416,8 @@ class StaticLibFile(File): def compare_details(self, other, source=None): differences = [] - # look up differences in metadata - content1 = get_ar_content(self.path) - content2 = get_ar_content(other.path) - differences.append(Difference.from_text( - content1, content2, self.path, other.path, source="metadata")) + differences.append(Difference.from_text_readers(list_libarchive(self.path), + list_libarchive(other.path), + self.path, other.path, source="file list")) differences.extend(_compare_elf_data(self.path, other.path)) return differences
def test_too_long_diff_block_lines(monkeypatch): monkeypatch.setattr(Config, "max_diff_block_lines", 10) too_long_text_a = StringIO("a\n" * 21) too_long_text_b = StringIO("b\n" * 21) difference = Difference.from_text_readers(too_long_text_a, too_long_text_b, "a", "b") assert "[ 11 lines removed ]" in difference.unified_diff
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" )