Change message for empty output

This commit is contained in:
ariarijp 2018-07-02 21:36:15 +09:00
parent 389c6cb3c5
commit c5f27253b0
2 changed files with 9 additions and 7 deletions

View File

@ -18,13 +18,15 @@ def query_to_script_path(path, query):
def run_script(script, shell):
output = subprocess.check_output(script, shell=shell)
if output is not None:
output = output.strip()
if output != "":
return output, None
if output is None:
return None, "Error reading output"
output = output.strip()
if not output:
return None, "Empty output from script"
return output, None
class Script(BaseQueryRunner):
@classmethod

View File

@ -31,6 +31,6 @@ class TestRunScript(BaseTestCase):
self.monkeypatch.setattr(subprocess, "check_output", lambda script, shell: None)
self.assertEqual((None, "Error reading output"), run_script("/foo/bar/baz.sh", True))
self.monkeypatch.setattr(subprocess, "check_output", lambda script, shell: "")
self.assertEqual((None, "Error reading output"), run_script("/foo/bar/baz.sh", True))
self.assertEqual((None, "Empty output from script"), run_script("/foo/bar/baz.sh", True))
self.monkeypatch.setattr(subprocess, "check_output", lambda script, shell: " ")
self.assertEqual((None, "Error reading output"), run_script("/foo/bar/baz.sh", True))
self.assertEqual((None, "Empty output from script"), run_script("/foo/bar/baz.sh", True))