[diffoscope] 01/01: Move diffoscope.Config to a more-standard and simpler singleton pattern and validate constraints on every __setattr__.
Chris Lamb
chris at chris-lamb.co.uk
Wed Sep 28 20:14:05 CEST 2016
This is an automated email from the git hooks/post-receive script.
lamby pushed a commit to branch master
in repository diffoscope.
commit 084611fe2ee9d5f7c2caede95ef16343d8d0602b
Author: Chris Lamb <lamby at debian.org>
Date: Wed Sep 28 19:12:50 2016 +0100
Move diffoscope.Config to a more-standard and simpler singleton pattern and validate constraints on every __setattr__.
Signed-off-by: Chris Lamb <lamby at debian.org>
---
diffoscope/comparators/__init__.py | 6 +-
diffoscope/comparators/binary.py | 2 +-
diffoscope/comparators/utils.py | 2 +-
diffoscope/config.py | 142 ++++++++++---------------------------
diffoscope/difference.py | 6 +-
diffoscope/main.py | 42 +++++------
diffoscope/presenters/html.py | 12 ++--
tests/comparators/test_deb.py | 2 +-
tests/comparators/test_debian.py | 4 +-
tests/comparators/test_dex.py | 2 +-
tests/comparators/test_elf.py | 4 +-
tests/comparators/test_epub.py | 2 +-
tests/comparators/test_fonts.py | 2 +-
tests/comparators/test_fsimage.py | 2 +-
tests/comparators/test_gettext.py | 2 +-
tests/comparators/test_gzip.py | 2 +-
tests/comparators/test_icc.py | 2 +-
tests/comparators/test_image.py | 2 +-
tests/comparators/test_ipk.py | 2 +-
tests/comparators/test_iso9660.py | 2 +-
tests/comparators/test_java.py | 2 +-
tests/comparators/test_macho.py | 2 +-
tests/comparators/test_mono.py | 2 +-
tests/comparators/test_tar.py | 2 +-
tests/comparators/test_utils.py | 6 +-
tests/comparators/utils.py | 3 +-
tests/test_difference.py | 5 +-
27 files changed, 101 insertions(+), 163 deletions(-)
diff --git a/diffoscope/comparators/__init__.py b/diffoscope/comparators/__init__.py
index ab247cb..4fc62a5 100644
--- a/diffoscope/comparators/__init__.py
+++ b/diffoscope/comparators/__init__.py
@@ -118,7 +118,7 @@ def bail_if_non_existing(*paths):
sys.exit(2)
def compare_root_paths(path1, path2):
- if not Config.general.new_file:
+ if not Config().new_file:
bail_if_non_existing(path1, path2)
if os.path.isdir(path1) and os.path.isdir(path2):
return compare_directories(path1, path2)
@@ -168,7 +168,7 @@ def specialize(file):
def perform_fuzzy_matching(members1, members2):
- if tlsh == None or Config.general.fuzzy_threshold == 0:
+ if tlsh == None or Config().fuzzy_threshold == 0:
return
already_compared = set()
# Perform local copies because they will be modified by consumer
@@ -186,7 +186,7 @@ def perform_fuzzy_matching(members1, members2):
comparisons.sort(key=operator.itemgetter(0))
score, name2 = comparisons[0]
logger.debug('fuzzy top match %s %s: %d difference score', name1, name2, score)
- if score < Config.general.fuzzy_threshold:
+ if score < Config().fuzzy_threshold:
yield name1, name2, score
already_compared.add(name2)
diff --git a/diffoscope/comparators/binary.py b/diffoscope/comparators/binary.py
index 4c6a6c4..11e2b02 100644
--- a/diffoscope/comparators/binary.py
+++ b/diffoscope/comparators/binary.py
@@ -278,7 +278,7 @@ class NonExistingFile(File):
@staticmethod
def recognizes(file):
if isinstance(file, FilesystemFile) and not os.path.lexists(file.name):
- assert Config.general.new_file, '%s does not exist' % file.name
+ assert Config().new_file, '%s does not exist' % file.name
return True
return False
diff --git a/diffoscope/comparators/utils.py b/diffoscope/comparators/utils.py
index 1529dae..75f40fb 100644
--- a/diffoscope/comparators/utils.py
+++ b/diffoscope/comparators/utils.py
@@ -217,7 +217,7 @@ class Container(object, metaclass=abc.ABCMeta):
comment = 'Files similar despite different names (difference score: %d)' % score
yield my_members.pop(my_name), other_members.pop(other_name), comment
p.step(2)
- if Config.general.new_file:
+ if Config().new_file:
for my_member in my_members.values():
yield my_member, NonExistingFile('/dev/null', my_member), NO_COMMENT
p.step()
diff --git a/diffoscope/config.py b/diffoscope/config.py
index ada80b5..aab2509 100644
--- a/diffoscope/config.py
+++ b/diffoscope/config.py
@@ -3,6 +3,7 @@
# diffoscope: in-depth comparison of files, archives, and directories
#
# Copyright © 2015 Reiner Herrmann <reiner at reiner-h.de>
+# Copyright © 2016 Chris Lamb <lamby at 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
@@ -18,108 +19,43 @@
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
-# From http://stackoverflow.com/a/7864317
-# Credits to kylealanhale
-class classproperty(property):
- def __get__(self, cls, owner):
- return classmethod(self.fget).__get__(None, owner)()
-
-
class Config(object):
- def __init__(self):
- self._max_diff_block_lines = 256
- self._max_diff_block_lines_parent = 50
- self._max_diff_block_lines_saved = float("inf")
- # html-dir output uses ratio * max-diff-block-lines as its limit
- self._max_diff_block_lines_html_dir_ratio = 4
- self._max_diff_input_lines = 2 ** 20 # GNU diff cannot process arbitrary large files :(
- self._max_report_size = 2000 * 2 ** 10 # 2000 kB
- self._max_report_child_size = 500 * 2 ** 10
- self._fuzzy_threshold = 60
- self._new_file = False
-
- @classproperty
- def general(cls):
- if not hasattr(cls, '_general_config'):
- cls._general_config = Config()
- return cls._general_config
-
- def _check_constraints(self):
- if self._max_diff_block_lines < self._max_diff_block_lines_parent:
- raise ValueError("max_diff_block_lines (%s) cannot be smaller than max_diff_block_lines_parent (%s)" %
- (self._max_diff_block_lines, self._max_diff_block_lines_parent))
- m = self._max_diff_block_lines_html_dir_ratio
- if self._max_diff_block_lines_saved < m * self._max_diff_block_lines:
- raise ValueError("max_diff_block_lines_saved (%s) cannot be smaller than %d*max_diff_block_lines (%s)" %
- (self._max_diff_block_lines_saved, m, m*self._max_diff_block_lines))
-
- @property
- def max_diff_block_lines(self):
- return self._max_diff_block_lines
-
- @max_diff_block_lines.setter
- def max_diff_block_lines(self, value):
- self._max_diff_block_lines = value
- self._check_constraints()
-
- @property
- def max_diff_block_lines_parent(self):
- return self._max_diff_block_lines_parent
-
- @max_diff_block_lines_parent.setter
- def max_diff_block_lines_parent(self, value):
- self._max_diff_block_lines_parent = value
- self._check_constraints()
-
- @property
- def max_diff_block_lines_saved(self):
- return self._max_diff_block_lines_saved
-
- @max_diff_block_lines_saved.setter
- def max_diff_block_lines_saved(self, value):
- self._max_diff_block_lines_saved = value
- self._check_constraints()
+ max_diff_block_lines = 256
+ max_diff_block_lines_parent = 50
+ max_diff_block_lines_saved = float("inf")
+ # html-dir output uses ratio * max-diff-block-lines as its limit
+ max_diff_block_lines_html_dir_ratio = 4
+ # GNU diff cannot process arbitrary large files :(
+ max_diff_input_lines = 2 ** 20
+ max_report_size = 2000 * 2 ** 10 # 2000 kB
+ max_report_child_size = 500 * 2 ** 10
+ new_file = False
+ fuzzy_threshold = 60
+ enforce_constraints = True
+
+ _singleton = {}
- @property
- def max_diff_block_lines_html_dir_ratio(self):
- return self._max_diff_block_lines_html_dir_ratio
-
- @property
- def max_diff_input_lines(self):
- return self._max_diff_input_lines
-
- @max_diff_input_lines.setter
- def max_diff_input_lines(self, value):
- self._max_diff_input_lines = value
-
- @property
- def max_report_size(self):
- return self._max_report_size
-
- @max_report_size.setter
- def max_report_size(self, value):
- self._max_report_size = value
-
- @property
- def max_report_child_size(self):
- return self._max_report_child_size
-
- @max_report_child_size.setter
- def max_report_child_size(self, value):
- self._max_report_child_size = value
-
- @property
- def fuzzy_threshold(self):
- return self._fuzzy_threshold
-
- @fuzzy_threshold.setter
- def fuzzy_threshold(self, value):
- self._fuzzy_threshold = value
-
- @property
- def new_file(self):
- return self._new_file
-
- @new_file.setter
- def new_file(self, value):
- self._new_file = value
+ def __init__(self):
+ self.__dict__ = self._singleton
+
+ def __setattr__(self, k, v):
+ super(Config, self).__setattr__(k, v)
+
+ if self.enforce_constraints:
+ self.check_constraints()
+
+ def check_constraints(self):
+ if self.max_diff_block_lines < self.max_diff_block_lines_parent:
+ raise ValueError("max_diff_block_lines ({0.max_diff_block_lines}) "
+ "cannot be smaller than max_diff_block_lines_parent "
+ "({0.max_diff_block_lines_parent})".format(self),
+ )
+
+ max_ = self.max_diff_block_lines_html_dir_ratio * \
+ self.max_diff_block_lines
+ if self.max_diff_block_lines_saved < max_:
+ raise ValueError("max_diff_block_lines_saved "
+ "({0.max_diff_block_lines_saved}) cannot be smaller than "
+ "{0.max_diff_block_lines_html_dir_ratio} * "
+ "max_diff_block_lines ({1})".format(self, max_),
+ )
diff --git a/diffoscope/difference.py b/diffoscope/difference.py
index 0330515..c55819e 100644
--- a/diffoscope/difference.py
+++ b/diffoscope/difference.py
@@ -113,7 +113,7 @@ class DiffParser(object):
else:
self._block_len = 1
self._direction = line[0]
- max_lines = Config.general.max_diff_block_lines_saved
+ max_lines = Config().max_diff_block_lines_saved
if self._block_len >= max_lines:
return self.skip_block
else:
@@ -123,7 +123,7 @@ class DiffParser(object):
def skip_block(self, line):
if self._remaining_hunk_lines == 0 or line[0] != self._direction:
- removed = self._block_len - Config.general.max_diff_block_lines_saved
+ removed = self._block_len - Config().max_diff_block_lines_saved
if removed:
self._diff.write('%s[ %d lines removed ]\n' % (self._direction, removed))
return self.read_hunk(line)
@@ -231,7 +231,7 @@ def empty_file_feeder():
def make_feeder_from_raw_reader(in_file, filter=lambda buf: buf):
def feeder(out_file):
- max_lines = Config.general.max_diff_input_lines
+ max_lines = Config().max_diff_input_lines
line_count = 0
end_nl = False
h = None
diff --git a/diffoscope/main.py b/diffoscope/main.py
index 2be34fe..1290f59 100644
--- a/diffoscope/main.py
+++ b/diffoscope/main.py
@@ -98,25 +98,25 @@ def create_parser():
help='Maximum bytes written in report. In html-dir '
'output, this is the max bytes of the parent page. '
'(0 to disable, default: %d)' %
- Config.general.max_report_size,
+ Config().max_report_size,
default=None).completer=RangeCompleter(0,
- Config.general.max_report_size, 200000)
+ Config().max_report_size, 200000)
group2.add_argument('--max-report-child-size', metavar='BYTES',
dest='max_report_child_size', type=int,
help='In html-dir output, this is the max bytes of '
'each child page. (0 to disable, default: %(default)s, '
'remaining in effect even with --no-default-limits)',
- default=Config.general.max_report_child_size).completer=RangeCompleter(0,
- Config.general.max_report_child_size, 50000)
+ default=Config().max_report_child_size).completer=RangeCompleter(0,
+ Config().max_report_child_size, 50000)
group2.add_argument('--max-diff-block-lines', dest='max_diff_block_lines',
metavar='LINES', type=int,
help='Maximum number of lines output per diff block. '
'In html-dir output, we use %d * this number instead, '
'taken over all pages. (0 to disable, default: %d)' %
- (Config.general.max_diff_block_lines_html_dir_ratio,
- Config.general.max_diff_block_lines),
+ (Config().max_diff_block_lines_html_dir_ratio,
+ Config().max_diff_block_lines),
default=None).completer=RangeCompleter(0,
- Config.general.max_diff_block_lines, 5)
+ Config().max_diff_block_lines, 5)
group2.add_argument('--max-diff-block-lines-parent', dest='max_diff_block_lines_parent',
metavar='LINES', type=int,
help='In --html-dir output, this is maximum number of '
@@ -124,8 +124,8 @@ def create_parser():
'before spilling it into child pages. (0 to disable, '
'default: %(default)s, remaining in effect even with '
'--no-default-limits)',
- default=Config.general.max_diff_block_lines_parent).completer=RangeCompleter(0,
- Config.general.max_diff_block_lines_parent, 200)
+ default=Config().max_diff_block_lines_parent).completer=RangeCompleter(0,
+ Config().max_diff_block_lines_parent, 200)
group2.add_argument('--max-diff-block-lines-saved', dest='max_diff_block_lines_saved',
metavar='LINES', type=int,
help='Maximum number of lines saved per diff block. '
@@ -141,15 +141,15 @@ def create_parser():
group3.add_argument('--fuzzy-threshold', dest='fuzzy_threshold', type=int,
help='Threshold for fuzzy-matching '
'(0 to disable, %(default)s is default, 400 is high fuzziness)',
- default=Config.general.fuzzy_threshold).completer=RangeCompleter(0,
+ default=Config().fuzzy_threshold).completer=RangeCompleter(0,
400, 20)
group3.add_argument('--max-diff-input-lines', dest='max_diff_input_lines',
metavar='LINES', type=int,
help='Maximum number of lines fed to diff(1). '
'(0 to disable, default: %d)' %
- Config.general.max_diff_input_lines,
+ Config().max_diff_input_lines,
default=None).completer=RangeCompleter(0,
- Config.general.max_diff_input_lines, 5000)
+ Config().max_diff_input_lines, 5000)
if not tlsh:
parser.epilog = 'File renaming detection based on fuzzy-matching is currently disabled. It can be enabled by installing the "tlsh" module available at https://github.com/trendmicro/tlsh'
@@ -219,17 +219,17 @@ def maybe_set_limit(config, parsed_args, key):
def run_diffoscope(parsed_args):
- if not tlsh and Config.general.fuzzy_threshold != parsed_args.fuzzy_threshold:
+ if not tlsh and Config().fuzzy_threshold != parsed_args.fuzzy_threshold:
logger.warning('Fuzzy-matching is currently disabled as the "tlsh" module is unavailable.')
- maybe_set_limit(Config.general, parsed_args, "max_report_size")
- maybe_set_limit(Config.general, parsed_args, "max_report_child_size")
+ maybe_set_limit(Config(), parsed_args, "max_report_size")
+ maybe_set_limit(Config(), parsed_args, "max_report_child_size")
# need to set them in this order due to Config._check_constraints
- maybe_set_limit(Config.general, parsed_args, "max_diff_block_lines_saved")
- maybe_set_limit(Config.general, parsed_args, "max_diff_block_lines_parent")
- maybe_set_limit(Config.general, parsed_args, "max_diff_block_lines")
- maybe_set_limit(Config.general, parsed_args, "max_diff_input_lines")
- Config.general.fuzzy_threshold = parsed_args.fuzzy_threshold
- Config.general.new_file = parsed_args.new_file
+ maybe_set_limit(Config(), parsed_args, "max_diff_block_lines_saved")
+ maybe_set_limit(Config(), parsed_args, "max_diff_block_lines_parent")
+ maybe_set_limit(Config(), parsed_args, "max_diff_block_lines")
+ maybe_set_limit(Config(), parsed_args, "max_diff_input_lines")
+ Config().fuzzy_threshold = parsed_args.fuzzy_threshold
+ Config().new_file = parsed_args.new_file
if parsed_args.debug:
logger.setLevel(logging.DEBUG)
set_locale()
diff --git a/diffoscope/presenters/html.py b/diffoscope/presenters/html.py
index 0d83da7..599a052 100644
--- a/diffoscope/presenters/html.py
+++ b/diffoscope/presenters/html.py
@@ -493,10 +493,10 @@ def row_was_output():
global spl_print_func, spl_print_ctrl, spl_rows, spl_current_page
spl_rows += 1
_, rotation_params = spl_print_ctrl
- max_lines = Config.general.max_diff_block_lines
- max_lines_parent = Config.general.max_diff_block_lines_parent
- max_lines_ratio = Config.general.max_diff_block_lines_html_dir_ratio
- max_report_child_size = Config.general.max_report_child_size
+ max_lines = Config().max_diff_block_lines
+ max_lines_parent = Config().max_diff_block_lines_parent
+ max_lines_ratio = Config().max_diff_block_lines_html_dir_ratio
+ max_report_child_size = Config().max_report_child_size
if not rotation_params:
# html-dir single output, don't need to rotate
if spl_rows >= max_lines:
@@ -706,7 +706,7 @@ def output_html(difference, css_url=None, print_func=None):
"""
if print_func is None:
print_func = print
- print_func = create_limited_print_func(print_func, Config.general.max_report_size)
+ print_func = create_limited_print_func(print_func, Config().max_report_size)
try:
output_header(css_url, print_func)
output_difference(difference, print_func, css_url, None, [])
@@ -754,7 +754,7 @@ def output_html_directory(directory, difference, css_url=None, jquery_url=None):
jquery_url = None
with file_printer(directory, "index.html") as print_func:
- print_func = create_limited_print_func(print_func, Config.general.max_report_size)
+ print_func = create_limited_print_func(print_func, Config().max_report_size)
try:
output_header(css_url, print_func)
output_difference(difference, print_func, css_url, directory, [])
diff --git a/tests/comparators/test_deb.py b/tests/comparators/test_deb.py
index 2bb85a1..52b97e0 100644
--- a/tests/comparators/test_deb.py
+++ b/tests/comparators/test_deb.py
@@ -101,7 +101,7 @@ def test_skip_comparison_of_known_identical_files(deb1, deb2, monkeypatch):
assert './usr/share/doc/test/README.Debian' not in compared
def test_compare_non_existing(monkeypatch, deb1):
- monkeypatch.setattr(Config.general, 'new_file', True)
+ monkeypatch.setattr(Config(), 'new_file', True)
difference = deb1.compare(NonExistingFile('/nonexisting', deb1))
assert difference.source2 == '/nonexisting'
assert difference.details[-1].source2 == '/dev/null'
diff --git a/tests/comparators/test_debian.py b/tests/comparators/test_debian.py
index baa351c..06a0cc8 100644
--- a/tests/comparators/test_debian.py
+++ b/tests/comparators/test_debian.py
@@ -115,7 +115,7 @@ def test_dot_changes_internal_diff(dot_changes_differences):
@pytest.mark.skipif(miss_debian_module, reason='debian module is not installed')
def test_dot_changes_compare_non_existing(monkeypatch, dot_changes1):
- monkeypatch.setattr(Config.general, 'new_file', True)
+ monkeypatch.setattr(Config(), 'new_file', True)
difference = dot_changes1.compare(NonExistingFile('/nonexisting', dot_changes1))
output_text(difference, print_func=print)
assert difference.source2 == '/nonexisting'
@@ -209,7 +209,7 @@ def test_dot_dsc_internal_diff(dot_dsc_differences):
@pytest.mark.skipif(miss_debian_module, reason='debian module is not installed')
def test_dot_dsc_compare_non_existing(monkeypatch, dot_dsc1):
- monkeypatch.setattr(Config.general, 'new_file', True)
+ monkeypatch.setattr(Config(), 'new_file', True)
difference = dot_dsc1.compare(NonExistingFile('/nonexisting', dot_dsc1))
output_text(difference, print_func=print)
assert difference.source2 == '/nonexisting'
diff --git a/tests/comparators/test_dex.py b/tests/comparators/test_dex.py
index b588362..4087134 100644
--- a/tests/comparators/test_dex.py
+++ b/tests/comparators/test_dex.py
@@ -56,7 +56,7 @@ def test_differences(differences):
@skip_unless_tools_exist('enjarify', 'zipinfo', 'javap')
def test_compare_non_existing(monkeypatch, dex1):
- monkeypatch.setattr(Config.general, 'new_file', True)
+ monkeypatch.setattr(Config(), 'new_file', True)
difference = dex1.compare(NonExistingFile('/nonexisting', dex1))
assert difference.source2 == '/nonexisting'
assert difference.details[-1].source2 == '/dev/null'
diff --git a/tests/comparators/test_elf.py b/tests/comparators/test_elf.py
index f1de146..6b07f81 100644
--- a/tests/comparators/test_elf.py
+++ b/tests/comparators/test_elf.py
@@ -51,7 +51,7 @@ def obj_differences(obj1, obj2):
@skip_unless_tools_exist('readelf')
def test_obj_compare_non_existing(monkeypatch, obj1):
- monkeypatch.setattr(Config, 'new_file', True)
+ monkeypatch.setattr(Config(), 'new_file', True)
difference = obj1.compare(NonExistingFile('/nonexisting', obj1))
assert difference.source2 == '/nonexisting'
assert len(difference.details) > 0
@@ -96,7 +96,7 @@ def test_lib_differences(lib_differences):
@skip_unless_tools_exist('readelf', 'objdump')
def test_lib_compare_non_existing(monkeypatch, lib1):
- monkeypatch.setattr(Config, 'new_file', True)
+ monkeypatch.setattr(Config(), 'new_file', True)
difference = lib1.compare(NonExistingFile('/nonexisting', lib1))
assert difference.source2 == '/nonexisting'
assert len(difference.details) > 0
diff --git a/tests/comparators/test_epub.py b/tests/comparators/test_epub.py
index 0a402bf..af55a41 100644
--- a/tests/comparators/test_epub.py
+++ b/tests/comparators/test_epub.py
@@ -54,7 +54,7 @@ def test_differences(differences):
@skip_unless_tools_exist('zipinfo')
def test_compare_non_existing(monkeypatch, epub1):
- monkeypatch.setattr(Config.general, 'new_file', True)
+ monkeypatch.setattr(Config(), 'new_file', True)
difference = epub1.compare(NonExistingFile('/nonexisting', epub1))
assert difference.source2 == '/nonexisting'
assert difference.details[-1].source2 == '/dev/null'
diff --git a/tests/comparators/test_fonts.py b/tests/comparators/test_fonts.py
index fefd0d3..70aa1ac 100644
--- a/tests/comparators/test_fonts.py
+++ b/tests/comparators/test_fonts.py
@@ -47,7 +47,7 @@ def test_diff(differences):
@skip_unless_tools_exist('showttf')
def test_compare_non_existing(monkeypatch, ttf1):
- monkeypatch.setattr(Config, 'new_file', True)
+ monkeypatch.setattr(Config(), 'new_file', True)
difference = ttf1.compare(NonExistingFile('/nonexisting', ttf1))
assert difference.source2 == '/nonexisting'
assert len(difference.details) > 0
diff --git a/tests/comparators/test_fsimage.py b/tests/comparators/test_fsimage.py
index bdb527e..643d461 100644
--- a/tests/comparators/test_fsimage.py
+++ b/tests/comparators/test_fsimage.py
@@ -81,7 +81,7 @@ def test_differences(differences):
@skip_unless_tools_exist('qemu-img')
@pytest.mark.skipif(miss_guestfs, reason='guestfs is missing')
def test_compare_non_existing(monkeypatch, img1):
- monkeypatch.setattr(Config.general, 'new_file', True)
+ monkeypatch.setattr(Config(), 'new_file', True)
difference = img1.compare(NonExistingFile('/nonexisting', img1))
assert difference.source2 == '/nonexisting'
assert difference.details[-1].source2 == '/dev/null'
diff --git a/tests/comparators/test_gettext.py b/tests/comparators/test_gettext.py
index 2b1548d..9b1a091 100644
--- a/tests/comparators/test_gettext.py
+++ b/tests/comparators/test_gettext.py
@@ -56,7 +56,7 @@ def test_charsets(mo_no_charset, mo_iso8859_1):
@skip_unless_tools_exist('msgunfmt')
def test_compare_non_existing(monkeypatch, mo1):
- monkeypatch.setattr(Config, 'new_file', True)
+ monkeypatch.setattr(Config(), 'new_file', True)
difference = mo1.compare(NonExistingFile('/nonexisting', mo1))
assert difference.source2 == '/nonexisting'
assert len(difference.details) > 0
diff --git a/tests/comparators/test_gzip.py b/tests/comparators/test_gzip.py
index c6c2c96..a448820 100644
--- a/tests/comparators/test_gzip.py
+++ b/tests/comparators/test_gzip.py
@@ -71,7 +71,7 @@ def test_content_diff(differences):
assert differences[1].unified_diff == expected_diff
def test_compare_non_existing(monkeypatch, gzip1):
- monkeypatch.setattr(Config.general, 'new_file', True)
+ monkeypatch.setattr(Config(), 'new_file', True)
difference = gzip1.compare(NonExistingFile('/nonexisting', gzip1))
assert difference.source2 == '/nonexisting'
assert difference.details[-1].source2 == '/dev/null'
diff --git a/tests/comparators/test_icc.py b/tests/comparators/test_icc.py
index 9fe872f..4ce74e1 100644
--- a/tests/comparators/test_icc.py
+++ b/tests/comparators/test_icc.py
@@ -46,7 +46,7 @@ def test_diff(differences):
@skip_unless_tools_exist('cd-iccdump')
def test_compare_non_existing(monkeypatch, icc1):
- monkeypatch.setattr(Config, 'new_file', True)
+ monkeypatch.setattr(Config(), 'new_file', True)
difference = icc1.compare(NonExistingFile('/nonexisting', icc1))
assert difference.source2 == '/nonexisting'
assert len(difference.details) > 0
diff --git a/tests/comparators/test_image.py b/tests/comparators/test_image.py
index 6691c30..16a3fc2 100644
--- a/tests/comparators/test_image.py
+++ b/tests/comparators/test_image.py
@@ -46,7 +46,7 @@ def test_diff(differences):
@skip_unless_tools_exist('img2txt')
def test_compare_non_existing(monkeypatch, image1):
- monkeypatch.setattr(Config, 'new_file', True)
+ monkeypatch.setattr(Config(), 'new_file', True)
difference = image1.compare(NonExistingFile('/nonexisting', image1))
assert difference.source2 == '/nonexisting'
assert len(difference.details) > 0
diff --git a/tests/comparators/test_ipk.py b/tests/comparators/test_ipk.py
index b1029cb..3d2fe15 100644
--- a/tests/comparators/test_ipk.py
+++ b/tests/comparators/test_ipk.py
@@ -49,7 +49,7 @@ def test_compressed_files(differences):
assert differences[1].details[2].source1 == './control.tar.gz'
def test_compare_non_existing(monkeypatch, ipk1):
- monkeypatch.setattr(Config.general, 'new_file', True)
+ monkeypatch.setattr(Config(), 'new_file', True)
difference = ipk1.compare(NonExistingFile('/nonexisting', ipk1))
assert difference.source2 == '/nonexisting'
assert difference.details[-1].source2 == '/dev/null'
diff --git a/tests/comparators/test_iso9660.py b/tests/comparators/test_iso9660.py
index 0cd6aee..4299f5d 100644
--- a/tests/comparators/test_iso9660.py
+++ b/tests/comparators/test_iso9660.py
@@ -64,7 +64,7 @@ def test_compressed_files(differences):
@skip_unless_tools_exist('isoinfo')
def test_compare_non_existing(monkeypatch, iso1):
- monkeypatch.setattr(Config.general, 'new_file', True)
+ monkeypatch.setattr(Config(), 'new_file', True)
difference = iso1.compare(NonExistingFile('/nonexisting', iso1))
assert difference.source2 == '/nonexisting'
assert difference.details[-1].source2 == '/dev/null'
diff --git a/tests/comparators/test_java.py b/tests/comparators/test_java.py
index 7229b21..22914a7 100644
--- a/tests/comparators/test_java.py
+++ b/tests/comparators/test_java.py
@@ -46,7 +46,7 @@ def test_diff(differences):
@skip_unless_tools_exist('javap')
def test_compare_non_existing(monkeypatch, class1):
- monkeypatch.setattr(Config, 'new_file', True)
+ monkeypatch.setattr(Config(), 'new_file', True)
difference = class1.compare(NonExistingFile('/nonexisting', class1))
assert difference.source2 == '/nonexisting'
assert len(difference.details) > 0
diff --git a/tests/comparators/test_macho.py b/tests/comparators/test_macho.py
index f280876..634f726 100644
--- a/tests/comparators/test_macho.py
+++ b/tests/comparators/test_macho.py
@@ -43,7 +43,7 @@ def obj_differences(obj1, obj2):
@skip_unless_tools_exist('otool', 'lipo')
def test_obj_compare_non_existing(monkeypatch, obj1):
- monkeypatch.setattr(Config, 'new_file', True)
+ monkeypatch.setattr(Config(), 'new_file', True)
difference = obj1.compare(NonExistingFile('/nonexisting', obj1))
assert difference.source2 == '/nonexisting'
assert len(difference.details) > 0
diff --git a/tests/comparators/test_mono.py b/tests/comparators/test_mono.py
index 6f12fdf..eda5c43 100644
--- a/tests/comparators/test_mono.py
+++ b/tests/comparators/test_mono.py
@@ -51,7 +51,7 @@ def test_diff(differences):
@skip_unless_tools_exist('pedump')
def test_compare_non_existing(monkeypatch, exe1):
- monkeypatch.setattr(Config, 'new_file', True)
+ monkeypatch.setattr(Config(), 'new_file', True)
difference = exe1.compare(NonExistingFile('/nonexisting', exe1))
assert difference.source2 == '/nonexisting'
assert len(difference.details) > 0
diff --git a/tests/comparators/test_tar.py b/tests/comparators/test_tar.py
index 0b205aa..ffca7d8 100644
--- a/tests/comparators/test_tar.py
+++ b/tests/comparators/test_tar.py
@@ -66,5 +66,5 @@ no_permissions_tar = load_fixture(data('no-perms.tar'))
def test_no_permissions_dir_in_tarball(monkeypatch, no_permissions_tar):
# We want to make sure OSError is not raised.
# Comparing with non-existing file makes it easy to make sure all files are unpacked
- monkeypatch.setattr(Config, 'new_file', True)
+ monkeypatch.setattr(Config(), 'new_file', True)
no_permissions_tar.compare(NonExistingFile('/nonexistent', no_permissions_tar))
diff --git a/tests/comparators/test_utils.py b/tests/comparators/test_utils.py
index 2cbb4ed..64e1dbb 100644
--- a/tests/comparators/test_utils.py
+++ b/tests/comparators/test_utils.py
@@ -81,15 +81,15 @@ fuzzy_tar_in_tar2 = load_fixture(data('fuzzy-tar-in-tar2.tar'))
@pytest.mark.skipif(miss_tlsh, reason='tlsh is missing')
def test_no_fuzzy_matching(monkeypatch, fuzzy_tar_in_tar1, fuzzy_tar_in_tar2):
- monkeypatch.setattr(Config, 'fuzzy_threshold', 0)
+ monkeypatch.setattr(Config(), 'fuzzy_threshold', 0)
difference = fuzzy_tar_in_tar1.compare(fuzzy_tar_in_tar2)
assert len(difference.details) == 1
assert difference.details[0].source1 == 'file list'
@pytest.mark.skipif(miss_tlsh, reason='tlsh is missing')
def test_no_fuzzy_matching_new_file(monkeypatch, fuzzy_tar_in_tar1, fuzzy_tar_in_tar2):
- monkeypatch.setattr(Config, 'fuzzy_threshold', 0)
- monkeypatch.setattr(Config, 'new_file', True)
+ monkeypatch.setattr(Config(), 'fuzzy_threshold', 0)
+ monkeypatch.setattr(Config(), 'new_file', True)
difference = fuzzy_tar_in_tar1.compare(fuzzy_tar_in_tar2)
assert len(difference.details) == 3
assert difference.details[1].source2 == '/dev/null'
diff --git a/tests/comparators/utils.py b/tests/comparators/utils.py
index f8f6399..838ce54 100644
--- a/tests/comparators/utils.py
+++ b/tests/comparators/utils.py
@@ -67,7 +67,8 @@ def data(filename):
)
def assert_non_existing(monkeypatch, fixture, has_null_source=True, has_details=True):
- monkeypatch.setattr(Config.general, 'new_file', True)
+ monkeypatch.setattr(Config(), 'new_file', True)
+ assert Config().new_file, "didnt get patched"
difference = fixture.compare(NonExistingFile('/nonexisting', fixture))
diff --git a/tests/test_difference.py b/tests/test_difference.py
index eb5fa92..9aa6b40 100644
--- a/tests/test_difference.py
+++ b/tests/test_difference.py
@@ -25,14 +25,15 @@ from diffoscope.difference import Difference
def test_too_much_input_for_diff(monkeypatch):
- monkeypatch.setattr(Config, 'max_diff_input_lines', 20)
+ 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
def test_too_long_diff_block_lines(monkeypatch):
- monkeypatch.setattr(Config, 'max_diff_block_lines_saved', 10)
+ 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')
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the diffoscope
mailing list