This repository has been archived on 2024-12-18. You can view files and clone it, but cannot push or open issues or pull requests.
PyBitmessage-2024-12-18/src/tests/test_sqlthread.py

45 lines
1.2 KiB
Python
Raw Normal View History

"""Tests for SQL thread"""
# flake8: noqa:E402
2021-03-04 15:15:41 +01:00
import os
import tempfile
2021-03-04 15:15:41 +01:00
import threading
import unittest
2021-03-04 15:15:41 +01:00
from .common import skip_python3
skip_python3()
os.environ['BITMESSAGE_HOME'] = tempfile.gettempdir()
2021-03-04 15:15:41 +01:00
from pybitmessage.helper_sql import (
sqlQuery, sql_ready, sqlStoredProcedure) # noqa:E402
from pybitmessage.class_sqlThread import sqlThread # noqa:E402
from pybitmessage.addresses import encodeAddress # noqa:E402
2021-03-04 15:15:41 +01:00
class TestSqlThread(unittest.TestCase):
"""Test case for SQL thread"""
2021-03-04 15:15:41 +01:00
@classmethod
def setUpClass(cls):
# Start SQL thread
sqlLookup = sqlThread()
sqlLookup.daemon = True
sqlLookup.start()
sql_ready.wait()
@classmethod
def tearDownClass(cls):
sqlStoredProcedure('exit')
for thread in threading.enumerate():
if thread.name == "SQL":
thread.join()
def test_create_function(self):
"""Check the result of enaddr function"""
2021-03-04 15:15:41 +01:00
encoded_str = encodeAddress(4, 1, "21122112211221122112")
query = sqlQuery('SELECT enaddr(4, 1, "21122112211221122112")')
self.assertEqual(
query[0][-1], encoded_str, "test case fail for create_function")