在机器人框架测试用例中,我设置了一个变量,然后进行了一个过程.
因为变量的设置不是一个非常有趣的信息,我不想在我的报告中包含它.
| Verifying STUFF |
| | ${endpoint}= | set variable | STUFF
| | Verify
Run Code Online (Sandbox Code Playgroud)
我的报告包含:
KEYWORD: ${endpoint} = BuiltIn.Set Variable STUFF
Run Code Online (Sandbox Code Playgroud)
但我宁愿不在那里.如何告诉Robot Framework不记录该行?
- - - 编辑 - - -
它看起来应该这样做:
pybot --removekeywords NAME:SetVariable testcase.txt
Run Code Online (Sandbox Code Playgroud)
但Set Variable关键字仍然存在.
(是的,我将我的机器人框架升级到2.8.3以利用此功能.)
显然我在这里缺少一些严肃的东西.这是我的测试程序:
"""
Doc and nothing but doc
"""
class TestMe(object):
"""
class documentation goes here
"""
def testFunc(self):
"""
FunctionDoc Goes here
"""
print "Hello world"
if __name__ =="__main__":
t=TestMe()
t.testFunc()
Run Code Online (Sandbox Code Playgroud)
我运行它并打印出"Hello world",natch.但是pydoc.py test.py给出这个:
no Python documentation found for 'test.py'
Run Code Online (Sandbox Code Playgroud)
显然我在这里缺少一些简单的东西,但是什么呢?
--edit-- Per Vishnu的建议我print t.__doc__在文件的最后一行添加了" ",现在运行该文件给出了:
Hello world
class documentation goes here
Run Code Online (Sandbox Code Playgroud)
但是pydoc仍然没有找到任何文档.
我在Robot Framework中使用了一个嵌套列表。我想在Robot Framework级别的子列表中更改一项。
我的清单如下所示:
[鲍勃,玛丽,[六月,七月,八月]]
我想将“七月”更改为其他内容,例如“九月”
Robot Framework将让我更改“ bob”或“ mary”,但是如果我尝试插入列表,它将转换为字符串。
(哦,我尝试使用“插入列表关键字”来插入一个新的子列表,以及其他列表关键字,但运气不好。)
我试图解析一个相对复杂的JSON.它有直接节点,并且它具有可变数量的元素的数组.这是一个示例:
{
status: 200,
generated: "2014-07-23T13:09:30.315Z",
copyright: "Copyright (c) 2014 Us Not You. All Rights Reserved.",
results: 1,
start: 0,
links: {
next: null,
prev: null,
self: "http://thing.com/thing.json"
},
docs: [
{
id: "thingID_001",
}
]
}
Run Code Online (Sandbox Code Playgroud)
当然是简化的.可能有零个或多个文档,每个文档都有许多节点."链接"很简单,我用正确的字段定义一个结构,然后我们去.但是文档,我无法进入元帅.这是我的代码:
import (
"net/http"
"fmt"
"io/ioutil"
"encoding/json"
)
type Thinglinks struct {
Next string
Prev string
Self string
}
//type ThingDoc struct {
// Id string
// Type string
//}
type ThingSection struct {
Status int
Generated string
Copyright string
Results int
Start …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用jsdom来分析一些HTML内容.我见过的例子使用基于html内容的jsdom.jsdom文档的.createWindow()方法.
但是当我尝试按照这些示例时,我的文档没有.createWindow()方法.
var getaPage=function (req, res, callback) {
jsdom.defaultDocumentFeatures={
FetchExternalResources : ['script'],
ProcessExternalResources : ['script'],
MutationEvents : '2.0',
QuerySelector : false
};
var htmlDoc = '<html lang="en-US">' +
'</html>';
var tstDocument=jsdom.jsdom(htmlDoc);
for (var attr in tstDocument){
if (attr == 'createWindow') {
console.log('Found it');
}else{
console.log('not it');
};
};
};
Run Code Online (Sandbox Code Playgroud)
当我运行这个时,我得到了一堆'不是'而没有'找到它'.
为什么我没有.createWindow()方法?
我需要创建一个特殊的dict子类.在其中我想为一组键设置默认值.
我似乎没有找到正确的语法来做到这一点.
这是我一直在尝试的:
class NewDict(dict):
Key1 = "stuff"
Key2 = "Other stuff"
NoList = []
Nada = None
Run Code Online (Sandbox Code Playgroud)
然后我实例化一个像这样的对象:
PrefilledDict = NewDict()
Run Code Online (Sandbox Code Playgroud)
并试图在那里使用一些东西:
print PrefilledDict['Key1']
Run Code Online (Sandbox Code Playgroud)
但似乎我的字典不是字典.
我错过了什么?
我可能正在接近这个错误,但我会感激被理顺.
我希望能够同时使用类的某些属性的值和名称
样品:
class DoStuff(object):
def __init__(self):
self.a="Alpha"
self.b="Beta"
self.c="Gamma"
def printStuff(self):
for thing in [self.a, self.b, self.c]:
print NAMEOFTHING, thing
Run Code Online (Sandbox Code Playgroud)
我想要的是:
Run Code Online (Sandbox Code Playgroud)a Alpha b Beta c Gamma
我怎么能得到它?
编辑:有些混乱,因为我的例子显示我打印了所有的值.相反,我想要这个:
Run Code Online (Sandbox Code Playgroud)a Alpha c Gamma
我的打印方法列表中只有'a'和'c'.
我需要说服自己这是一个坏主意.我想为同一个变量分配第二个名称,其内容可能会发生变化.
A='Bob'
B=A #wrong function, I want to figure out something that works here.
A='Alice'
print A
print B
Run Code Online (Sandbox Code Playgroud)
我希望A和B都打印'Alice',而B打印'Bob',A打印'Alice'.
我为什么要这样做?在我的代码中,我使用一个名称来表示一些数据,这对于处理是有意义的,但是另一个名称对于用户输入是有意义的.argparse似乎想根据命令行选项分配变量名.所以我想在输入数据时使用一个名称,但在处理数据时使用另一个名称.我宁愿避免将一个复制到另一个,但那是我的后备位置.
好的,我有一本叫做食物的字典.食物有两个元素,都是字典本身,蔬菜和乳制品.蔬菜有两个元素根:萝卜和茎:芦笋.乳制品有奶酪:切达干酪和酸奶:草莓.我还有一个新的字典水果,有红色:樱桃和黄色:香蕉.
food['veg']['root'] == 'Turnip'
food['dairy']['cheese'] == 'Cheddar'
Run Code Online (Sandbox Code Playgroud)
等等
fruit['red'] == 'Cherry'
Run Code Online (Sandbox Code Playgroud)
现在我想将"水果"字典全部添加到"食物"字典中,以便我将:
food['fruit']['red'] == 'Cherry'
Run Code Online (Sandbox Code Playgroud)
我知道我可以这样做:
food['fruit'] = fruit
Run Code Online (Sandbox Code Playgroud)
但这看起来很笨拙.我想做点什么
food.Append(fruit)
Run Code Online (Sandbox Code Playgroud)
但这并不能满足我的需要.
(编辑从变量名中删除了初始大写,因为这似乎导致分心.)
这应该很容易,但因为我遗漏了一些东西.
我有一个完全符合我预期的对象.
class TextElement(ContentItemElement):
'''
Single String Elements, for example, headlines
'''
def __init__(self, name, data):
super(TextElement, self).__init__()
self.name=name
self.text=data
def prettyPrint(self):
printstring = u'*HTML* '
self.name.encode('utf-8')
printstring += u'<h3> '+self.name+u' </h3>'
self.text.encode('utf-8')
printstring += u'<p> '+self.text+u' </h3>'
print printstring
Run Code Online (Sandbox Code Playgroud)
好的,很好,我可以实例化它,它完全符合我的要求.但我真的想创建一个更具体的TextObjects版本.所以我这样做:
class CiteElement(TextElement):
'''
Single String Elements, for example, headlines
'''
def __init__(self, name, data):
super(CiteElement, self).__init__()
self.validValues=['Crap I make up', 'Crap I found on the web']
Run Code Online (Sandbox Code Playgroud)
但是当我尝试实例化它时,这有效:
ee = TextElement(element, self.raw[element])
ee.validValues=['Crap I make up', 'Crap I found on …Run Code Online (Sandbox Code Playgroud) python ×6
dictionary ×2
attributes ×1
go ×1
jsdom ×1
json ×1
marshalling ×1
namespaces ×1
node.js ×1
object ×1
oop ×1
pydoc ×1
subclass ×1