Fix failing tests

This commit is contained in:
Eric Torres 2021-12-20 22:39:27 -08:00
parent b2ddc57086
commit 50be791ab7
2 changed files with 13 additions and 12 deletions

View File

@ -90,7 +90,7 @@ def locate_files(patterns, bin_override=None, capture_text=None):
:returns: path of user-selected file :returns: path of user-selected file
:rtype: bytes, str if capture_text was initialized from None :rtype: bytes, str if capture_text was initialized from None
""" """
cmd = [bin_override if bin_override is not None else LOCATE_CMD, *LOCATE_OPTS] cmd = [bin_override if bin_override is not None else LOCATE_CMD, *LOCATE_OPTS, "--"]
cmd.extend(patterns) cmd.extend(patterns)
return subprocess.run(cmd, capture_output=True, text=capture_text).stdout return subprocess.run(cmd, capture_output=True, text=capture_text).stdout

View File

@ -37,9 +37,11 @@ class TestFindFiles(unittest.TestCase):
def test_bin_override(self, test_override, test_opts): def test_bin_override(self, test_override, test_opts):
search.find_files(opts=test_opts, bin_override=test_override) search.find_files(opts=test_opts, bin_override=test_override)
self.mocked_run.assert_called_with( self.mocked_run.assert_called_with(
[test_override, *test_opts], capture_output=True, text=None [test_override, *test_opts, "--"], capture_output=True, text=None
) )
# bin, opts, pattern, directory
@given(text()) @given(text())
def test_directory_override(self, d): def test_directory_override(self, d):
test_override = "fd_bin" test_override = "fd_bin"
@ -53,9 +55,9 @@ class TestFindFiles(unittest.TestCase):
) )
def test_default_directory(self): def test_default_directory(self):
test_override = "fd_bin" test_override = "path/to/find"
test_opts = ["option1"] test_opts = ["option1", "option2"]
expected_cmd = [test_override, *test_opts] expected_cmd = [test_override, *test_opts, "--"]
search.find_files(opts=test_opts, bin_override=test_override) search.find_files(opts=test_opts, bin_override=test_override)
self.mocked_run.assert_called_with(expected_cmd, capture_output=True, text=None) self.mocked_run.assert_called_with(expected_cmd, capture_output=True, text=None)
@ -69,19 +71,18 @@ class TestFindFiles(unittest.TestCase):
class LocateFiles(unittest.TestCase): class LocateFiles(unittest.TestCase):
def setUp(self): def setUp(self):
self.patched_locate_opts = patch(f"{TESTING_MODULE}") #self.patched_locate_opts = patch(f"{TESTING_MODULE}")
self.patched_subprocess = patch(f"{TESTING_MODULE}.subprocess.run") self.patched_subprocess = patch(f"{TESTING_MODULE}.subprocess.run")
self.mocked_locate_opts = self.patched_subprocess.start()
self.mocked_run = self.patched_subprocess.start() self.mocked_run = self.patched_subprocess.start()
self.mocked_locate_opts.LOCATE_OPTS = ["opt1", "opt2"] search.LOCATE_OPTS = ["opt1", "opt2"]
@given(p=lists(text()), b=text()) @given(test_patterns=lists(text()), bin=text())
def test_bin_override(self, p, b): def test_bin_override(self, test_patterns, bin):
search.locate_files(p, bin_override=b) search.locate_files(test_patterns, bin_override=bin)
self.mocked_run.assert_called_with( self.mocked_run.assert_called_with(
[b, *self.mocked_locate_opts, *p], [bin, *search.LOCATE_OPTS, "--", *test_patterns],
capture_output=True, capture_output=True,
text=None, text=None,
) )