Skip to content

Commit 21bad63

Browse files
wanghan-iapcmHan Wang
and
Han Wang
authored
Use the dflow run_command (#115)
Co-authored-by: Han Wang <[email protected]>
1 parent fe0fa83 commit 21bad63

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

dpgen2/utils/run_command.py

+7-13
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
import sys, subprocess
1+
from dflow.utils import run_command as dflow_run_command
2+
from typing import Tuple, Union, List
23

34
def run_command(
4-
cmd,
5+
cmd : Union[str, List[str]],
56
shell: bool = False,
6-
):
7-
pp = subprocess.Popen(
7+
) -> Tuple[int, str, str]:
8+
return dflow_run_command(
89
cmd,
9-
stdout=subprocess.PIPE,
10-
stderr=subprocess.PIPE,
11-
shell=shell,
10+
raise_error=False,
11+
try_bash=shell,
1212
)
13-
out, err = pp.communicate()
14-
return_code = pp.poll()
15-
out = out.decode(sys.stdin.encoding)
16-
err = err.decode(sys.stdin.encoding)
17-
return return_code, out, err
18-

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ classifiers = [
1717
dependencies = [
1818
'numpy',
1919
'dpdata',
20-
'pydflow>=1.6.23',
20+
'pydflow>=1.6.30',
2121
'dargs>=0.3.1',
2222
'scipy',
2323
'lbg',

tests/utils/test_run_command.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def test_success_shell(self):
2020
ret, out, err = run_command(['ls | sort'], shell=True)
2121
self.assertEqual(ret, 0)
2222
self.assertEqual(out, 'bar\nfoo\n')
23-
self.assertEqual(err, '')
23+
# ignore the warnings
24+
# self.assertEqual(err, '')
2425
os.chdir('..')
2526

2627
def test_success(self):
@@ -42,7 +43,8 @@ def test_success_foo(self):
4243
def test_failed(self):
4344
os.chdir(self.work_path)
4445
ret, out, err = run_command(['ls', 'tar'])
45-
self.assertEqual(ret, 2)
46+
self.assertNotEqual(ret, 0)
4647
self.assertEqual(out, '')
47-
self.assertEqual(err, "ls: cannot access 'tar': No such file or directory\n")
48+
# self.assertEqual(err, "ls: cannot access 'tar': No such file or directory\n")
49+
self.assertNotEqual(err, '')
4850
os.chdir('..')

0 commit comments

Comments
 (0)