################################################################################
#
# Copyright (c) 2019, the Perspective Authors.
#
# This file is part of the Perspective library, distributed under the terms of
# the Apache License 2.0.  The full license can be found in the LICENSE file.
#

from perspective.table import Table
import psutil
import os


class TestDelete(object):

    # delete

    def test_table_delete(self):
        process = psutil.Process(os.getpid())
        mem = process.memory_info().rss
        for x in range(10000):
            data = [{"a": 1, "b": 2}, {"a": 3, "b": 4}]
            tbl = Table(data)
            tbl.delete()
        
        mem2 = process.memory_info().rss

        # assert 1 < (max2 / max) < 1.01
        assert (mem2 - mem) < 2000000

    def test_table_delete_with_view(self, sentinel):
        data = [{"a": 1, "b": 2}, {"a": 3, "b": 4}]
        tbl = Table(data)

        process = psutil.Process(os.getpid())
        mem = process.memory_info().rss
        for x in range(10000):
            view = tbl.view()
            view.delete()
        
        tbl.delete()
        mem2 = process.memory_info().rss
        assert (mem2 - mem) < 2000000
