-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtest_array.py
More file actions
122 lines (115 loc) · 5.15 KB
/
test_array.py
File metadata and controls
122 lines (115 loc) · 5.15 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# SPDX-FileCopyrightText: 2025-present The Firebird Projects <www.firebirdsql.org>
#
# SPDX-License-Identifier: MIT
#
# PROGRAM/MODULE: firebird-driver
# FILE: tests/test_array.py
# DESCRIPTION: Tests for Array type
# CREATED: 10.4.2025
#
# Software distributed under the License is distributed AS IS,
# WITHOUT WARRANTY OF ANY KIND, either express or implied.
# See the License for the specific language governing rights
# and limitations under the License.
#
# The Original Code was created by Pavel Cisar
#
# Copyright (c) Pavel Cisar <pcisar@users.sourceforge.net>
# and all contributors signed below.
#
# All Rights Reserved.
# Contributor(s): ______________________________________.
#
# See LICENSE.TXT for details.
import datetime
import decimal
import pytest
from firebird.driver import InterfaceError, DatabaseError
# Common data setup
c2 = [[[1, 1], [2, 2], [3, 3], [4, 4]], [[5, 5], [6, 6], [7, 7], [8, 8]], [[9, 9], [10, 10], [11, 11], [12, 12]], [[13, 13], [14, 14], [15, 15], [16, 16]]]
c3 = [['a', 'a'], ['bb', 'bb'], ['ccc', 'ccc'], ['dddd', 'dddd'], ['eeeee', 'eeeee'], ['fffffff78901234', 'fffffff78901234']]
c4 = ['a ', 'bb ', 'ccc ', 'dddd ', 'eeeee']
c5 = [datetime.datetime(2012, 11, 22, 12, 8, 24, 474800), datetime.datetime(2012, 11, 22, 12, 8, 24, 474800)]
c6 = [datetime.time(12, 8, 24, 474800), datetime.time(12, 8, 24, 474800)]
c7 = [decimal.Decimal('10.22'), decimal.Decimal('100000.33')]
c8 = [decimal.Decimal('10.22'), decimal.Decimal('100000.33')]
c9 = [1, 0]
c10 = [5555555, 7777777]
c11 = [3.140000104904175, 3.140000104904175]
c12 = [3.14, 3.14]
c13 = [decimal.Decimal('10.2'), decimal.Decimal('100000.3')]
c14 = [decimal.Decimal('10.22222'), decimal.Decimal('100000.333')]
c15 = [decimal.Decimal('1000000000000.22222'), decimal.Decimal('1000000000000.333')]
c16 = [True, False, True]
@pytest.fixture(autouse=True)
def setup_array_test(db_connection):
con = db_connection
# Ensure table exists or skip
try:
with con.cursor() as cur:
# Simplified check, assume table exists if no error
cur.execute("SELECT c1 FROM AR WHERE 1=0")
except DatabaseError as e:
if "Table unknown AR" in str(e):
pytest.skip("Table 'AR' needed for array tests does not exist.")
else:
raise
# Insert initial data needed for read tests
with con.cursor() as cur:
cur.execute("delete from AR") # Clean first
cur.execute("insert into ar (c1,c2) values (2,?)",[c2])
cur.execute("insert into ar (c1,c3) values (3,?)",[c3])
cur.execute("insert into ar (c1,c4) values (4,?)",[c4])
cur.execute("insert into ar (c1,c5) values (5,?)",[c5])
cur.execute("insert into ar (c1,c6) values (6,?)",[c6])
cur.execute("insert into ar (c1,c7) values (7,?)",[c7])
cur.execute("insert into ar (c1,c8) values (8,?)",[c8])
cur.execute("insert into ar (c1,c9) values (9,?)",[c9])
cur.execute("insert into ar (c1,c10) values (10,?)",[c10])
cur.execute("insert into ar (c1,c11) values (11,?)",[c11])
cur.execute("insert into ar (c1,c12) values (12,?)",[c12])
cur.execute("insert into ar (c1,c13) values (13,?)",[c13])
cur.execute("insert into ar (c1,c14) values (14,?)",[c14])
cur.execute("insert into ar (c1,c15) values (15,?)",[c15])
con.commit()
yield
def test_basic(db_connection):
with db_connection.cursor() as cur:
cur.execute("select LANGUAGE_REQ from job "\
"where job_code='Eng' and job_grade=3 and job_country='Japan'")
row = cur.fetchone()
assert row == (['Japanese\n', 'Mandarin\n', 'English\n', '\n', '\n'],)
cur.execute('select QUART_HEAD_CNT from proj_dept_budget')
row = cur.fetchall()
# ... (assert list contents) ...
assert len(row) > 10 # Example check
def test_read_full(db_connection):
with db_connection.cursor() as cur:
cur.execute("select c1,c2 from ar where c1=2")
row = cur.fetchone()
assert row[1] == c2
# ... (rest of the read tests using assert) ...
cur.execute("select c1,c15 from ar where c1=15")
row = cur.fetchone()
assert row[1] == c15
def test_write_full(db_connection):
with db_connection.cursor() as cur:
# INTEGER
cur.execute("insert into ar (c1,c2) values (102,?)", [c2])
db_connection.commit()
cur.execute("select c1,c2 from ar where c1=102")
row = cur.fetchone()
assert row[1] == c2
# ... (rest of the write tests using assert) ...
# BOOLEAN
cur.execute("insert into ar (c1,c16) values (116,?)", [c16])
db_connection.commit()
cur.execute("select c1,c16 from ar where c1=116")
row = cur.fetchone()
assert row[1] == c16
def test_write_wrong(db_connection):
with db_connection.cursor() as cur:
with pytest.raises(ValueError, match='Incorrect ARRAY field value.'):
cur.execute("insert into ar (c1,c2) values (102,?)", [c3]) # Wrong type
with pytest.raises(ValueError, match='Incorrect ARRAY field value.'):
cur.execute("insert into ar (c1,c2) values (102,?)", [c2[:-1]]) # Wrong dimensions