Exemple #1
0
 def test_manager_host(self):
     manager = PerspectiveManager()
     table = Table(data)
     manager.host(table)
     table.update({"a": [4, 5, 6], "b": ["d", "e", "f"]})
     names = manager.get_table_names()
     assert manager.get_table(names[0]).size() == 6
Exemple #2
0
    def test_async_queue_process(self):
        tbl = Table({
            "a": int,
            "b": float,
            "c": str
        })
        manager = PerspectiveManager()
        manager._set_queue_process(TestAsync.wrapped_queue_process)
        manager.host(tbl)

        assert tbl.size() == 0

        for i in range(5):
            tbl.update([data[i]])

        table_id = tbl._table.get_id()
        pool = tbl._table.get_pool()

        assert _PerspectiveStateManager.TO_PROCESS == {
            table_id: pool
        }
        assert tbl.view().to_records() == data[:5]

        # should have flushed the process queue
        assert _PerspectiveStateManager.TO_PROCESS == {}
Exemple #3
0
    def test_async_single_manager_tables_chained(self):
        columns = {"index": int, "num1": int, "num2": int}
        manager = PerspectiveManager()
        tbl = Table(columns, index="index")
        view = tbl.view()
        tbl2 = Table(view.to_arrow(), index=tbl.get_index())
        manager.host(tbl, "tbl")
        manager.host(tbl2, "tbl2")
        view.on_update(lambda port, delta: tbl2.update(delta), "row")
        manager.set_loop_callback(TestAsync.loop.add_callback)

        for i in range(1000):
            manager.call_loop(tbl.update, [{
                "index": i,
                "num1": i,
                "num2": 2 * i
            }])
            i += 1

        q = queue.Queue()
        manager.call_loop(q.put, True)
        q.get()

        @syncify
        def _tbl_task2():
            size = tbl2.size()
            return size

        assert _tbl_task2() == 1000
        view.delete()
        tbl.delete()
        tbl2.delete()
Exemple #4
0
    def test_async_queue_process_multiple_ports(self):
        tbl = Table({"a": int, "b": float, "c": str})
        port_ids = [0]
        port_data = [{"a": 0, "b": 0, "c": "0"}]

        for i in range(10):
            port_id = tbl.make_port()
            port_ids.append(port_id)
            port_data.append({
                "a": port_id,
                "b": port_id * 1.5,
                "c": str(port_id)
            })

        assert port_ids == list(range(0, 11))
        manager = PerspectiveManager()
        manager.host(tbl)
        manager.set_loop_callback(TestAsync.loop.add_callback)

        assert syncify(lambda: tbl.size())() == 0

        random.shuffle(port_ids)

        @syncify
        def _tbl_task():
            for port_id in port_ids:
                idx = port_id if port_id < len(port_ids) else len(port_ids) - 1
                tbl.update([port_data[idx]], port_id=port_id)
            size = tbl.size()
            tbl.delete()
            return size

        assert len(port_ids) == 11
        assert _tbl_task() == 11
Exemple #5
0
 def test_manager_host_table_or_view(self):
     manager = PerspectiveManager()
     table = Table(data)
     view = table.view()
     manager.host(table, name="table1")
     manager.host(view, name="view1")
     assert manager.get_table("table1").size() == 3
     assert manager.get_view("view1").to_dict() == data
Exemple #6
0
    def test_async_call_loop(self):
        tbl = Table({"a": int, "b": float, "c": str})
        manager = PerspectiveManager()
        manager.set_loop_callback(TestAsync.loop.add_callback)
        manager.call_loop(tbl.update, data)
        manager.host(tbl)

        @syncify
        def _task():
            return tbl.size()

        assert _task() == 10
        tbl.delete()
Exemple #7
0
    def test_async_queue_process(self):
        tbl = Table({"a": int, "b": float, "c": str})
        manager = PerspectiveManager()
        manager.set_loop_callback(TestAsync.loop.add_callback)
        manager.host(tbl)

        @syncify
        def _task():
            assert tbl.size() == 0
            for i in range(5):
                tbl.update([data[i]])
            return tbl.size()

        assert _task() == 5
        tbl.delete()
Exemple #8
0
    def test_async_queue_process_csv(self):
        """Make sure GIL release during CSV loading works"""
        tbl = Table("x,y,z\n1,a,true\n2,b,false\n3,c,true\n4,d,false")
        manager = PerspectiveManager()
        manager.set_loop_callback(TestAsync.loop.add_callback)
        manager.host(tbl)

        @syncify
        def _task():
            assert tbl.size() == 4
            for i in range(5):
                tbl.update("x,y,z\n1,a,true\n2,b,false\n3,c,true\n4,d,false")
            return tbl.size()

        assert _task() == 24

        tbl.delete()
Exemple #9
0
    def test_async_queue_process(self):
        tbl = Table({
            "a": int,
            "b": float,
            "c": str
        })
        manager = PerspectiveManager()
        manager._set_queue_process(TestAsync.wrapped_queue_process)
        manager.host(tbl)

        assert tbl.size() == 0

        for i in range(5):
            tbl.update([data[i]])

        # process should have been called at least once
        assert SENTINEL.get() > 0

        tbl.delete()
Exemple #10
0
    def test_async_call_loop_error_if_no_loop(self):
        tbl = Table({"a": int, "b": float, "c": str})
        manager = PerspectiveManager()

        with raises(PerspectiveError):
            # loop not set - errors
            manager.call_loop(tbl.update, data)

        manager.set_loop_callback(TestAsync.loop.add_callback)
        manager.call_loop(tbl.update, data)
        manager.host(tbl)

        @syncify
        def _task():
            return tbl.size()

        # subsequent calls to call_loop will work if loop_callback is set.
        assert _task() == 10

        tbl.delete()
Exemple #11
0
    def test_async_queue_process_multiple_ports(self):
        tbl = Table({
            "a": int,
            "b": float,
            "c": str
        })

        port_ids = [0]
        port_data = [{
            "a": 0,
            "b": 0,
            "c": "0"
        }]

        for i in range(10):
            port_id = tbl.make_port()
            port_ids.append(port_id)
            port_data.append({
                "a": port_id,
                "b": port_id * 1.5,
                "c": str(port_id)
            })

        assert port_ids == list(range(0, 11))

        manager = PerspectiveManager()
        manager._set_queue_process(TestAsync.wrapped_queue_process)
        manager.host(tbl)

        assert tbl.size() == 0

        random.shuffle(port_ids)

        for port_id in port_ids:
            idx = port_id if port_id < len(port_ids) else len(port_ids) - 1
            tbl.update([port_data[idx]], port_id=port_id)

        # assert that process is being called asynchronously
        assert SENTINEL.get() > 0

        tbl.delete()
Exemple #12
0
 def test_manager_host_invalid(self):
     manager = PerspectiveManager()
     with raises(PerspectiveError):
         manager.host({})