6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-22 21:43:06 +01:00
firebird-qa/tests/bugs/core_5092_test.py

225 lines
7.5 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
#
# id: bugs.core_5092
# title: ISQL extract command looses COMPUTED BY field types
2021-11-29 20:54:28 +01:00
# decription:
2021-04-26 20:07:00 +02:00
# Test creates database with empty table T1 that has computed by fileds with DDL appopriate to the ticket issues.
# Then we:
# 1) extract metadata from database and store it to <init_meta.sql>;
# 2) run query to the table T1 with setting sqlda_display = ON, and store output to <init_sqlda.log>;
# 3) DROP table T1;
# 4) try to apply script with extracted metadata (see step "1") - it should pass without errors;
# 5) AGAIN extract metadata and store it to <last_meta.sql>;
# 6) AGAIN run query to T1 with set sqlda_display = on, and store output to <last_sqlda.log>;
2021-11-29 20:54:28 +01:00
# 7) compare text files:
2021-04-26 20:07:00 +02:00
# <init_meta.sql> vs <last_meta.sql>
# <init_sqlda.log> vs <last_sqlda.log>
# 8) Check that result of comparison is EMPTY (no rows).
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# Confirmed bug on 3.0.0.32300, fixed on 3.0.0.32306.
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# tracker_id: CORE-5092
# min_versions: ['3.0']
# versions: 3.0
# qmid: None
import pytest
2021-11-29 20:54:28 +01:00
from difflib import unified_diff
from firebird.qa import db_factory, python_act, Action
2021-04-26 20:07:00 +02:00
# version: 3.0
# resources: None
substitutions_1 = []
init_script_1 = """
recreate table t1 (
n0 int
,si smallint computed by( 32767 )
,bi bigint computed by ( 2147483647 )
,s2 smallint computed by ( mod(bi, nullif(si,0)) )
,dv double precision computed by (pi())
,fv float computed by (dv*dv)
,nv numeric(3,1) computed by (sqrt(fv))
,dt date computed by ('now')
,tm time computed by ('now')
,dx timestamp computed by ( dt )
,tx timestamp computed by ( tm )
2021-11-29 20:54:28 +01:00
2021-04-26 20:07:00 +02:00
,c1 char character set win1251 computed by ('ы')
,c2 char character set win1252 computed by ('å')
,cu char character set utf8 computed by ('')
2021-11-29 20:54:28 +01:00
2021-04-26 20:07:00 +02:00
,c1x char computed by(c1)
,c2x char computed by(c2)
,cux char computed by(cu)
2021-11-29 20:54:28 +01:00
2021-04-26 20:07:00 +02:00
,b1 blob character set win1251 computed by ('ы')
,b2 blob character set win1252 computed by ('ä')
,bu blob character set utf8 computed by ('')
,bb blob computed by ('')
2021-11-29 20:54:28 +01:00
2021-04-26 20:07:00 +02:00
,b1x blob computed by (b1)
,b2x blob computed by (b2)
,bux blob computed by (bu)
,bbx blob computed by (bb)
2021-11-29 20:54:28 +01:00
);
2021-04-26 20:07:00 +02:00
--insert into t1 values(null);
2021-11-29 20:54:28 +01:00
commit;
"""
2021-04-26 20:07:00 +02:00
db_1 = db_factory(charset='UTF8', sql_dialect=3, init=init_script_1)
# test_script_1
#---
# import os
# import time
# import subprocess
# import difflib
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# os.environ["ISC_USER"] = user_name
# os.environ["ISC_PASSWORD"] = user_password
# db_file = db_conn.database_name
# db_conn.close()
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# #--------------------------------------------
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# def flush_and_close(file_handle):
# # https://docs.python.org/2/library/os.html#os.fsync
2021-11-29 20:54:28 +01:00
# # If you're starting with a Python file object f,
# # first do f.flush(), and
2021-04-26 20:07:00 +02:00
# # then do os.fsync(f.fileno()), to ensure that all internal buffers associated with f are written to disk.
# global os
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# file_handle.flush()
# if file_handle.mode not in ('r', 'rb') and file_handle.name != os.devnull:
# # otherwise: "OSError: [Errno 9] Bad file descriptor"!
# os.fsync(file_handle.fileno())
# file_handle.close()
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# #--------------------------------------------
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# def cleanup( f_names_list ):
# global os
# for i in range(len( f_names_list )):
# if type(f_names_list[i]) == file:
# del_name = f_names_list[i].name
# elif type(f_names_list[i]) == str:
# del_name = f_names_list[i]
# else:
# print('Unrecognized type of element:', f_names_list[i], ' - can not be treated as file.')
# del_name = None
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# if del_name and os.path.isfile( del_name ):
# os.remove( del_name )
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# #--------------------------------------------
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# f_meta_init_sql = open( os.path.join(context['temp_directory'],'tmp_meta_5092_init.sql'), 'w')
# subprocess.call( [context['isql_path'], dsn, "-x", "-ch", "utf8"],
# stdout = f_meta_init_sql,
# stderr = subprocess.STDOUT
# )
# flush_and_close( f_meta_init_sql )
2021-11-29 20:54:28 +01:00
#
# sqlda_check='set list on; set sqlda_display on; select * from t1; commit; drop table t1; exit;'
#
2021-04-26 20:07:00 +02:00
# f_sqlda_init = open( os.path.join(context['temp_directory'],'tmp_sqlda_5092_init.log'), 'w')
# f_sqlda_init.close()
# runProgram( 'isql',[dsn, '-q', '-m', '-o', f_sqlda_init.name], sqlda_check)
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# f_apply_meta_log = open( os.path.join(context['temp_directory'],'tmp_meta_5092_apply.log'), 'w')
# subprocess.call( [context['isql_path'], dsn, "-i", f_meta_init_sql.name, "-ch", "utf8" ],
# stdout = f_apply_meta_log,
# stderr = subprocess.STDOUT
# )
# flush_and_close( f_apply_meta_log )
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# f_meta_last_sql = open( os.path.join(context['temp_directory'],'tmp_meta_5092_last.sql'), 'w')
# subprocess.call( [context['isql_path'], dsn, "-x", "-ch", "utf8"],
# stdout = f_meta_last_sql,
# stderr = subprocess.STDOUT
# )
# flush_and_close( f_meta_last_sql )
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# f_sqlda_last = open( os.path.join(context['temp_directory'],'tmp_sqlda_5092_last.log') , 'w')
# f_sqlda_last.close()
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# runProgram( 'isql',[dsn, '-q', '-m', '-o', f_sqlda_last.name], sqlda_check)
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# f_diff_txt=open( os.path.join(context['temp_directory'],'tmp_5092_meta_diff.txt'), 'w')
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# f_old=[]
# f_new=[]
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# f_old.append(f_meta_init_sql)
# f_old.append(f_sqlda_init)
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# f_new.append(f_meta_last_sql)
# f_new.append(f_sqlda_last)
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# for i in range(len(f_old)):
# old_file=open(f_old[i].name,'r')
# new_file=open(f_new[i].name,'r')
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# f_diff_txt.write( ''.join( difflib.unified_diff( old_file.readlines(), new_file.readlines() ) ) )
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# old_file.close()
# new_file.close()
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# flush_and_close( f_diff_txt )
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# # Should be EMPTY:
# ##################
# with open( f_apply_meta_log.name, 'r') as f:
# for line in f:
# print( 'Error log of applying extracted metadata: ' + f.line() )
2021-11-29 20:54:28 +01:00
#
#
2021-04-26 20:07:00 +02:00
# # Should be EMPTY:
# ##################
# with open( f_diff_txt.name,'r') as f:
# for line in f:
# print( ' '.join(line.split()).upper() )
2021-11-29 20:54:28 +01:00
#
#
#
2021-04-26 20:07:00 +02:00
# # Cleanup.
# ##########
# time.sleep(1)
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# cleanup( (f_meta_init_sql,f_meta_last_sql,f_sqlda_init,f_sqlda_last,f_apply_meta_log,f_diff_txt) )
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
#---
2021-11-29 20:54:28 +01:00
act_1 = python_act('db_1', substitutions=substitutions_1)
2021-04-26 20:07:00 +02:00
2021-11-29 20:54:28 +01:00
@pytest.mark.version('>=3.0')
def test_1(act_1: Action):
# Initial metadata
act_1.isql(switches=['-x'])
initial_metadata = act_1.stdout.splitlines()
# SQLDA initial
sqlda_check = 'set list on; set sqlda_display on; select * from t1; commit; drop table t1; exit;'
act_1.reset()
act_1.isql(switches=['-q', '-m'], input=sqlda_check)
initial_sqlda = act_1.stdout.splitlines()
# Apply extracted metadata
act_1.reset()
act_1.isql(switches=[], input='\n'.join(initial_metadata))
# New metadata
act_1.reset()
act_1.isql(switches=['-x'])
new_metadata = act_1.stdout.splitlines()
# SQLDA new
act_1.reset()
act_1.isql(switches=['-q', '-m'], input=sqlda_check)
new_sqlda = act_1.stdout.splitlines()
# Check
assert list(unified_diff(initial_sqlda, new_sqlda)) == []
assert list(unified_diff(initial_metadata, new_metadata)) == []