cases.py 4.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
###################################################################
#           Copyright (c) 2016 by TAOS Technologies, Inc.
#                     All rights reserved.
#
#  This file is proprietary and confidential to TAOS Technologies.
#  No part of this file may be reproduced, stored, transmitted,
#  disclosed or used in any form or by any means other than as
#  expressly provided by the written permission from Jianhui Tao
#
###################################################################

# -*- coding: utf-8 -*-

import sys
import os
import time
import datetime
18 19
import inspect
import importlib
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
from util.log import *


class TDCase:
    def __init__(self, name, case):
        self.name = name
        self.case = case


class TDCases:
    def __init__(self):
        self.linuxCases = []
        self.windowsCases = []
        self.clusterCases = []

35 36 37 38
    def __dynamicLoadModule(self, fileName):
        moduleName = fileName.replace(".py", "").replace("/", ".")
        return importlib.import_module(moduleName, package='..')

39 40 41 42 43 44 45 46 47 48
    def addWindows(self, name, case):
        self.windowsCases.append(TDCase(name, case))

    def addLinux(self, name, case):
        self.linuxCases.append(TDCase(name, case))

    def addCluster(self, name, case):
        self.clusterCases.append(TDCase(name, case))

    def runAllLinux(self, conn):
49 50 51 52 53 54 55 56 57 58 59
        # TODO: load all Linux cases here
        runNum = 0
        for tmp in self.linuxCases:
            if tmp.name.find(fileName) != -1:
                case = testModule.TDTestCase()
                case.init(conn)
                case.run()
                case.stop()
                runNum += 1
                continue

S
Shuduo Sang 已提交
60
        tdLog.info("total %d Linux test case(s) executed" % (runNum))
61 62

    def runOneLinux(self, conn, fileName):
63 64
        testModule = self.__dynamicLoadModule(fileName)

65
        runNum = 0
66 67 68 69
        for tmp in self.linuxCases:
            if tmp.name.find(fileName) != -1:
                case = testModule.TDTestCase()
                case.init(conn)
70 71 72 73
                try:
                    case.run()
                except Exception as e:
                    tdLog.notice(repr(e))
sangshuduo's avatar
sangshuduo 已提交
74
                    tdLog.exit("%s failed: %s" % (__file__, fileName))
75
                case.stop()
76
                runNum += 1
77 78
                continue

79
    def runAllWindows(self, conn):
80 81 82 83 84 85 86 87 88 89 90 91
        # TODO: load all Windows cases here
        runNum = 0
        for tmp in self.windowsCases:
            if tmp.name.find(fileName) != -1:
                case = testModule.TDTestCase()
                case.init(conn)
                case.run()
                case.stop()
                runNum += 1
                continue

        tdLog.notice("total %d Windows test case(s) executed" % (runNum))
92 93

    def runOneWindows(self, conn, fileName):
94 95
        testModule = self.__dynamicLoadModule(fileName)

96
        runNum = 0
97 98 99 100 101 102
        for tmp in self.windowsCases:
            if tmp.name.find(fileName) != -1:
                case = testModule.TDTestCase()
                case.init(conn)
                case.run()
                case.stop()
103
                runNum += 1
104 105
                continue
        tdLog.notice("total %d Windows case(s) executed" % (runNum))
106 107

    def runAllCluster(self):
108 109 110 111 112 113 114 115 116 117 118 119 120 121
        # TODO: load all cluster case module here

        runNum = 0
        for tmp in self.clusterCases:
            if tmp.name.find(fileName) != -1:
                tdLog.notice("run cases like %s" % (fileName))
                case = testModule.TDTestCase()
                case.init()
                case.run()
                case.stop()
                runNum += 1
                continue

        tdLog.notice("total %d Cluster test case(s) executed" % (runNum))
122 123

    def runOneCluster(self, fileName):
124 125
        testModule = self.__dynamicLoadModule(fileName)

126
        runNum = 0
127 128 129 130 131 132 133
        for tmp in self.clusterCases:
            if tmp.name.find(fileName) != -1:
                tdLog.notice("run cases like %s" % (fileName))
                case = testModule.TDTestCase()
                case.init()
                case.run()
                case.stop()
134
                runNum += 1
135 136 137
                continue

        tdLog.notice("total %d Cluster test case(s) executed" % (runNum))
138 139 140


tdCases = TDCases()