def test_normal(self): logger.clear_log() assert len(logger.get_log()) == 0 logger.info("a") assert len(logger.get_log()) == 1 logger.clear_log() assert len(logger.get_log()) == 0
def moveFile(cls, src_path, dst_path): import shutil try: check_file_existence(src_path) except FileNotFoundError: _, e, _ = sys.exc_info() # for python 2.5 compatibility logger.debug(e) return False if os.path.realpath(src_path) == os.path.realpath(dst_path): logger.debug("%s and %s are the same file" % ( src_path, dst_path)) return True logger.info("move: %s -> %s" % (src_path, dst_path)) if not cls.__dry_run: shutil.move(src_path, dst_path) return True
def rename(cls, src_path, dst_path): try: check_file_existence(src_path) except (InvalidFilePathError, FileNotFoundError): _, e, _ = sys.exc_info() # for python 2.5 compatibility logger.exception(e) return False if dataproperty.is_empty_string(dst_path): logger.error("empty destination path") return False if os.path.lexists(dst_path): logger.error("'%s' already exists" % (dst_path)) return False logger.info("rename: %s -> %s" % (src_path, dst_path)) if not cls.__dry_run: os.rename(src_path, dst_path) return True
def __call__(self, *args): import thutils.gfile as gfile return_value = -1 try: return_value = self.function() return return_value except (gfile.InvalidFilePathError, gfile.FileNotFoundError): _, e, _ = sys.exc_info() # for python 2.5 compatibility logger.exception(e) return_value = EX_NOINPUT return return_value except IOError: _, e, _ = sys.exc_info() # for python 2.5 compatibility logger.exception(e) return_value = EX_IOERR return return_value except ValueError: _, e, _ = sys.exc_info() # for python 2.5 compatibility logger.exception(e) return_value = EX_SOFTWARE return return_value except ImportError: _, e, _ = sys.exc_info() # for python 2.5 compatibility logger.exception(e) return_value = EX_OSFILE return return_value except KeyboardInterrupt: logger.info( self.KEYBOARD_INTERRUPT_FORMAT % (os.path.basename(__file__))) return_value = 1 return return_value except Exception: _, e, _ = sys.exc_info() # for python 2.5 compatibility logger.exception(e) return_value = 1 return return_value finally: logger.debug("exit code: " + str(return_value))
def test_smoke(self, message, caller): logger.info(message, caller)