Exemplo n.º 1
0
    def test_object_referencecount_delete(self):
        t = CustomObjectStore(1)
        t2 = CustomObjectStore(2)
        t_ref_count = 2
        t2_ref_count = 2

        tbl = Table({"a": [1], "b": [t]}, index="a")
        t_ref_count += 1

        assert tbl.schema() == {"a": int, "b": object}
        assert tbl.size() == 1

        # Count references
        # 1 for `t`, 1 for `data`, 1 for argument to sys.getrefcount, and 1 for the table
        print(sys.getrefcount(t), "should be", t_ref_count)
        print(sys.getrefcount(t2), "should be", t2_ref_count)

        tbl.update({"a": [2], "b": [t]})
        t_ref_count += 1
        tbl.update({"a": [3], "b": [t]})
        t_ref_count += 1

        assert sys.getrefcount(t) == t_ref_count

        tbl.remove([1])

        tbl.clear()
        assert tbl.size() == 0
        assert tbl.view().to_dict() == {}
        print(sys.getrefcount(t), "should be", 2)
        assert sys.getrefcount(t) == 2
        print(sys.getrefcount(t2), "should be", 2)
        assert sys.getrefcount(t2) == 2
Exemplo n.º 2
0
 def test_remove_multiple_single(self):
     tbl = Table({"a": int, "b": str}, index="a")
     for i in range(0, 10):
         tbl.update([{"a": i, "b": str(i)}])
     for i in range(1, 10):
         tbl.remove([i])
     assert tbl.view().to_records() == [{"a": 0, "b": "0"}]
Exemplo n.º 3
0
 def test_remove_nonsequential(self):
     tbl = Table([{
         "a": "abc",
         "b": 123
     }, {
         "a": "def",
         "b": 456
     }, {
         "a": "efg",
         "b": 789
     }], {"index": "a"})
     tbl.remove(["abc", "efg"])
     assert tbl.view().to_records() == [{"a": "def", "b": 456}]
Exemplo n.º 4
0
 def test_remove_all(self):
     tbl = Table([{"a": "abc", "b": 123}], index="a")
     tbl.remove(["abc"])
     assert tbl.view().to_records() == []