1 ##############################################################################
\r
2 # Copyright (c) 2018 HUAWEI TECHNOLOGIES CO.,LTD and others.
\r
4 # All rights reserved. This program and the accompanying materials
\r
5 # are made available under the terms of the Apache License, Version 2.0
\r
6 # which accompanies this distribution, and is available at
\r
7 # http://www.apache.org/licenses/LICENSE-2.0
\r
8 ##############################################################################
\r
10 from src.step.test_step import TestStep
\r
15 class TestStepManager(object):
\r
16 def __init__(self, context):
\r
17 self._context = context
\r
19 currentDirPath = os.path.dirname(os.path.abspath(__file__))
\r
20 sys.path.append(currentDirPath)
\r
22 excludeFiles = ('__init__.py', 'step_manager.py', 'test_step.py')
\r
23 for fileName in os.listdir(currentDirPath):
\r
24 if os.path.isfile(os.path.join(currentDirPath, fileName)) and \
\r
25 os.path.splitext(fileName)[1] == '.py' and \
\r
26 fileName not in excludeFiles:
\r
27 __import__(os.path.splitext(fileName)[0])
\r
29 def getStepObj(self, type, id, name, service, action, args):
\r
30 for subclass in TestStep.__subclasses__():
\r
31 if type == subclass.__step_type__:
\r
32 return subclass(id, name, service, action, args, self._context)
\r
35 if __name__ == "__main__":
\r
36 tsMgr = TestStepManager()
\r
37 args = {'command': 'greet', 'method': 'POST', 'args': {'name': 'leo'}}
\r
38 stepObj = tsMgr.getStepObj('test', 1, 'test_cpu', {
\r
39 'name': 'greet', 'call': 'REST'}, 'start', args)
\r
41 print stepObj.__class__.__mro__
\r