1
0
mirror of https://github.com/rancher/os.git synced 2025-09-20 10:03:59 +00:00

use with to close streams properly

This commit is contained in:
Ivan Mikushin
2015-05-08 13:03:50 +05:00
parent f919ac3193
commit 2c4b918a89

View File

@@ -12,7 +12,6 @@ def qemu(request):
def fin(): def fin():
print('\nTerminating QEMU') print('\nTerminating QEMU')
p.stdout.close()
p.terminate() p.terminate()
request.addfinalizer(fin) request.addfinalizer(fin)
@@ -30,12 +29,13 @@ def rancheros_version():
@pytest.mark.timeout(30) @pytest.mark.timeout(30)
def test_system_boot(qemu): def test_system_boot(qemu):
for ln in iter(qemu.stdout.readline, ''): with qemu.stdout as f:
ros_booted_substr = str.find(ln, 'RancherOS {v} started'.format(v=rancheros_version())) for ln in iter(f.readline, ''):
print(str.strip(ln)) ros_booted_substr = str.find(ln, 'RancherOS {v} started'.format(v=rancheros_version()))
if ros_booted_substr > -1: print(str.strip(ln))
assert True if ros_booted_substr > -1:
return assert True
return
assert False assert False
@@ -54,12 +54,11 @@ def test_run_system_container(qemu):
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
try: try:
for ln in iter(ssh.stdout.readline, ''): with ssh.stdout as f:
print(str.strip(ln)) for ln in iter(f.readline, ''):
pass print(str.strip(ln))
ssh.wait() ssh.wait()
assert ssh.returncode == 0 assert ssh.returncode == 0
finally: finally:
ssh.stdout.close()
if ssh.returncode is None: if ssh.returncode is None:
ssh.terminate() ssh.terminate()