Skip to content

Commit 70d2e05

Browse files
committed
Added/Updated tests\bugs\gh_7548_test.py: refactored, see notes
1 parent ba5eecf commit 70d2e05

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

tests/bugs/gh_7548_test.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,30 @@
99
No errors must occur for all of them.
1010
NOTES:
1111
[19.04.2023] pzotov
12-
Confirmed bug on 4.0.3.2930, 5.0.0.1017
12+
Confirmed bug on 4.0.3.2929, 5.0.0.1014
1313
Checked on 4.0.3.2931, 5.0.0.1021 - all OK.
14+
15+
[31.08.2023] pzotov
16+
Refactored:
17+
* output of checked timestamp can be suppressed, see redirection: 'out {os.devnull}';
18+
* there is no need to display the same error messages for many charsets; rather, we can use dictionary
19+
with key = error message and val = list of character sets which did not pass check (i.e. for which
20+
we get "SQLSTATE = 22001 / ... / -string right truncation / -expected length N, actual M";
21+
* removed unneeded substitutions, use 'init' arg for db_factory in order to make test run faster;
1422
"""
1523

24+
import os
1625
import pytest
1726
from firebird.qa import *
1827
from firebird.driver import CHARSET_MAP
28+
from collections import defaultdict
1929

20-
db = db_factory()
30+
db = db_factory(init = 'recreate table test(f01 timestamp with time zone);')
2131

2232
ts = '19-APR-2023 21:15:19.0110'
2333
test_sql = f"""
2434
set list on;
25-
recreate table test(f01 timestamp with time zone);
35+
delete from test;
2636
insert into test values(timestamp '{ts}');
2737
set term ^;
2838
execute block as
@@ -31,17 +41,13 @@
3141
end
3242
^
3343
set term ;^
44+
out {os.devnull};
3445
select * from test;
35-
commit;
46+
out;
47+
rollback;
3648
"""
3749

38-
substitutions = [ ('[\t ]+', ' '), (f'F01 {ts} .*', f'F01 {ts}') ]
39-
40-
act = python_act('db', substitutions = substitutions)
41-
42-
expected_stdout = f"""
43-
F01 {ts} Europe/Moscow
44-
"""
50+
act = python_act('db')
4551

4652
@pytest.mark.version('>=4.0.3')
4753
def test_1(act: Action, capsys):
@@ -51,26 +57,24 @@ def test_1(act: Action, capsys):
5157
cur.execute("select trim(c.rdb$character_set_name) from rdb$character_sets c where coalesce(c.rdb$system_flag,0)<>0 and c.rdb$character_set_name not in ('NONE', 'OCTETS')")
5258
cset_list = [x[0] for x in cur.fetchall() if x[0] in CHARSET_MAP]
5359

54-
#print(cset_list)
55-
#assert '' == capsys.readouterr().out
60+
# Result: cset_list = ['ASCII', 'UNICODE_FSS', 'UTF8', 'SJIS_0208', ..., 'KOI8U', 'WIN1258', 'GBK', 'GB18030']
5661

57-
cset_fails = {}
58-
for x in cset_list:
62+
cset_fails = defaultdict(list)
63+
for cset_i in cset_list:
5964
act.reset()
60-
act.expected_stdout = expected_stdout
61-
act.isql(switches=['-q'], charset = x, input = test_sql, combine_output = True)
65+
act.expected_stdout = ''
66+
act.isql(switches=['-q'], charset = cset_i, input = test_sql, combine_output = True)
6267
if act.clean_stdout == act.clean_expected_stdout:
6368
pass
6469
else:
65-
cset_fails[x] = act.clean_stdout
70+
cset_fails[act.clean_stdout] += cset_i,
6671

6772
if cset_fails:
68-
print('Detected fail for some charset(s):')
73+
print('Detected fails:')
6974
for k,v in sorted(cset_fails.items()):
70-
print( f'charset: {k}' )
75+
print('Character sets:', ','.join(v))
7176
print('Result:')
72-
for p in v.split('\n'):
73-
print(p)
77+
print(k)
7478
print('')
75-
79+
7680
assert '' == capsys.readouterr().out

0 commit comments

Comments
 (0)