1
0
mirror of https://github.com/wting/autojump synced 2024-10-27 20:34:07 +00:00

Refactor windows tests to use the same fixture for data

The fixture now returns example paths  specific to windows if run on windows,
else linux like paths are returned.
This commit is contained in:
Christopher Musselle 2019-03-04 20:43:37 +00:00
parent bec3616d86
commit 0a94f79ceb

View File

@ -20,53 +20,53 @@ class TestMatchAnywhere(object):
entry3 = Entry('/foo/baz', 10)
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(r'D:\Program Files (x86)\GIMP', 10)
win_entry3 = Entry(r'C:\Windows\System32', 10)
win_entry2 = Entry('C:\\baz\\foo\\bar', 10)
win_entry3 = Entry('C:\\foo\\baz', 10)
win_entry4 = Entry('C:\\\\zhong\\\\guo', 10)
win_entry5 = Entry('C:\\is\'t\\this\\a\\b*tchin\\edge\\case?', 10)
@pytest.fixture
def haystack(self):
return [
self.entry1,
self.entry2,
self.entry3,
self.entry4,
self.entry5,
]
@pytest.fixture
def windows_haystack(self):
return [self.win_entry1, self.win_entry2, self.win_entry3]
if platform.system() == 'Windows':
return [
self.win_entry1,
self.win_entry2,
self.win_entry3,
self.win_entry4,
self.win_entry5,
]
else:
return [
self.entry1,
self.entry2,
self.entry3,
self.entry4,
self.entry5,
]
def test_single_needle(self, haystack):
assert list(match_anywhere(['bar'], haystack)) == [self.entry1, self.entry2]
assert list(match_anywhere(['bar'], haystack)) == [haystack[0], haystack[1]]
def test_consecutive(self, haystack):
assert list(match_anywhere(['foo', 'bar'], haystack)) \
== [self.entry1, self.entry2]
== [haystack[0], haystack[1]]
assert list(match_anywhere(['bar', 'foo'], haystack)) == []
def test_skip(self, haystack):
assert list(match_anywhere(['baz', 'bar'], haystack)) == [self.entry2]
assert list(match_anywhere(['', ''], haystack)) == [self.entry4]
assert list(match_anywhere(['baz', 'bar'], haystack)) == [haystack[1]]
assert list(match_anywhere(['', ''], haystack)) == [haystack[3]]
def test_ignore_case(self, haystack):
assert list(match_anywhere(['bAz', 'bAR'], haystack, ignore_case=True)) \
== [self.entry2]
def test_backslashes_for_windows_paths(self, windows_haystack):
# https://github.com/wting/autojump/issues/281
assert list(match_anywhere(['foo', 'baz'], windows_haystack)) \
== [self.win_entry1]
assert list(match_anywhere(['program', 'gimp'], windows_haystack, True)) \
== [self.win_entry2]
assert list(match_anywhere(['win', '32'], windows_haystack, True)) \
== [self.win_entry3]
== [haystack[1]]
def test_wildcard_in_needle(self, haystack):
# https://github.com/wting/autojump/issues/402
assert list(match_anywhere(['*', 'this'], haystack)) == []
assert list(match_anywhere(['this', '*'], haystack)) == [self.entry5]
assert list(match_anywhere(['this', '*'], haystack)) == [haystack[4]]
class TestMatchConsecutive(object):
@ -77,68 +77,50 @@ 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(r'C:\Foo\Bar\Baz', 10)
win_entry2 = Entry(r'D:\Program Files (x86)\GIMP', 10)
win_entry3 = Entry(r'C:\Windows\System32', 10)
win_entry4 = Entry('C:\\is\'t\\this\\a\\b*tchin\\edge\\case?', 10)
win_entry1 = Entry('C:\\foo\\bar\\baz', 10)
win_entry2 = Entry('C:\\baz\\foo\\bar', 10)
win_entry3 = Entry('C:\\foo\\baz', 10)
win_entry4 = Entry('C:\\\\zhong\\\\guo', 10)
win_entry5 = Entry('C:\\\\', 10)
win_entry6 = Entry('C:\\is\'t\\this\\a\\b*tchin\\edge\\case?', 10)
@pytest.fixture
def haystack(self):
return [
self.entry1,
self.entry2,
self.entry3,
self.entry4,
self.entry5,
]
@pytest.fixture
def windows_haystack(self):
return [self.win_entry1, self.win_entry2, self.win_entry3, self.win_entry4]
if platform.system() == 'Windows':
return [
self.win_entry1,
self.win_entry2,
self.win_entry3,
self.win_entry4,
self.win_entry5,
self.win_entry6,
]
else:
return [
self.entry1,
self.entry2,
self.entry3,
self.entry4,
self.entry5,
self.entry6,
]
@pytest.mark.skipif(is_windows, reason='Different reference data for path.')
def test_single_needle(self, haystack):
assert list(match_consecutive(['baz'], haystack)) == [self.entry1, self.entry3]
assert list(match_consecutive([''], haystack)) == [self.entry5]
assert list(match_consecutive(['baz'], haystack)) == [haystack[0], haystack[2]]
assert list(match_consecutive([''], haystack)) == [haystack[4]]
@pytest.mark.skipif(is_windows, reason='Different reference data for path.')
def test_consecutive(self, haystack):
assert list(match_consecutive(['bar', 'baz'], haystack)) == [self.entry1]
assert list(match_consecutive(['foo', 'bar'], haystack)) == [self.entry2]
assert list(match_consecutive(['', 'guo'], haystack)) == [self.entry4]
assert list(match_consecutive(['bar', 'baz'], haystack)) == [haystack[0]]
assert list(match_consecutive(['foo', 'bar'], haystack)) == [haystack[1]]
assert list(match_consecutive(['', 'guo'], haystack)) == [haystack[3]]
assert list(match_consecutive(['bar', 'foo'], haystack)) == []
@pytest.mark.skipif(is_windows, reason='Different reference data for path.')
def test_ignore_case(self, haystack):
assert list(match_consecutive(['FoO', 'bAR'], haystack, ignore_case=True)) \
== [self.entry2]
== [haystack[1]]
def test_windows_ignore_case(self, windows_haystack):
assert list(match_consecutive(['gimp'], windows_haystack, True)) == [self.win_entry2]
@pytest.mark.skipif(not is_windows, reason='Different path seperator')
def test_backslashes_for_windows_paths(self, windows_haystack):
# https://github.com/wting/autojump/issues/418
assert list(match_consecutive(['program', 'gimp'], windows_haystack, True)) \
== [self.win_entry2]
@pytest.mark.skipif(not is_windows, reason='Different path seperator')
def test_foo_bar_baz(self, windows_haystack):
# https://github.com/wting/autojump/issues/418
assert list(match_consecutive(['bar', 'baz'], windows_haystack, ignore_case=True)) \
== [self.win_entry1]
@pytest.mark.skipif(not is_windows, reason='Different path seperator')
def test_thing(self, windows_haystack):
assert list(match_consecutive(['win', '32'], windows_haystack, True)) \
== [self.win_entry3]
@pytest.mark.skipif(is_windows, reason='Different reference data for path.')
def test_wildcard_in_needle(self, haystack):
assert list(match_consecutive(['*', 'this'], haystack)) == []
assert list(match_consecutive(['*', 'edge', 'case'], haystack)) == [self.entry6]
@pytest.mark.skipif(not is_windows, reason='Different path seperator')
def test_wildcard_in_needle(self, windows_haystack):
assert list(match_consecutive(['*', 'this'], windows_haystack)) == []
assert list(match_consecutive(['*', 'edge', 'case'], windows_haystack)) == [self.win_entry4]
assert list(match_consecutive(['*', 'edge', 'case'], haystack)) == [haystack[5]]