Exemplo n.º 1
0
 def test_it_supports_slice_with_steps_on_objects(self):
     fake_obj1 = self.objectFake()
     fake_obj2 = self.objectFake()
     fake_obj3 = self.objectFake()
     fake_obj4 = self.objectFake()
     self.wr_list = WeakList([fake_obj1, fake_obj2, fake_obj3, fake_obj4])
     expected = WeakList([self.ref_item(1)(), self.ref_item(3)()])
     self.assertEqual(expected, self.wr_list[1::2])
Exemplo n.º 2
0
 def test_it_supports_sort_with_reverse(self):
     fake_obj0 = self.objectFake()
     fake_obj1 = self.objectFake()
     self.wr_list.extend([fake_obj0, fake_obj1])
     expected = WeakList(sorted(list(self.wr_list), reverse=True))
     not_expected = WeakList(sorted(list(self.wr_list)))
     self.wr_list.sort(reverse=True)
     self.assertEqual(expected, self.wr_list)
     self.assertNotEqual(not_expected, self.wr_list)
Exemplo n.º 3
0
 def test_extend_update_finalizer(self):
     fake_obj = self.objectFake()
     wr_list = WeakList([fake_obj])
     self.wr_list.extend(wr_list)
     del fake_obj
     self.assertEqual(1, len(wr_list))
     self.assertEqual(1, len(self.wr_list))
Exemplo n.º 4
0
 def test_addition_update_finalizer(self):
     fake_obj = self.objectFake()
     wr_list = WeakList([fake_obj])
     self.wr_list += wr_list
     del fake_obj
     self.assertEqual(1, len(wr_list))
     self.assertEqual(1, len(self.wr_list))
Exemplo n.º 5
0
 def test_it_appends_ref_values_at_init_wth_exception(self):
     fake_obj = self.objectFake()
     wr_list = WeakList([fake_obj])
     self.assertEqual(1, len(wr_list))
     del fake_obj
     self.assertEqual(1, len(wr_list))
     with self.assertRaises(TreeDeletedException):
         wr_list[0]
Exemplo n.º 6
0
 def test_it_supports_sort(self):
     fake_obj0 = self.objectFake()
     fake_obj1 = self.objectFake()
     self.wr_list.extend([fake_obj1, fake_obj0])
     expected = WeakList(sorted(list(self.wr_list)))
     self.wr_list.sort()
     self.assertGreater(fake_obj1, fake_obj0)
     self.assertEqual(expected, self.wr_list)
Exemplo n.º 7
0
 def test_get_slice_update_finalizer(self):
     fake_obj1 = self.objectFake()
     fake_obj2 = self.objectFake()
     self.wr_list = WeakList([fake_obj1, fake_obj2])
     sliced = self.wr_list[1:]
     del fake_obj2
     self.assertEqual(2, len(self.wr_list))
     self.assertEqual(1, len(sliced))
Exemplo n.º 8
0
 def test_extend_update_finalizer_with_exception(self):
     fake_obj = self.objectFake()
     wr_list = WeakList([fake_obj])
     self.wr_list.extend(wr_list)
     del fake_obj
     self.assertEqual(1, len(wr_list))
     self.assertEqual(1, len(self.wr_list))
     with self.assertRaises(TreeDeletedException):
         wr_list[0]
     with self.assertRaises(TreeDeletedException):
         self.wr_list[0]
Exemplo n.º 9
0
    def test_it_supports_sort_with_key(self):
        def index_plus_2_if_odd(item):
            return item.index + 2 if item.index % 2 != 0 else item.index

        fake_obj0 = self.objectFake()
        fake_obj1 = self.objectFake()
        self.wr_list.extend([fake_obj1, fake_obj0])
        expected = WeakList(sorted(list(self.wr_list),
                                   key=index_plus_2_if_odd))
        self.wr_list.sort(key=index_plus_2_if_odd)
        self.assertEqual(expected, self.wr_list)
Exemplo n.º 10
0
 def test_get_slice_update_finalizer_with_exception(self):
     fake_obj1 = self.objectFake()
     fake_obj2 = self.objectFake()
     self.wr_list = WeakList([fake_obj1, fake_obj2])
     sliced = self.wr_list[1:]
     del fake_obj2
     self.assertEqual(2, len(self.wr_list))  #1
     self.assertEqual(1, len(sliced))  #0
     with self.assertRaises(TreeDeletedException):
         sliced[0]
     with self.assertRaises(TreeDeletedException):
         self.wr_list[1]
Exemplo n.º 11
0
 def setUp(self):
     self.wr_list = WeakList()
Exemplo n.º 12
0
 def test_it_supports_slice_on_int(self):
     self.wr_list = WeakList(range(10))
     self.assertEqual(
         [self.ref_item(1),
          self.ref_item(2),
          self.ref_item(3)], self.wr_list[1:4])
Exemplo n.º 13
0
 def test_it_appends_ref_values_at_init(self):
     fake_obj = self.objectFake()
     wr_list = WeakList([fake_obj])
     self.assertEqual(1, len(wr_list))
     del fake_obj
     self.assertEqual(1, len(wr_list))
Exemplo n.º 14
0
 def test_it_supports_addition(self):
     fake_obj = self.objectFake()
     expected = WeakList([fake_obj])
     self.wr_list += expected
     self.assertEqual(expected, self.wr_list)
     self.assertEqual(1, len(self.wr_list))