Browse Source

Add echo in run_script()

Bobholamovic 2 năm trước cách đây
mục cha
commit
a1f7747eb9
2 tập tin đã thay đổi với 5 bổ sung2 xóa
  1. 2 1
      tests/test_tutorials.py
  2. 3 1
      tests/testing_utils.py

+ 2 - 1
tests/test_tutorials.py

@@ -62,7 +62,8 @@ class TestTutorial(CpuCommonTest):
                 raise ValueError(
                 raise ValueError(
                     f"{script_name} should be directly contained in {cls.SUBDIR}"
                     f"{script_name} should be directly contained in {cls.SUBDIR}"
                 )
                 )
-            setattr(cls, 'test_' + script_name, _test_tutorial(script_name))
+            setattr(cls, 'test_' + osp.splitext(script_name)[0],
+                    _test_tutorial(script_name))
 
 
         return cls
         return cls
 
 

+ 3 - 1
tests/testing_utils.py

@@ -24,13 +24,15 @@ import paddle
 __all__ = ['CommonTest', 'CpuCommonTest', 'run_script']
 __all__ = ['CommonTest', 'CpuCommonTest', 'run_script']
 
 
 
 
-def run_script(cmd, silent=True, wd=None, timeout=None):
+def run_script(cmd, silent=True, wd=None, timeout=None, echo=True):
     # XXX: This function is not safe!!!
     # XXX: This function is not safe!!!
     cfg = dict(check=True, shell=True, timeout=timeout)
     cfg = dict(check=True, shell=True, timeout=timeout)
     if silent:
     if silent:
         cfg['stdout'] = subprocess.DEVNULL
         cfg['stdout'] = subprocess.DEVNULL
     if wd is not None:
     if wd is not None:
         cmd = f"cd {wd} && {cmd}"
         cmd = f"cd {wd} && {cmd}"
+    if echo:
+        print(cmd)
     return subprocess.run(cmd, **cfg)
     return subprocess.run(cmd, **cfg)