summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerenaFeng <feng.xiaowei@zte.com.cn>2018-03-02 18:20:45 +0800
committerSerena Feng <feng.xiaowei@zte.com.cn>2018-03-06 01:12:14 +0000
commitead4a2bee15cf8c5891497c23592f8fa4fc2dc91 (patch)
treeae67917aa82f08d3ff4874a5263158083f953dd5
parentb25c1371f82911ea26b8c893b6612bb5ae0c8c19 (diff)
simplify file existence check with os.path.isfile()
Change-Id: I89d15e18c588c27ab41596119d5288cba6e4e02d Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
-rw-r--r--dovetail/cli/commands/cli_testcase.py27
1 files changed, 11 insertions, 16 deletions
diff --git a/dovetail/cli/commands/cli_testcase.py b/dovetail/cli/commands/cli_testcase.py
index 6fe789f7..7529765f 100644
--- a/dovetail/cli/commands/cli_testcase.py
+++ b/dovetail/cli/commands/cli_testcase.py
@@ -60,23 +60,18 @@ class CliTestcase(object):
else:
click.echo("No testsuite defined yet in dovetail!!!")
- def show_testcase(self, testcase):
- abs_testcase_path = constants.TESTCASE_PATH
- if testcase.startswith("dovetail."):
- testcase_yml = testcase[9:] + '.yml'
+ def show_testcase(self, name):
+ tc_path = os.path.join(
+ constants.TESTCASE_PATH,
+ "%s.yml" % (name[9:] if name.startswith('dovetail.') else name))
+ if os.path.isfile(tc_path):
+ with open(tc_path, 'r') as stream:
+ try:
+ click.echo(stream.read())
+ except yaml.YAMLError as exc:
+ click.echo(exc)
else:
- testcase_yml = testcase + '.yml'
- for root, dirs, files in os.walk(abs_testcase_path):
- if testcase_yml in files:
- testcase_path = os.path.join(abs_testcase_path, testcase_yml)
- with open(testcase_path, 'r') as stream:
- try:
- click.echo(stream.read())
- except yaml.YAMLError as exc:
- click.echo(exc)
- else:
- click.echo("testcase %s does not exist or not supported"
- % testcase)
+ click.echo("testcase %s not exist or not supported" % name)
def run(self, args_str):
options = ''