本文整理汇总了Python中Naked.toolshed.types.XDict类的典型用法代码示例。如果您正苦于以下问题:Python XDict类的具体用法?Python XDict怎么用?Python XDict使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XDict类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: write_files
def write_files(self):
the_file_xdict = XDict(self.file_dictionary)
for filepath, file_string in the_file_xdict.xitems():
fw = nfile.FileWriter(filepath)
try:
fw.write_utf8(file_string)
except TypeError as te: # catch unicode write errors
fw.write(file_string)
开发者ID:INAP-LABS,项目名称:noc-orchestrator,代码行数:8,代码来源:make.py
示例2: test_xdict_key_xlist
def test_xdict_key_xlist(self):
xd = XDict({'a_one': 'value_one', 'b_two': 'value_two', 'c_three': 'value_three'}, {'attrkey': 'attrval'})
xl = xd.key_xlist()
self.assertEqual(type(xl), type(XList(['item']))) #actually makes XList
self.assertTrue(len(xl) == 3) # includes all items
self.assertTrue('a_one' in xl) # includes appropriate items in XList
self.assertTrue('b_two' in xl)
self.assertTrue('c_three' in xl)
self.assertEqual(xl.attrkey, 'attrval') # includes original attributes
开发者ID:chrisidefix,项目名称:naked,代码行数:9,代码来源:test_TYPES_c.py
示例3: test_xdict_equals_newobj_addattr
def test_xdict_equals_newobj_addattr(self):
xd = XDict({'key': 'value'})
xn = XDict({'key': 'value'})
xd.test = 'testing'
xn.test = 'testing'
self.assertTrue(hasattr(xd, 'test'))
self.assertTrue(hasattr(xn, 'test'))
self.assertTrue(xd.equals(xn))
self.assertTrue(xd == xn)
self.assertFalse(xd != xn)
开发者ID:chrisidefix,项目名称:naked,代码行数:10,代码来源:test_TYPES_c.py
示例4: test_xdict_map_to_vals
def test_xdict_map_to_vals(self):
def cap_val(xdict_val):
return xdict_val.upper()
xd = XDict({'a_one': 'value_one', 'b_two': 'value_two', 'a_three': 'value_three'}, {'attrkey': 'attrval'})
xd = xd.map_to_vals(cap_val)
self.assertEqual(type(xd), type(XDict({'test': 'dict'})))
self.assertTrue(len(xd.values()) == 3)
self.assertTrue('VALUE_ONE' in xd.values())
self.assertTrue('VALUE_TWO' in xd.values())
self.assertTrue('VALUE_THREE' in xd.values())
self.assertEqual(xd.attrkey, 'attrval')
开发者ID:chrisidefix,项目名称:naked,代码行数:12,代码来源:test_TYPES_c.py
示例5: test_xdict_conditional_map_to_vals
def test_xdict_conditional_map_to_vals(self):
def true_a(xdict_key):
return xdict_key.startswith('a')
def cap_val(xdict_val):
return xdict_val.upper()
xd = XDict({'a_one': 'value_one', 'b_two': 'value_two', 'a_three': 'value_three'}, {'attrkey': 'attrval'})
xd = xd.conditional_map_to_vals(true_a, cap_val)
self.assertTrue(len(xd.values()) == 3)
self.assertTrue('VALUE_ONE' in xd.values())
self.assertTrue('VALUE_THREE' in xd.values())
self.assertTrue('value_two' in xd.values())
self.assertFalse('VALUE_TWO' in xd.values()) # the b_two value was not converted as per the conditional function
开发者ID:chrisidefix,项目名称:naked,代码行数:14,代码来源:test_TYPES_c.py
示例6: test_xdict_val_count_integer
def test_xdict_val_count_integer(self):
xd = XDict({'one': 1, 'two': 1, 'three': 3})
self.assertEqual(xd.val_count(1), 2)
self.assertEqual(xd.val_count(3), 1)
self.assertEqual(xd.val_count(10), 0) # missing value count is 0
开发者ID:chrisidefix,项目名称:naked,代码行数:5,代码来源:test_TYPES_c.py
示例7: test_xdict_val_count_string
def test_xdict_val_count_string(self):
xd = XDict({'one': '1', 'two': '1', 'three': '3'})
self.assertEqual(xd.val_count('1'), 2)
self.assertEqual(xd.val_count('3'), 1)
self.assertEqual(xd.val_count('10'), 0) # missing value count is 0
开发者ID:chrisidefix,项目名称:naked,代码行数:5,代码来源:test_TYPES_c.py
示例8: test_xdict_sum_vals_string_type
def test_xdict_sum_vals_string_type(self):
xd = XDict({'one': '1', 'two': '2', 'three': '3'})
with self.assertRaises(TypeError): # raises TypeError when inappropriate types in the XDict vals
xd.sum_vals()
开发者ID:chrisidefix,项目名称:naked,代码行数:4,代码来源:test_TYPES_c.py
示例9: test_xdict_equals_newobj_emptyattrs
def test_xdict_equals_newobj_emptyattrs(self):
xd = XDict({'key': 'value'})
xn = XDict({'key': 'value'})
self.assertTrue(xd.equals(xn))
self.assertTrue(xd == xn)
self.assertFalse(xd != xn)
开发者ID:chrisidefix,项目名称:naked,代码行数:6,代码来源:test_TYPES_c.py
示例10: test_xdict_equals_newobj_diffattrval
def test_xdict_equals_newobj_diffattrval(self):
xd = XDict({'key': 'value'}, {'attrkey': 'diff'})
xn = XDict({'key': 'value'}, {'attrkey': 'attrval'})
self.assertFalse(xd.equals(xn))
self.assertFalse(xd == xn)
self.assertTrue(xd != xn)
开发者ID:chrisidefix,项目名称:naked,代码行数:6,代码来源:test_TYPES_c.py
示例11: test_xdict_key_intersection_when_none_present
def test_xdict_key_intersection_when_none_present(self):
xd = XDict({'one': 1, 'two': 1, 'three': 3})
xn = XDict({'oneone': 1, 'twotwo': 1, 'threethree': 3})
self.assertEqual(len(xd.intersection(xn)), 0)
self.assertEqual(xd.intersection(xn), set([]))
开发者ID:chrisidefix,项目名称:naked,代码行数:5,代码来源:test_TYPES_c.py
示例12: test_xdict_key_difference_when_none_present
def test_xdict_key_difference_when_none_present(self):
xd = XDict({'one': 1, 'two': 1, 'three': 3})
xn = XDict({'one': 1, 'two': 1, 'three': 3})
self.assertEqual(xd.difference(xn), set([])) # returns empty set
开发者ID:chrisidefix,项目名称:naked,代码行数:4,代码来源:test_TYPES_c.py
示例13: test_xdict_builtin_dictionary_method
def test_xdict_builtin_dictionary_method(self):
xd = XDict({'key': 'value'}, {'attrkey': 'attrval'})
nd = {'another': 'value2'}
xd.update(nd) # test a built in dictionary method on an XDict
self.assertEqual(xd['another'], 'value2')
self.assertEqual(xd.attrkey, 'attrval') # confirm that attribute remains
开发者ID:chrisidefix,项目名称:naked,代码行数:6,代码来源:test_TYPES_c.py
示例14: test_xdict_add_attribute
def test_xdict_add_attribute(self):
xd = XDict({'key': 'value'}, {'attrkey': 'attrval'})
xd.newatt = 'the test'
self.assertEqual(xd.newatt, 'the test')
开发者ID:chrisidefix,项目名称:naked,代码行数:4,代码来源:test_TYPES_c.py
示例15: test_xdict_equals_newobj_diff_dicttypes
def test_xdict_equals_newobj_diff_dicttypes(self):
xd = XDict({'key': '1'}, {'attrkey': 'attrval'})
xn = XDict({'key': 1}, {'attrkey': 'attrval'})
self.assertFalse(xd.equals(xn))
self.assertFalse(xd == xn)
self.assertTrue(xd != xn)
开发者ID:chrisidefix,项目名称:naked,代码行数:6,代码来源:test_TYPES_c.py
示例16: test_xdict_equals_newobj_diffattr_number
def test_xdict_equals_newobj_diffattr_number(self):
xd = XDict({'key': 'value'}, {'attrkey': 'attrval', 'another': 'test'})
xn = XDict({'key': 'value'}, {'attrkey': 'attrval'})
self.assertFalse(xd.equals(xn))
self.assertFalse(xd == xn)
self.assertTrue(xd != xn)
开发者ID:chrisidefix,项目名称:naked,代码行数:6,代码来源:test_TYPES_c.py
示例17: test_xdict_val_count_ci
def test_xdict_val_count_ci(self):
xd = XDict({'one': 'TEST', 'two': 'Test', 'int': 1})
self.assertEqual(xd.val_count_ci('test'), 2)
开发者ID:chrisidefix,项目名称:naked,代码行数:3,代码来源:test_TYPES_c.py
示例18: test_xdict_key_difference
def test_xdict_key_difference(self):
xd = XDict({'one': 1, 'two': 1, 'three': 3})
xn = XDict({'one': 1, 'twotwo': 1, 'three': 3})
self.assertEqual(len(xd.difference(xn)), 1)
self.assertEqual(xd.difference(xn), set(['two']))
开发者ID:chrisidefix,项目名称:naked,代码行数:5,代码来源:test_TYPES_c.py
示例19: test_xdict_max_val_strings
def test_xdict_max_val_strings(self):
xd = XDict({'one': '1', 'two': '2', 'three': '3'})
value, key = xd.max_val()
self.assertEqual(xd.max_val(), ('3', 'three')) # returns a tuple
self.assertEqual(value, '3')
self.assertEqual(key, 'three')
开发者ID:chrisidefix,项目名称:naked,代码行数:6,代码来源:test_TYPES_c.py
示例20: test_xdict_key_intersection
def test_xdict_key_intersection(self):
xd = XDict({'one': 1, 'two': 1, 'three': 3})
xn = XDict({'one': 1, 'twotwo': 1, 'three': 3})
self.assertEqual(len(xd.intersection(xn)), 2)
self.assertEqual(xd.intersection(xn), set(['one', 'three']))
开发者ID:chrisidefix,项目名称:naked,代码行数:5,代码来源:test_TYPES_c.py
注:本文中的Naked.toolshed.types.XDict类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论