本文整理汇总了Python中treedict.TreeDict.hash方法的典型用法代码示例。如果您正苦于以下问题:Python TreeDict.hash方法的具体用法?Python TreeDict.hash怎么用?Python TreeDict.hash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类treedict.TreeDict
的用法示例。
在下文中一共展示了TreeDict.hash方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testhashes_12
# 需要导入模块: from treedict import TreeDict [as 别名]
# 或者: from treedict.TreeDict import hash [as 别名]
def testhashes_12(self):
p1 = TreeDict('hashes_test_tree')
p1.a.b.c.asdf = deepcopy(test_list)
p2 = TreeDict('hashes_test_tree')
p2.a.b.c.asdf = deepcopy(test_list)
self.assert_(p1.hash() == p2.hash())
示例2: testhashes_02
# 需要导入模块: from treedict import TreeDict [as 别名]
# 或者: from treedict.TreeDict import hash [as 别名]
def testhashes_02(self):
p1 = TreeDict('hashes_test_tree')
p1.asdf = "1234"
p2 = TreeDict('hashes_test_tree')
p2.asdf = "1235"
self.assert_(len(p1.hash()) != 0)
self.assert_(p1.hash() != p2.hash())
示例3: testhashes_03
# 需要导入模块: from treedict import TreeDict [as 别名]
# 或者: from treedict.TreeDict import hash [as 别名]
def testhashes_03(self):
p1 = TreeDict('hashes_test_tree')
p1.asdf = "1234"
p2 = TreeDict('hashes_test_tree')
p2.asdf = "1234"
self.assert_(len(p1.hash("asdf")) != 0)
self.assert_(p1.hash("asdf") == p2.hash("asdf"))
示例4: testhashes_04
# 需要导入模块: from treedict import TreeDict [as 别名]
# 或者: from treedict.TreeDict import hash [as 别名]
def testhashes_04(self):
p1 = TreeDict('hashes_test_tree')
p1.asdf = 221.12345139
p2 = TreeDict('hashes_test_tree')
p2.asdf = 221.12345139
self.assert_(len(p1.hash("asdf")) != 0)
self.assert_(p1.hash("asdf") == p2.hash("asdf"))
示例5: testhashes_15_attaching
# 需要导入模块: from treedict import TreeDict [as 别名]
# 或者: from treedict.TreeDict import hash [as 别名]
def testhashes_15_attaching(self):
p1 = TreeDict('root')
p1.b1 = TreeDict('b1')
h = p1.hash()
p1.attach(copy = False, recursive = True)
self.assert_(p1.hash() != h)
示例6: testhashes_05
# 需要导入模块: from treedict import TreeDict [as 别名]
# 或者: from treedict.TreeDict import hash [as 别名]
def testhashes_05(self):
p1 = TreeDict('hashes_test_tree')
p1.asdf = 1234498484884499393939999324322432
p2 = TreeDict('hashes_test_tree')
p2.asdf = 1234498484884499393939999324322432
self.assert_(len(p1.hash("asdf")) != 0)
self.assert_(p1.hash("asdf") == p2.hash("asdf"))
示例7: __call__
# 需要导入模块: from treedict import TreeDict [as 别名]
# 或者: from treedict.TreeDict import hash [as 别名]
def __call__(self, *args, **kwargs):
# Use TreeDict to allow for mutable parameters / kwargs
kw_t = TreeDict(**kwargs)
arg_t = TreeDict(args = args)
cache_key = ( kw_t.hash(), arg_t.hash())
try:
return self.cache[cache_key]
except KeyError:
self.cache[cache_key] = value = self.func(*args, **kwargs)
return value
示例8: testHashError_03
# 需要导入模块: from treedict import TreeDict [as 别名]
# 或者: from treedict.TreeDict import hash [as 别名]
def testHashError_03(self):
p = TreeDict()
p.a.b = {'a' : lambda: None}
self.assertRaises(HashError, lambda: p.hash())
try:
p.hash()
except HashError as he:
self.assert_(he.key == 'a.b', he.key)
示例9: testHashError_05_custom
# 需要导入模块: from treedict import TreeDict [as 别名]
# 或者: from treedict.TreeDict import hash [as 别名]
def testHashError_05_custom(self):
p = TreeDict()
class HType:
def __init__(self):
self.h = 1
def __treedict_hash__(self):
self.h += 1
return self.h
p.a.b.c = HType()
self.assert_(p.hash() != p.hash())
示例10: itemHash
# 需要导入模块: from treedict import TreeDict [as 别名]
# 或者: from treedict.TreeDict import hash [as 别名]
def itemHash(self, *items):
"""
Returns a hash of arbitrary items. This is intended to be
used for fine-grained control of dependencies on parameters;
the resulting value can passed to :ref:`inCache`,
:ref:`loadFromCache`, and :ref:`saveToCache`. For example::
key = self.itemHash(self.p.x1, self.p.x2)
if self.inCache(key):
return self.loadFromCache(key)
else:
# process, create obj
self.saveToCache(key, obj)
Note that most of this functionality is provided by specifying
`items` as a tuple to the key argument of :ref:inCache,
:ref:loadFromCache, or :ref:saveToCache.
"""
t = TreeDict()
for n, it in enumerate(items):
t["b%d" % n] = it
return t.hash()
示例11: testCopying_01d
# 需要导入模块: from treedict import TreeDict [as 别名]
# 或者: from treedict.TreeDict import hash [as 别名]
def testCopying_01d(self):
p1 = TreeDict('root')
p1.a = 123
p2 = deepcopy(p1)
self.assert_(p1 == p2)
self.assert_(p1.hash() == p2.hash())
示例12: testCopying_02d_dangling
# 需要导入模块: from treedict import TreeDict [as 别名]
# 或者: from treedict.TreeDict import hash [as 别名]
def testCopying_02d_dangling(self):
p1 = TreeDict('root')
p1.a
p2 = deepcopy(p1)
self.assert_(p1 == p2)
self.assert_(p1.hash() == p2.hash())
示例13: testhashes_20a_infinite_recursion_raises_error
# 需要导入模块: from treedict import TreeDict [as 别名]
# 或者: from treedict.TreeDict import hash [as 别名]
def testhashes_20a_infinite_recursion_raises_error(self):
p = TreeDict()
p.makeBranch("a")
p.a.b.c = p.a
self.assertRaises(RuntimeError, lambda: p.hash())
示例14: testpruning_03
# 需要导入模块: from treedict import TreeDict [as 别名]
# 或者: from treedict.TreeDict import hash [as 别名]
def testpruning_03(self):
p = TreeDict('prunetest')
p.a.b.c = 123
h1 = p.hash()
self.assert_('a.b.c' in p)
del p.a.b.c
self.assert_('a.b.c' not in p)
h2 = p.hash()
p.a.b.c = 123
h3 = p.hash()
self.assert_(h1 != h2)
self.assert_(h1 == h3)
示例15: testpruning_02
# 需要导入模块: from treedict import TreeDict [as 别名]
# 或者: from treedict.TreeDict import hash [as 别名]
def testpruning_02(self):
p = TreeDict('prunetest')
p.a.b.c = 123
h1 = p.hash()
self.assert_('a.b.c' in p)
p.pop('a.b.c', prune_empty=True)
self.assert_('a.b' not in p)
h2 = p.hash()
p.a.b.c = 123
h3 = p.hash()
self.assert_(h1 != h2)
self.assert_(h1 == h3)