Merge pull request #850 from manics/execute_cmd-flush

[MRG] utils.execute_cmd flush buffer if no EOL
pull/855/head
Tim Head 2020-02-18 14:05:36 +01:00 zatwierdzone przez GitHub
commit d8ccf36b11
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 10 dodań i 0 usunięć

Wyświetl plik

@ -50,6 +50,8 @@ def execute_cmd(cmd, capture=False, **kwargs):
if c == b"\n":
yield flush()
c_last = c
if buf:
yield flush()
finally:
ret = proc.wait()
if ret != 0:

Wyświetl plik

@ -27,6 +27,14 @@ def test_capture_cmd_capture_success():
assert line == "test\n"
def test_capture_cmd_noeol_capture_success():
# This should succeed
lines = list(
utils.execute_cmd(["/bin/bash", "-c", "echo -en 'test\ntest'"], capture=True)
)
assert lines == ["test\n", "test"]
def test_capture_cmd_capture_fail():
with pytest.raises(subprocess.CalledProcessError):
for line in utils.execute_cmd(