本文整理汇总了Python中Danu.Output.set_attribute方法的典型用法代码示例。如果您正苦于以下问题:Python Output.set_attribute方法的具体用法?Python Output.set_attribute怎么用?Python Output.set_attribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Danu.Output
的用法示例。
在下文中一共展示了Output.set_attribute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestOutputWriteAttribute
# 需要导入模块: from Danu import Output [as 别名]
# 或者: from Danu.Output import set_attribute [as 别名]
class TestOutputWriteAttribute(unittest.TestCase):
def setUp(self):
self.filename = 'test-Output.h5'
self.int_attr_name = 'Dummy Int Attribute'
self.double_attr_name = 'Dummy Double Attribute'
self.str_attr_name = 'Dummy String Attribute'
self.fh = Output(self.filename,'a')
def tearDown(self):
if os.path.exists(self.filename):
self.fh.close()
os.remove(self.filename)
def test_string_attribute(self):
import random
str_len = random.randint(16,1024)
self.fh.set_attribute(self.str_attr_name,os.urandom(str_len))
def test_double_attribute(self):
import random
self.fh.set_attribute(self.double_attr_name,random.random())
def test_int_attribute(self):
import random
self.fh.set_attribute(self.int_attr_name,random.randint(0,100000))
示例2: TestOutputReadAttribute
# 需要导入模块: from Danu import Output [as 别名]
# 或者: from Danu.Output import set_attribute [as 别名]
class TestOutputReadAttribute(unittest.TestCase):
def setUp(self):
import random
import string
self.filename = 'test-Output.h5'
self.fh = Output(self.filename,'w')
self.attributes = []
self.int_attr_name = 'Dummy Int Attribute'
self.attributes.append(self.int_attr_name)
self.int_attr = random.randint(0,1000000)
self.fh.set_attribute(self.int_attr_name,self.int_attr)
self.double_attr_name = 'Dummy Double Attribute'
self.attributes.append(self.double_attr_name)
self.double_attr = random.random()
self.fh.set_attribute(self.double_attr_name,self.double_attr)
self.str_attr_name = 'Dummy String Attribute'
self.attributes.append(self.str_attr_name)
str_len = random.randint(10,1024)
self.str_attr = ''.join(random.choice(string.letters) for i in xrange(str_len))
self.fh.set_attribute(self.str_attr_name,self.str_attr)
def tearDown(self):
if os.path.exists(self.filename):
self.fh.close()
os.remove(self.filename)
def test_string_attribute(self):
test_str = self.fh.get_attribute(self.str_attr_name)
self.assertEqual(test_str,self.str_attr)
def test_double_attribute(self):
test_double = self.fh.get_attribute(self.double_attr_name)
self.assertEqual(test_double,self.double_attr)
def test_int_attribute(self):
test_int = self.fh.get_attribute(self.int_attr_name)
self.assertEqual(test_int,self.int_attr)
def test_attributes(self):
attributes = self.fh.attributes()
for attr in self.attributes:
if attr not in attributes: TestCase.fail('Failed to read attributes correctly')