Merge "Add unit test file for ArithmeticRunner"
[yardstick.git] / yardstick / cmd / commands / testcase.py
1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10 """ Handler for yardstick command 'testcase' """
11 from __future__ import absolute_import
12
13 import prettytable
14
15 from yardstick.benchmark.core.testcase import Testcase
16 from yardstick.common.utils import cliargs
17 from yardstick.cmd.commands import change_osloobj_to_paras
18 from yardstick.cmd.commands import Commands
19
20
21 class TestcaseCommands(Commands):
22     """Testcase commands.
23
24        Set of commands to discover and display test cases.
25     """
26
27     def do_list(self, *args):
28         """List existing test cases"""
29         testcase_list = self.client.get('/yardstick/testcases')['result']
30         self._format_print(testcase_list)
31
32     @cliargs("casename", type=str, help="test case name", nargs=1)
33     def do_show(self, args):
34         """Show details of a specific test case"""
35         param = change_osloobj_to_paras(args)
36         Testcase().show(param)
37
38     def _format_print(self, testcase_list):
39         """format output"""
40         case_table = prettytable.PrettyTable(['Testcase Name', 'Description'])
41         case_table.align = 'l'
42         for testcase_record in testcase_list:
43             case_table.add_row([testcase_record['Name'], testcase_record['Description']])
44         print(case_table)