Skip to content

Commit c526a17

Browse files
committed
update unittest
1 parent ae28aca commit c526a17

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

tests/tools/test_process_data.py

+27-14
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,33 @@
1010

1111

1212
def run_in_subprocess(cmd):
13-
result = subprocess.run(
14-
cmd,
15-
shell=True,
16-
capture_output=True,
17-
text=True
18-
)
19-
20-
if result.returncode != 0:
21-
print(f"Command failed with return code {result.returncode}")
22-
print(f"Standard Output: {result.stdout}")
23-
print(f"Standard Error: {result.stderr}")
24-
raise subprocess.CalledProcessError(result, cmd)
25-
26-
return result
13+
try:
14+
with subprocess.Popen(
15+
cmd, shell=True, stdout=subprocess.PIPE,
16+
stderr=subprocess.PIPE) as return_info:
17+
while True:
18+
next_line = return_info.stdout.readline()
19+
return_line = next_line.decode('utf-8', 'ignore').strip()
20+
if return_line == '' and return_info.poll() != None:
21+
break
22+
if return_line != '':
23+
print(return_line)
24+
25+
err_lines = ''
26+
while True:
27+
next_line = return_info.stderr.readline()
28+
return_line = next_line.decode('utf-8', 'ignore').strip()
29+
if return_line == '' and return_info.poll() != None:
30+
break
31+
if return_line != '':
32+
print(return_line)
33+
err_lines += return_line + '\n'
34+
35+
return_code = return_info.wait()
36+
if return_code:
37+
raise RuntimeError(err_lines)
38+
except Exception as e:
39+
raise e
2740

2841

2942
class ProcessDataTest(DataJuicerTestCaseBase):

0 commit comments

Comments
 (0)