[meld: 1/2] issue: #dirdiff._files_same.need_contents - When `ignore blank line` retain content for rematch afte
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld: 1/2] issue: #dirdiff._files_same.need_contents - When `ignore blank line` retain content for rematch afte
- Date: Tue, 10 Jul 2018 21:10:32 +0000 (UTC)
commit 489a400fd80bfa9ca80b4c97064e16f1a7f597ad
Author: hugosenari <hugosenari gmail com>
Date: Tue Jul 10 06:24:20 2018 -0300
issue: #dirdiff._files_same.need_contents - When `ignore blank line` retain content for rematch after
remove blank lines; commit: fix bug that we dont ignore blank lines if apply_text_filter is false
part of old [dirdiff-mmap](https://gitlab.gnome.org/GNOME/meld/merge_requests/9) merge request
meld/dirdiff.py | 7 ++--
test/dirdiff/__init__.py | 0
test/dirdiff/fixture.py | 72 ++++++++++++++++++++++++++++++++++++++
test/dirdiff/test_files_same.py | 76 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 153 insertions(+), 2 deletions(-)
---
diff --git a/meld/dirdiff.py b/meld/dirdiff.py
index c6791683..f93c33ca 100644
--- a/meld/dirdiff.py
+++ b/meld/dirdiff.py
@@ -111,8 +111,9 @@ def _files_same(files, regexes, comparison_args):
shallow_comparison = comparison_args['shallow-comparison']
time_resolution_ns = comparison_args['time-resolution']
ignore_blank_lines = comparison_args['ignore_blank_lines']
+ apply_text_filters = comparison_args['apply-text-filters']
- need_contents = comparison_args['apply-text-filters']
+ need_contents = ignore_blank_lines or apply_text_filters
# If all entries are directories, they are considered to be the same
if all([stat.S_ISDIR(s.mode) for s in stats]):
@@ -189,7 +190,9 @@ def _files_same(files, regexes, comparison_args):
else:
contents = [b"\n".join(c.splitlines()) for c in contents]
- contents = [misc.apply_text_filters(c, regexes) for c in contents]
+ if apply_text_filters:
+ contents = [misc.apply_text_filters(c, regexes) for c in contents]
+
result = SameFiltered if all_same(contents) else Different
_cache[cache_key] = CacheResult(stats, result)
diff --git a/test/dirdiff/__init__.py b/test/dirdiff/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/test/dirdiff/fixture.py b/test/dirdiff/fixture.py
new file mode 100644
index 00000000..1571ba03
--- /dev/null
+++ b/test/dirdiff/fixture.py
@@ -0,0 +1,72 @@
+from os import mkdir, path
+
+CHUNK_SIZE = 4096
+
+diff_definition = {
+ 'a': {
+ 'a.txt': lambda: b'',
+ 'c': {
+ 'c.txt': lambda: b''
+ },
+ 'd': {
+ 'd.txt': lambda: (b'd' * CHUNK_SIZE) + b'd'
+ },
+ 'e': {
+ 'f': {},
+ 'g': {
+ 'g.txt': lambda: b'g'
+ },
+ 'h': {
+ 'h.txt': lambda: b'h'
+ },
+ 'e.txt': lambda: b''
+ },
+ 'crlf.txt': lambda: b'foo\r\nbar\r\n',
+ 'crlftrailing.txt': lambda: b'foo\r\nbar\r\n\r\n',
+ },
+ 'b': {
+ 'b.txt': lambda: b'',
+ 'c': {
+ 'c.txt': lambda: b''
+ },
+ 'd': {
+ 'd.txt': lambda: (b'd' * CHUNK_SIZE) + b'd',
+ 'd.1.txt': lambda: (b'D' * CHUNK_SIZE) + b'D',
+ 'd.2.txt': lambda: (b'd' * CHUNK_SIZE) + b'D'
+ },
+ 'e': {
+ 'f': {
+ 'f.txt': lambda: b''
+ },
+ 'g': {
+ 'g.txt': lambda: b''
+ },
+ 'h': {
+ 'h.txt': lambda: b'h'
+ },
+ 'e.txt': lambda: b''
+ },
+ 'lf.txt': lambda: b'foo\nbar\n',
+ 'lftrailing.txt': lambda: b'foo\nbar\n\n',
+ }
+}
+
+CUR_DIR = path.dirname(__file__)
+ROOT_DIR = path.join(CUR_DIR, 'diffs')
+
+
+def make(definition=diff_definition, root_dir=ROOT_DIR):
+ if not path.exists(root_dir):
+ mkdir(root_dir, 0o755)
+
+ for k, v in definition.items():
+ file_path = path.join(root_dir, k)
+ if isinstance(v, dict):
+ make(v, file_path)
+ else:
+ with open(file_path, 'bw') as open_file:
+ open_file.write(v())
+
+
+if __name__ == '__main__':
+ make()
diff --git a/test/dirdiff/test_files_same.py b/test/dirdiff/test_files_same.py
new file mode 100644
index 00000000..d71fea9e
--- /dev/null
+++ b/test/dirdiff/test_files_same.py
@@ -0,0 +1,76 @@
+import pytest
+
+from enum import Enum
+from os import path
+from meld.dirdiff import _files_same
+from .fixture import make
+
+
+DiffResult = Enum('DiffResult', 'Same SameFiltered DodgySame DodgyDifferent Different FileError')
+
+
+@pytest.fixture
+def differnt_dirs():
+ make()
+
+
+def abspath(*args):
+ d = path.dirname(__file__)
+ return list(path.join(d, arg) for arg in args)
+
+
+cmp_args = {
+ 'shallow-comparison': False,
+ 'time-resolution': 10000000000,
+ 'ignore_blank_lines': True,
+ 'apply-text-filters': True
+}
+
+no_ignore_args = dict(cmp_args)
+no_ignore_args['ignore_blank_lines'] = False
+no_ignore_args['apply-text-filters'] = False
+
+dodgy_args = dict(cmp_args)
+dodgy_args['shallow-comparison'] = True
+
+@pytest.mark.parametrize('files, regexes, comparison_args, expected', [
+ # empty file list
+ ((), [], cmp_args, DiffResult.Same),
+ # dirs are same
+ (('diffs/a', 'diffs/b'), [], cmp_args, DiffResult.Same),
+ # dir and file ar diffent
+ (('diffs/a', 'diffs/b/b.txt'), [], cmp_args, DiffResult.Different),
+ # shallow equal (time + size)
+ (('diffs/a/d/d.txt', 'diffs/b/d/d.1.txt'), [], dodgy_args, DiffResult.DodgySame),
+ # empty files (fastest equal, wont read files)
+ (('diffs/a/c/c.txt', 'diffs/b/c/c.txt'), [], cmp_args, DiffResult.Same),
+ # 4.1kb vs 4.1kb file (slow equal, read both until end)
+ (('diffs/a/d/d.txt', 'diffs/b/d/d.txt'), [], cmp_args, DiffResult.Same),
+ # 4.1kb vs 4.1kb file (fast different, first chunk diff)
+ (('diffs/a/d/d.txt', 'diffs/b/d/d.1.txt'), [], cmp_args, DiffResult.Different),
+ # 4.1kb vs 4.1kb file (slow different, read both until end)
+ (('diffs/a/d/d.txt', 'diffs/b/d/d.2.txt'), [], cmp_args, DiffResult.Different),
+ # empty vs 1b file (fast different, first chunk diff)
+ (('diffs/a/e/g/g.txt', 'diffs/b/e/g/g.txt'), [], cmp_args, DiffResult.Different),
+ # CRLF vs CRLF with trailing, ignoring blank lines
+ (('diffs/a/crlf.txt', 'diffs/a/crlftrailing.txt'), [], cmp_args, DiffResult.SameFiltered),
+ # CRLF vs CRLF with trailing, not ignoring blank lines
+ (('diffs/a/crlf.txt', 'diffs/a/crlftrailing.txt'), [], no_ignore_args, DiffResult.Different),
+ # LF vs LF with trailing, ignoring blank lines
+ (('diffs/b/lf.txt', 'diffs/b/lftrailing.txt'), [], cmp_args, DiffResult.SameFiltered),
+ # LF vs LF with trailing, not ignoring blank lines
+ (('diffs/b/lf.txt', 'diffs/b/lftrailing.txt'), [], no_ignore_args, DiffResult.Different),
+ # CRLF vs LF, ignoring blank lines
+ (('diffs/a/crlf.txt', 'diffs/b/lf.txt'), [], cmp_args, DiffResult.SameFiltered),
+ # CRLF vs LF, not ignoring blank lines
+ (('diffs/a/crlf.txt', 'diffs/b/lf.txt'), [], no_ignore_args, DiffResult.Different),
+ # CRLF with trailing vs LF with trailing, ignoring blank lines
+ (('diffs/a/crlftrailing.txt', 'diffs/b/lftrailing.txt'), [], cmp_args, DiffResult.SameFiltered),
+ # CRLF with trailing vs LF with trailing, not ignoring blank lines
+ (('diffs/a/crlftrailing.txt', 'diffs/b/lftrailing.txt'), [], no_ignore_args, DiffResult.Different),
+])
+def test_files_same(files, regexes, comparison_args, expected, differnt_dirs):
+ files_path = abspath(*files)
+ result = _files_same(files_path, regexes, comparison_args)
+ actual = DiffResult(result + 1)
+ assert actual == expected
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]