From 6d9521fff519412e66d585d8f980824414a218eb Mon Sep 17 00:00:00 2001 From: "Yiting.Li" Date: Tue, 19 Jan 2016 14:39:31 +0800 Subject: JIRA: BOTTLENECKS-29 add the performance test framework add the copyright on the code. Change-Id: I6ec9eefe65bf07c2dd6c636d1b90b64da303952e Signed-off-by: Yiting.Li (cherry picked from commit 5b4f794932cb9b28ec679e6dd88e6febb2a5db7b) --- vstf/vstf/common/candy_text.py | 61 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 vstf/vstf/common/candy_text.py (limited to 'vstf/vstf/common/candy_text.py') diff --git a/vstf/vstf/common/candy_text.py b/vstf/vstf/common/candy_text.py new file mode 100755 index 00000000..818ae767 --- /dev/null +++ b/vstf/vstf/common/candy_text.py @@ -0,0 +1,61 @@ +############################################################################## +# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + + +import sys + +THIS = sys.modules[__name__] +__id_max = 100 +__style_max = 10 +dom = {"chapter", "section", "unit"} +element = {"title", "table", "figure", "paragraph", "plot", "chart", "space"} + +nodes = dom | element +for _node in nodes: + setattr(THIS, _node, _node) + + +def tuple2text(sn, node, style): + assert sn in range(__id_max) + assert style in range(__style_max) + assert node in nodes + return "%02d##%s#%d" % (sn, node, style) + + +def dict2text(info): + assert "sn" in info and info["sn"] in range(__id_max) + assert "style" in info and info["style"] in range(__style_max) + assert "node" in info and info["node"] in nodes + return "%02d##%s#%d" % (info["sn"], info["node"], info["style"]) + + +def text2dict(candy): + tmp = candy.replace("##","#").split("#") + result = { + "sn": int(tmp[0]), + "node": tmp[1], + "style": int(tmp[2]) + } + assert result["sn"] in range(__id_max) + assert result["style"] in range(__style_max) + assert result["node"] in nodes + return result + + +def text2tuple(candy): + tmp = candy.replace("##","#").split("#") + + sn = int(tmp[0]) + node = tmp[1] + style = int(tmp[2]) + + assert sn in range(__id_max) + assert style in range(__style_max) + assert node in nodes + return sn, node, style -- cgit 1.2.3-korg