File: test_common.py

package info (click to toggle)
python-clickhouse-driver 0.2.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,516 kB
  • sloc: python: 10,950; pascal: 42; makefile: 31; sh: 3
file content (50 lines) | stat: -rw-r--r-- 1,768 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from tests.testcase import BaseTestCase


class CommonTestCase(BaseTestCase):
    client_kwargs = {'settings': {'insert_block_size': 1}}

    def setUp(self):
        super(CommonTestCase, self).setUp()

        self.send_data_count = 0
        old_send_data = self.client.connection.send_data

        def send_data(*args, **kwargs):
            self.send_data_count += 1
            return old_send_data(*args, **kwargs)

        self.client.connection.send_data = send_data

    def test_insert_block_size(self):
        with self.create_table('a UInt8'):
            data = [(x, ) for x in range(4)]
            self.client.execute(
                'INSERT INTO test (a) VALUES', data
            )
            # Two empty blocks: for end of sending external tables
            # and data.
            self.assertEqual(self.send_data_count, 4 + 2)

            query = 'SELECT * FROM test'
            inserted = self.emit_cli(query)
            self.assertEqual(inserted, '0\n1\n2\n3\n')
            inserted = self.client.execute(query)
            self.assertEqual(inserted, data)

    def test_columnar_insert_block_size(self):
        with self.create_table('a UInt8'):
            data = [(0, 1, 2, 3)]
            self.client.execute(
                'INSERT INTO test (a) VALUES', data, columnar=True
            )
            # Two empty blocks: for end of sending external tables
            # and data.
            self.assertEqual(self.send_data_count, 4 + 2)

            query = 'SELECT * FROM test'
            inserted = self.emit_cli(query)
            self.assertEqual(inserted, '0\n1\n2\n3\n')
            inserted = self.client.execute(query)
            expected = [(0, ), (1, ), (2, ), (3, )]
            self.assertEqual(inserted, expected)