How to use dumpTree method in fMBT

Best Python code snippet using fMBT_python

list2tree.py

Source:list2tree.py Github

copy

Full Screen

1#!/usr/bin/python2#coding:utf-834def BuildTree(arr):5 """ 很特殊的转换树的函数, TODO: 'p' 参数化6 >>> t=BuildTree([{}, {'p':0}, {'p':0}, {'p':1}, {}, {'p':0}])7 >>> DumpTree(t)8 09 110 311 212 513 414 >>> t=BuildTree([{}])15 >>> DumpTree(t)16 017 >>> t=BuildTree([{}, {}])18 >>> DumpTree(t)19 020 121 >>> t=BuildTree([{}, {'p':0}])22 >>> DumpTree(t)23 024 125 >>> t=BuildTree([{}, {}, {'p':1}])26 >>> DumpTree(t)27 028 129 230 >>> t=BuildTree([{}, {'p':2}, {}]) # 诡异的情形,早期的条目居然是后来的子节点31 >>> DumpTree(t)32 033 234 >>> arr = [{u'name': u'testa', u'p': u'-1'}, {u'body': u'2.a', u'name': u'testa', u'p': u'-1'}]35 >>> BuildTree(arr)36 []37 """38 39 tree = []40 for i in range(0, len(arr)):41 a = arr[i]42 a['i'] = i43 if 'p' not in a or ('p' in a and '-1' == a['p']):44 tree.append(a)45 # print 'root', i46 else:47 # 处理诡异情形48 if len(tree) < a['p'] or not isinstance(a['p'], int):49 continue50 51 # print 'c', i52 53 p = arr[a['p']]54 if 'child' not in p:55 p['child'] = []5657 p['child'].append(a)58 return tree596061def DumpTree(t, indent=0, f=lambda item: item['i']):62 for i in t:63 print "%s%s" % (' ' * indent, f(i))6465 if 'child' in i:66 DumpTree(i['child'], 1+indent)676869if __name__ == "__main__":70 # t=BuildTree([{}, {'p':0}, {'p':0}, {'p':1}, {}, {'p':0}])71 # DumpTree(t)72 import doctest ...

Full Screen

Full Screen

dumptree.py

Source:dumptree.py Github

copy

Full Screen

...5 value = {'extremely-long-key-name': 'sensitive-content'}6 level = 37 names = {'extremely-long-key-name': 1}8 pos = 09 self.assertEqual('{"extremely-...": -hidden-}', dumpTree(value, level, names, pos))10 def test_hide_sensitive_pos(self):11 value = ['one', 'two', 'three', 'four']12 level = 313 names = {'extremely-long-key-name': 1}14 pos = int('1010', 2)15 self.assertEqual('("one", -hidden-, "three", -hidden-)', dumpTree(value, level, names, pos))16 def test_dict_key_types(self):17 level = 318 names = {}19 pos = 020 self.assertEqual('{true: "first"}', dumpTree({True: 'first'}, level, names, pos))21 self.assertEqual('{false: "second"}', dumpTree({False: 'second'}, level, names, pos))22 self.assertEqual('{3: "third"}', dumpTree({3: 'third'}, level, names, pos))23 self.assertEqual('{4.2: "fourth"}', dumpTree({4.2: 'fourth'}, level, names, pos))24 self.assertEqual('{"5": "fifth"}', dumpTree({'5': 'fifth'}, level, names, pos))25 test_hash_object = TestHashObject('sixth')26 self.assertEqual('{'+str(test_hash_object)+': "sixth"}', dumpTree({test_hash_object: 'sixth'}, level, names, pos))27class TestHashObject(object):28 def __init__(self, name):29 self.name = name30 def __hash__(self):31 return hash((self.name))32if __name__ == '__main__':...

Full Screen

Full Screen

4073.py

Source:4073.py Github

copy

Full Screen

...5 value = {'extremely-long-key-name': 'sensitive-content'}6 level = 37 names = {'extremely-long-key-name': 1}8 pos = 09 self.assertEqual('{"extremely-...": -hidden-}', dumpTree(value, level, names, pos))10 def test_hide_sensitive_pos(self):11 value = ['one', 'two', 'three', 'four']12 level = 313 names = {'extremely-long-key-name': 1}14 pos = int('1010', 2)15 self.assertEqual('("one", -hidden-, "three", -hidden-)', dumpTree(value, level, names, pos))16 def test_dict_key_types(self):17 level = 318 names = {}19 pos = 020 self.assertEqual('{true: "first"}', dumpTree({True: 'first'}, level, names, pos))21 self.assertEqual('{false: "second"}', dumpTree({False: 'second'}, level, names, pos))22 self.assertEqual('{3: "third"}', dumpTree({3: 'third'}, level, names, pos))23 self.assertEqual('{4.2: "fourth"}', dumpTree({4.2: 'fourth'}, level, names, pos))24 self.assertEqual('{"5": "fifth"}', dumpTree({'5': 'fifth'}, level, names, pos))25 test_hash_object = TestHashObject('sixth')26 self.assertEqual('{'+str(test_hash_object)+': "sixth"}', dumpTree({test_hash_object: 'sixth'}, level, names, pos))27class TestHashObject(object):28 def __init__(self, name):29 self.name = name30 def __hash__(self):31 return hash((self.name))32if __name__ == '__main__':...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fMBT automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful