def test_mod(self): other_dict = smart({'t1': 1, 'ta': 2, 't32': 3, 'j3': 4}) result1 = other_dict % '^t[0-9]+$' result2 = other_dict % compile('^t[0-9]+$') self.assertDictEqual(smart(result1), {'t1': 1, 't32': 3}) self.assertDictEqual(smart(result2), {'t1': 1, 't32': 3})
def test_del_slice(self): copy_list = deepcopy(self.smart_list) del copy_list[0:10] result_list = smart(copy_list) compare_list = list(range(11, 21)) self.assertListEqual(result_list, compare_list)
def test_multiple_remove(self): normal_list = copy(self.test_list) result = self.smart_list - [18, 19, 20] for i in [18, 19, 20]: normal_list.remove(i) self.assertListEqual(smart(result), normal_list)
def test_step(self): self.assertListEqual(smart(self.smart_list[::5]), [1, 6, 11, 16])
def test_del_item(self): copy_list = deepcopy(self.smart_list) del copy_list[4] result_list = smart(copy_list) self.assertFalse(5 in result_list)
def test_add(self): result = self.smart_dict + {'d': 4} self.assertDictEqual(smart(result), {'a': 1, 'b': 2, 'c': 3, 'd': 4})
def test_intersection(self): result = self.smart_list & [1, 2, 3, 99] self.assertListEqual(smart(result), [1, 2, 3])
def test_single_remove(self): normal_list = copy(self.test_list) result = self.smart_list - 20 normal_list.remove(20) self.assertListEqual(smart(result), normal_list)
def test_concat(self): result = self.smart_list + [21, 22, 23] self.assertListEqual(smart(result), self.test_list + [21, 22, 23])
def test_append(self): example_list = smart([1, 2, 3]) example_list.append(4) self.assertEqual(example_list[3], 4)
def test_flatten(self): example_list = smart([1, [2, 3, [4]], [5, 6], 7, [8, [[9, [[10]]]]]]) comparison_list = list(range(1, 11)) result = smart(~example_list) self.assertListEqual(result, comparison_list)
def test_convert_normal(self): self.assertDictEqual(smart(self.smart_dict), self.test_dict)
def setUp(self): self.test_dict = {'a': 1, 'b': 2, 'c': 3} self.smart_dict = smart(self.test_dict)
def test_copy(self): copy_dict = self.smart_dict.copy() self.assertDictEqual(smart(self.smart_dict), smart(copy_dict))
def test_flatten(self): other_dict = smart({'a': 1, 'b': {'c': 2}}) flattened = ~other_dict self.assertDictEqual(smart(flattened), {'a': 1, 'b-c': 2})
def test_mul(self): result = self.smart_list * 2 self.assertListEqual(smart(result), self.test_list * 2)
def setUp(self): self.test_list = list(range(1, 21)) self.smart_list = smart(self.test_list)
def test_get_slice(self): self.assertListEqual(smart(self.smart_list[1:4]), [2, 3, 4])
def test_add_item(self): normal_list = copy(self.test_list) result = self.smart_list + 21 normal_list.append(21) self.assertListEqual(smart(result), normal_list)
def test_copy(self): copy_list = self.smart_list.copy() self.assertListEqual(smart(self.smart_list), smart(copy_list))
def test_convert_normal(self): self.assertListEqual(smart(self.smart_list), self.test_list)
def test_get_multiple(self): result = self.smart_list[[2, 4, -1]] list_result = smart(result) self.assertListEqual(list_result, [3, 5, 20])
def test_filter(self): normal_list = copy(self.test_list) result = self.smart_list % (lambda x: not x % 2) normal_result = list(filter(lambda x: not x % 2, normal_list)) self.assertListEqual(smart(result), normal_result)
def test_get_multiple(self): filtered_dict = self.smart_dict[['a', 'b']] self.assertDictEqual(smart(filtered_dict), {'a': 1, 'b': 2})