本文整理汇总了Python中Naked.toolshed.types.XList类的典型用法代码示例。如果您正苦于以下问题:Python XList类的具体用法?Python XList怎么用?Python XList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_xlist_remove_dupes_int
def test_xlist_remove_dupes_int(self):
xl = XList([1, 2, 2, 3, 3, 3], {'first_attr': 1})
nodupe = xl.remove_duplicates()
self.assertEqual(type(nodupe), type(XList(['test', 'again'])))
self.assertEqual(nodupe.count(1), 1)
self.assertEqual(nodupe.count(2), 1)
self.assertEqual(nodupe.count(3), 1)
示例2: test_xlist_multi_wildcard_match
def test_xlist_multi_wildcard_match(self):
xl = XList(['many', 'tom', 'Many'], {'first_attr': 1})
nl = xl.multi_wildcard_match('m*|t*')
self.assertTrue(len(nl) == 2)
self.assertTrue('many' in nl)
self.assertTrue('tom' in nl)
self.assertFalse('Many' in nl)
示例3: test_xlist_difference
def test_xlist_difference(self):
xl = XList([1 , 2, 3], {'first_attr': 1})
xl2 = XList([2, 4, 5])
diff = xl.difference(xl2) # returns items in XList that are not in parameter list/XList as set
self.assertTrue(1 in diff)
self.assertTrue(3 in diff)
self.assertFalse(2 in diff)
self.assertFalse(4 in diff)
self.assertFalse(5 in diff)
示例4: test_xlist_intersection
def test_xlist_intersection(self):
xl = XList([1 , 2, 3], {'first_attr': 1})
xl2 = XList([2, 4, 5])
inter = xl.intersection(xl2) # returns items in both XList and parameter list/XList
self.assertTrue(2 in inter)
self.assertFalse(1 in inter)
self.assertFalse(3 in inter)
self.assertFalse(4 in inter)
self.assertFalse(5 in inter)
示例5: test_xlist_map_items
def test_xlist_map_items(self):
def cap_val(xlist_item):
return xlist_item.upper()
xl = XList(['one', 'two', 'three'], {'first_attr': 1})
nl = xl.map_to_items(cap_val)
self.assertTrue('ONE' in nl)
self.assertTrue('TWO' in nl)
self.assertTrue('THREE' in nl)
self.assertFalse('one' in nl)
self.assertFalse('two' in nl)
self.assertFalse('three' in nl)
示例6: test_xlist_conditional_map_items
def test_xlist_conditional_map_items(self):
def true_a(xdict_key):
return xdict_key.startswith('a')
def cap_val(xdict_val):
return xdict_val.upper()
xl = XList(['all', 'many', 'none'], {'first_attr': 1})
nl = xl.conditional_map_to_items(true_a, cap_val)
self.assertTrue('ALL' in nl)
self.assertFalse('all' in nl)
self.assertFalse('MANY' in nl)
self.assertFalse('NONE' in nl)
self.assertTrue(nl[0] == 'ALL')
self.assertTrue(nl[1] == 'many')
self.assertTrue(nl[2] == 'none')
示例7: test_xlist_count_case_insensitive_withother
def test_xlist_count_case_insensitive_withother(self):
xl = XList(['MANY', 1, 'many'], {'first_attr': 1})
nl = xl.count_ci('Many')
self.assertTrue(nl == 2)
示例8: test_xlist_map_items_noreturn_value
def test_xlist_map_items_noreturn_value(self):
def no_return(xlist_val):
x = 1
xl = XList(['one', 'two', 'three'], {'first_attr': 1})
nl = xl.map_to_items(no_return)
self.assertTrue(nl[0] == None)
示例9: test_xlist_surround_two_strings
def test_xlist_surround_two_strings(self):
xl = XList(['one', 'two', 'three'], {'first_attr': 1})
nl = xl.surround('<p>', '</p>')
self.assertTrue('<p>one</p>' in nl)
self.assertTrue('<p>two</p>' in nl)
self.assertTrue('<p>three</p>' in nl)
示例10: test_xlist_postfix_unicode_char
def test_xlist_postfix_unicode_char(self):
xl = XList(['one', 'two', 'three'], {'first_attr': 1})
nl = xl.postfix('ত')
self.assertTrue('oneত' in nl)
self.assertTrue('twoত' in nl)
self.assertTrue('threeত' in nl)
示例11: test_xlist_wildcard_match
def test_xlist_wildcard_match(self):
xl = XList(['MANY', 'many', 'Many'], {'first_attr': 1})
nl = xl.wildcard_match('m*')
self.assertTrue(len(nl) == 1)
self.assertEqual(nl[0], 'many')
示例12: test_xlist_shuffle
def test_xlist_shuffle(self):
xl = XList([1 , 2, 3], {'first_attr': 1})
nl = xl.random_sample(2)
示例13: test_xlist_count_dupes_string_twodupe
def test_xlist_count_dupes_string_twodupe(self):
xl = XList(['test', 'test', 'another', 'another', 'last', 'last'], {'first_attr': 1})
dupes = xl.count_duplicates()
self.assertEqual(dupes, 3)
示例14: test_xlist_count_dupes_int_twodupe
def test_xlist_count_dupes_int_twodupe(self):
xl = XList([1, 2, 2, 3, 3, 3], {'first_attr': 1})
dupes = xl.count_duplicates()
self.assertEqual(dupes, 3)
示例15: test_xlist_sum_float
def test_xlist_sum_float(self):
xl = XList([1.2 , 2.5, 3.1], {'first_attr': 1})
total = xl.sum()
self.assertAlmostEqual(total, 6.8)