From 7053fece67381e5b86b2962cd76fab2588fcfe1c Mon Sep 17 00:00:00 2001 From: Alex Thiessen Date: Tue, 8 Feb 2022 21:10:34 +0100 Subject: [PATCH 1/5] tests/unit/autojump_match_test: Fix backslashes in strings --- tests/unit/autojump_match_test.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/unit/autojump_match_test.py b/tests/unit/autojump_match_test.py index bd02ff50..3b823911 100644 --- a/tests/unit/autojump_match_test.py +++ b/tests/unit/autojump_match_test.py @@ -19,8 +19,8 @@ class TestMatchAnywhere(object): entry4 = Entry('/中/zhong/国/guo', 10) entry5 = Entry('/is\'t/this/a/b*tchin/edge/case?', 10) win_entry1 = Entry('C:\\foo\\bar\\baz', 10) - win_entry2 = Entry('D:\Program Files (x86)\GIMP', 10) - win_entry3 = Entry('C:\Windows\System32', 10) + win_entry2 = Entry('D:\\Program Files (x86)\\GIMP', 10) + win_entry3 = Entry('C:\\Windows\\System32', 10) @pytest.fixture def haystack(self): @@ -75,9 +75,9 @@ class TestMatchConsecutive(object): entry4 = Entry('/中/zhong/国/guo', 10) entry5 = Entry('/日/本', 10) entry6 = Entry('/is\'t/this/a/b*tchin/edge/case?', 10) - win_entry1 = Entry('C:\Foo\Bar\Baz', 10) - win_entry2 = Entry('D:\Program Files (x86)\GIMP', 10) - win_entry3 = Entry('C:\Windows\System32', 10) + win_entry1 = Entry('C:\\Foo\\Bar\\Baz', 10) + win_entry2 = Entry('D:\\Program Files (x86)\\GIMP', 10) + win_entry3 = Entry('C:\\Windows\\System32', 10) @pytest.fixture def haystack(self): From 9da67c3277f75e2cf9dfccf67e63b70ec2cbfa14 Mon Sep 17 00:00:00 2001 From: Alex Thiessen Date: Tue, 8 Feb 2022 21:10:37 +0100 Subject: [PATCH 2/5] tox: Fix obsoletion warning --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 8a21b973..239e3676 100644 --- a/tox.ini +++ b/tox.ini @@ -19,7 +19,7 @@ deps = pytest >= 2.9 commands = coverage run --source=bin/ --omit=bin/autojump_argparse.py -m \ - py.test -vv -rxs --tb native -s --strict {posargs:tests} + py.test -vv -rxs --tb native -s --strict-markers {posargs:tests} coverage report -m From 4f07c55f033d6794775a44cd7fa02f60ceafe0c4 Mon Sep 17 00:00:00 2001 From: Alex Thiessen Date: Tue, 8 Feb 2022 21:10:40 +0100 Subject: [PATCH 3/5] tests/integration: Add a failing test Reproduce https://github.com/wting/autojump/issues/348 --- bin/autojump.py | 1 + tests/integration/autojump_test.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 120000 bin/autojump.py create mode 100644 tests/integration/autojump_test.py diff --git a/bin/autojump.py b/bin/autojump.py new file mode 120000 index 00000000..ee78df49 --- /dev/null +++ b/bin/autojump.py @@ -0,0 +1 @@ +autojump \ No newline at end of file diff --git a/tests/integration/autojump_test.py b/tests/integration/autojump_test.py new file mode 100644 index 00000000..195088ca --- /dev/null +++ b/tests/integration/autojump_test.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import os +import sys + +sys.path.append(os.path.join(os.getcwd(), 'bin')) # noqa +from autojump import find_matches +from autojump_data import entriefy + + +def test_find_matches_returns_unique_results(tmpdir): + path = str(tmpdir) + needle = str(os.path.basename(tmpdir)) + + matches = find_matches(entriefy({path: 10}), [needle]) + + assert list(matches) == list(entriefy({path: 10})) From 4e11af9f1280ae94dcc145caca3afef32df4a2b1 Mon Sep 17 00:00:00 2001 From: Alex Thiessen Date: Tue, 8 Feb 2022 21:10:43 +0100 Subject: [PATCH 4/5] bin/autojump: Fix a Flake8 warning --- bin/autojump | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/autojump b/bin/autojump index ed0151d9..2b2ec38a 100755 --- a/bin/autojump +++ b/bin/autojump @@ -129,8 +129,8 @@ def parse_arguments(): help='show database entries and their key weights', ) parser.add_argument( - '-v', '--version', action='version', version='%(prog)s v' + - VERSION, help='show version information', + '-v', '--version', action='version', version='%(prog)s v' + VERSION, + help='show version information', ) return parser.parse_args() From 54e5cb03565ceaa30b152578b3d8791bb9edb29a Mon Sep 17 00:00:00 2001 From: Alex Thiessen Date: Sun, 23 Jan 2022 02:05:39 +0100 Subject: [PATCH 5/5] bin/autojump: Make the test pass The order of completion suggestions must be according to the weights, yet `set` is unordered. Thus, sorting needs to be performed after de-duplicating. Fixes https://github.com/wting/autojump/issues/348 --- bin/autojump | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/bin/autojump b/bin/autojump index 2b2ec38a..aa99be21 100755 --- a/bin/autojump +++ b/bin/autojump @@ -188,18 +188,15 @@ def find_matches(entries, needles, check_entries=True): else: path_exists = lambda _: True - data = sorted( - entries, - key=attrgetter('weight', 'path'), - reverse=True, - ) - return ifilter( lambda entry: not is_cwd(entry) and path_exists(entry), - chain( - match_consecutive(needles, data, ignore_case), - match_fuzzy(needles, data, ignore_case), - match_anywhere(needles, data, ignore_case), + sorted( + set(chain( + match_consecutive(needles, entries, ignore_case), + match_fuzzy(needles, entries, ignore_case), + match_anywhere(needles, entries, ignore_case), + )), key=attrgetter('weight', 'path'), + reverse=True, ), )