Skip to content

Commit 164c6c3

Browse files
committed
remove create_function calling from test case
1 parent e540c24 commit 164c6c3

File tree

3 files changed

+41
-28
lines changed

3 files changed

+41
-28
lines changed

src/class_sqlThread.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ def _upgrade_one_level_sql_statement(self, file_name):
5151
Execute SQL files and queries
5252
"""
5353
try:
54-
print("=======================")
55-
print(file_name)
5654
if int(file_name) == 8:
5755
res = self.cur.execute('''PRAGMA table_info('inbox');''')
5856
print("""""""""""""""-----------res""""""""""""""")
@@ -121,6 +119,19 @@ class sqlThread(threading.Thread, UpgradeDB):
121119
def __init__(self):
122120
super(sqlThread, self).__init__()
123121
threading.Thread.__init__(self, name="SQL")
122+
self.__flag = threading.Event()
123+
124+
# Adding for pause/resume thread
125+
self.__flag = threading.Event()
126+
self.__flag.set() # Set to True
127+
self.__running = threading.Event() # Used to stop the thread identification
128+
self.__running.set() # Set running to True
129+
130+
def pause(self):
131+
self.__flag.clear() # Set to False to block the thread
132+
133+
def resume(self):
134+
self.__flag.set() # Set to True, let the thread stop blocking
124135

125136
def run(self): # pylint: disable=too-many-locals, too-many-branches, too-many-statements,
126137
# Redefinition-of-parameters-type-from-tuple-to-str, R0204, line-too-long, E501

src/tests/sql/init_version_9.sql

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ CREATE TABLE IF NOT EXISTS `sent` (
1515
`encodingtype` int DEFAULT NULL,
1616
`ttl` int DEFAULT NULL,
1717
UNIQUE(msgid) ON CONFLICT REPLACE
18-
) ;
18+
);
19+
20+
DROP TABLE IF EXISTS `pubkeys`;
1921

2022
CREATE TABLE IF NOT EXISTS `pubkeys` (
21-
`hash` text,
22-
`addressversion` int,
23-
`transmitdata` blob,
24-
`time` int,
25-
`usedpersonally` text,
23+
`hash` text DEFAULT NULL,
24+
`addressversion` int DEFAULT NULL,
25+
`transmitdata` blob DEFAULT NULL,
26+
`time` int DEFAULT NULL,
27+
`usedpersonally` text DEFAULT NULL
2628
UNIQUE(hash) ON CONFLICT REPLACE
2729
) ;

src/tests/test_sqlthread.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#
1010
# skip_python3()
1111

12-
os.environ['BITMESSAGE_HOME'] = tempfile.gettempdir()
12+
# os.environ['BITMESSAGE_HOME'] = tempfile.gettempdir()
1313
from pybitmessage.helper_sql import (
1414
sqlQuery, sql_ready, sqlStoredProcedure, SqlBulkExecute, sqlExecuteScript, sqlExecute) # noqa:E402
1515
from pybitmessage.class_sqlThread import sqlThread, UpgradeDB # noqa:E402
@@ -110,20 +110,20 @@ def wrapper(*args):
110110
func_name = func.__name__
111111
version = func_name.rsplit('_', 1)[-1]
112112

113-
print("-------------=========")
114-
print(version)
115-
print("-------------=========")
116113

117114
if int(version) == 8:
118115
res = sqlQuery('''PRAGMA table_info('inbox');''')
119116
print("""""""""""""""res""""""""""""""")
120117
print(res)
121118

119+
# sqlThread().pause()
122120

123121
# Update versions DB mocking
124122
self.initialise_database("init_version_{}".format(version))
125123

126-
124+
print("-------------=========")
125+
print(version)
126+
print("-------------=========")
127127

128128
if int(version) == 9:
129129
sqlThread().create_function()
@@ -133,12 +133,12 @@ def wrapper(*args):
133133
print("""""""""""""""-----------res""""""""""""""")
134134
print(res)
135135

136-
137136
# Test versions
138137
upgrade_db = UpgradeDB()
139138
upgrade_db._upgrade_one_level_sql_statement(int(version)) # pylint: disable= W0212, protected-access
140139
# upgrade_db.upgrade_to_latest(upgrade_db.cur, upgrade_db.conn)
141140
# upgrade_db.upgrade_to_latest(upgrade_db.cur, upgrade_db.conn, int(version))
141+
# sqlThread().resume()
142142
return func(*args) # <-- use (self, ...)
143143
func = self
144144
return wrapper
@@ -255,20 +255,20 @@ def test_sql_thread_version_8(self):
255255
result = list(filter_table_column(res, "sighash"))
256256
self.assertEqual(result, ['sighash'], "Data not migrated for version 8")
257257

258-
# @version
259-
# def test_sql_thread_version_9(self):
260-
# """
261-
# Test with version 9
262-
# """
263-
#
264-
# # Assertion
265-
# res = sqlQuery(''' SELECT count(name) FROM sqlite_master WHERE type='table' AND name='pubkeys_backup' ''')
266-
# self.assertNotEqual(res[0][0], 1, "Table pubkeys_backup not deleted")
267-
#
268-
# res = sqlQuery('''PRAGMA table_info('pubkeys');''')
269-
# # res = res.fetchall()
270-
# result = list(filter_table_column(res, "address"))
271-
# self.assertEqual(result, ['address'], "Data not migrated for version 9")
258+
@version
259+
def test_sql_thread_version_9(self):
260+
"""
261+
Test with version 9
262+
"""
263+
264+
# Assertion
265+
res = sqlQuery(''' SELECT count(name) FROM sqlite_master WHERE type='table' AND name='pubkeys_backup' ''')
266+
self.assertNotEqual(res[0][0], 1, "Table pubkeys_backup not deleted")
267+
268+
res = sqlQuery('''PRAGMA table_info('pubkeys');''')
269+
# res = res.fetchall()
270+
result = list(filter_table_column(res, "address"))
271+
self.assertEqual(result, ['address'], "Data not migrated for version 9")
272272

273273
# @version
274274
# def test_sql_thread_version_10(self):

0 commit comments

Comments
 (0)