Пример #1
0
 def rm(self, filepath):
     if not type(filepath) in [str, unicode]:
         raise WorkspaceError("filepath must be strings.")
     if not os.path.exists(filepath):
         L.warning("it is not exists %s" % filepath)
     else:
         try:
             os.remove(filepath)
             return filepath
         except Exception as e:
             L.traceback()
             raise WorkspaceError("Can't remove file %s. Please Check File Permission." % filepath)
Пример #2
0
    def execute(self, script, host, v=2):
        if not os.path.exists(host):
            raise TestRunnerError("%s is not exists." % (host))
        sys.path.append(host)

        suite = unittest.TestSuite()
        loader = unittest.TestLoader()
        module = self.load(script, host)
        if not module:
            L.warning("Not loaded module : %s" % script)
            raise TestRunnerError("%s is not extended StveTestCase." % script)
        else: suite.addTest(loader.loadTestsFromModule(module))
        unittest.TextTestRunner(verbosity=v).run(suite)
Пример #3
0
 def register(cls, host):
     if not os.path.exists(host):
         raise LibraryError("%s is not exists." % (host))
     for fdn in os.listdir(host):
         try:
             if fdn.endswith(".pyc") or fdn.endswith(".py"):
                 pass
             else:
                 sys.path.append(os.path.join(host, fdn))
                 f, n, d = imp.find_module("service")
                 module = imp.load_module("service", f, n, d)
                 cls.service[module.NAME] = module.FACTORY
                 sys.path.remove(os.path.join(host, fdn))
         except Exception as e:
             L.warning(str(e))
Пример #4
0
    def execute_with_report(self, script, host, output):
        if not os.path.exists(host):
            raise TestRunnerError("%s is not exists." % (host))
        sys.path.append(host)

        if not os.path.exists(output):
            raise TestRunnerError("%s is not exists." % (output))

        suite = unittest.TestSuite()
        loader = unittest.TestLoader()
        module = self.load(script, host)
        if not module:
            L.warning("Not loaded module : %s" % script)
            raise TestRunnerError("%s is not extended StveTestCase." % script)
        else: suite.addTest(loader.loadTestsFromModule(module))
        xmlrunner.XMLTestRunner(output=output).run(suite)
Пример #5
0
 def __init__(self, path, clear=False):
     if not type(path) in [str, unicode]:
         raise WorkspaceError("path must be strings.")
     self.default_path = os.path.abspath(path)
     if os.path.exists(path):
         if len(os.listdir(path)) > 0:
             L.warning("It is not vacant folder in the path.")
             if clear:
                 try:
                     for f in os.listdir(path):
                         shutil.rmtree(os.path.join(path, f))
                 except Exception as e:
                     L.traceback()
                     raise WorkspaceError("it must be vacant folder in the path.")
     else:
         self._mkdir_recursive(self.default_path)
Пример #6
0
    def rmdir(self, folder, host=""):
        if not type(folder) in [str, unicode]:
            raise WorkspaceError("folder must be strings.")

        if host == "":
            path = os.path.join(self.root(), folder)
        else:
            if not os.path.exists(host):
                L.warning("it is not exists %s" % host)
                return host
            path = os.path.join(host, folder)

        if not os.path.exists(path):
            L.warning("it is not exists %s" % path)
            return path
        else:
            try:
                shutil.rmtree(path); return path
            except Exception as e:
                L.traceback()
                raise WorkspaceError("Can't remove file %s. Please Check File Permission." % path)
Пример #7
0
    def mkdir(self, folder, host="", clear=False):
        if not type(folder) in [str, unicode]:
            raise WorkspaceError("folder must be strings.")
        if host == "":
            path = os.path.join(self.root(), folder)
        else:
            if not os.path.exists(host): self._mkdir_recursive(host)
            path = os.path.join(host, folder)

        if os.path.exists(path):
            if len(os.listdir(path)) > 0:
                L.warning("It is not vacant folder in the path.")
                if clear:
                    try:
                        for f in os.listdir(path):
                            shutil.rmtree(os.path.join(path, f))
                    except Exception as e:
                        L.traceback()
                        raise WorkspaceError("it must be vacant folder in the path.")
        else:
            self._mkdir_recursive(path)
        return path