當前位置: 首頁>>代碼示例>>Python>>正文


Python types.XDict類代碼示例

本文整理匯總了Python中Naked.toolshed.types.XDict的典型用法代碼示例。如果您正苦於以下問題:Python XDict類的具體用法?Python XDict怎麽用?Python XDict使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了XDict類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的Naked.toolshed.types.XDict類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。