Runnable with both Python3 and Python2, with PyQt4 #2249

Open
kashikoibumi wants to merge 59 commits from kashikoibumi/py3 into v0.6
12 changed files with 45 additions and 18 deletions
Showing only changes of commit 597372543b - Show all commits

13
src/py3bitmessage Executable file
View File

@ -0,0 +1,13 @@
#!/usr/bin/python3
import os
import pkg_resources
import pybitmessage
dist = pkg_resources.get_distribution('pybitmessage')
script_file = os.path.join(dist.location, dist.key, 'bitmessagemain.py')
new_globals = globals()
new_globals.update(__file__=script_file)
execfile(script_file, new_globals)

0
src/pybitmessage Normal file → Executable file
View File

View File

@ -39,7 +39,7 @@ broadcastSendersForWhichImWatching = {}
def isAddressInMyAddressBook(address):
"""Is address in my addressbook?"""
queryreturn = sqlQuery(
'''select address from addressbook where address=?''',
'''select TRUE from addressbook where address=?''',
dbstr(address))
return queryreturn != []
@ -48,7 +48,7 @@ def isAddressInMyAddressBook(address):
def isAddressInMySubscriptionsList(address):
"""Am I subscribed to this address?"""
queryreturn = sqlQuery(
'''select * from subscriptions where address=?''',
'''select TRUE from subscriptions where address=?''',
dbstr(address))
return queryreturn != []

View File

@ -23,7 +23,10 @@ from .test_process import TestProcessProto
class TestAPIProto(TestProcessProto):
"""Test case logic for testing API"""
_process_cmd = ['pybitmessage', '-t']
if six.PY3:
_process_cmd = ['./py3bitmessage', '-t']
else: # assume six.PY2
_process_cmd = ['./pybitmessage', '-t']
@classmethod
def setUpClass(cls):
@ -58,6 +61,9 @@ class TestAPIShutdown(TestAPIProto):
class TestAPI(TestAPIProto):
"""Main API test case"""
if six.PY3:
_seed = base64.encodebytes(sample_seed)
else: # assume six.PY2
_seed = base64.encodestring(sample_seed)
def _add_random_address(self, label):

View File

@ -6,9 +6,6 @@ import os
import tempfile
from pybitmessage.bmconfigparser import config
from .test_process import TestProcessProto
from .common import skip_python3
skip_python3()
class TestProcessConfig(TestProcessProto):

View File

@ -43,6 +43,7 @@ class TestHelperInbox(unittest.TestCase):
@patch("pybitmessage.helper_inbox.sqlExecute")
def test_trash(self, mock_sql_execute): # pylint: disable=no-self-use
"""Test marking a message in the `inbox` as `trash`"""
mock_sql_execute.return_value = 1
mock_msg_id = b"fefkosghsbse92"
trash(msgid=mock_msg_id)
mock_sql_execute.assert_called_once()
@ -50,6 +51,7 @@ class TestHelperInbox(unittest.TestCase):
@patch("pybitmessage.helper_inbox.sqlExecute")
def test_delete(self, mock_sql_execute): # pylint: disable=no-self-use
"""Test for permanent deletion of message from trash"""
mock_sql_execute.return_value = 1
mock_ack_data = genAckPayload()
delete(mock_ack_data)
mock_sql_execute.assert_called_once()
@ -57,6 +59,7 @@ class TestHelperInbox(unittest.TestCase):
@patch("pybitmessage.helper_inbox.sqlExecute")
def test_undeleteMessage(self, mock_sql_execute): # pylint: disable=no-self-use
"""Test for Undelete the message"""
mock_sql_execute.return_value = 1
mock_msg_id = b"fefkosghsbse92"
undeleteMessage(msgid=mock_msg_id)
mock_sql_execute.assert_called_once()
@ -64,7 +67,7 @@ class TestHelperInbox(unittest.TestCase):
@patch("pybitmessage.helper_inbox.sqlQuery")
def test_isMessageAlreadyInInbox(self, mock_sql_query):
"""Test for check for previous instances of this message"""
fake_sigHash = "h4dkn54546"
fake_sigHash = b"h4dkn54546"
# if Message is already in Inbox
mock_sql_query.return_value = [(1,)]
result = isMessageAlreadyInInbox(sigHash=fake_sigHash)

View File

@ -45,10 +45,12 @@ class TestHelperSent(unittest.TestCase):
@patch("pybitmessage.helper_sent.sqlExecute")
def test_delete(self, mock_sql_execute):
"""Test delete function"""
mock_sql_execute.return_value = 1
delete(b"ack_data")
self.assertTrue(mock_sql_execute.called)
import sqlite3
mock_sql_execute.assert_called_once_with(
"DELETE FROM sent WHERE ackdata = ?", b"ack_data"
"DELETE FROM sent WHERE ackdata = ?", sqlite3.Binary(b"ack_data")
)
@patch("pybitmessage.helper_sent.sqlQuery")
@ -64,7 +66,7 @@ class TestHelperSent(unittest.TestCase):
)
]
mock_sql_query.return_value = return_data
result = retrieve_message_details("12345")
result = retrieve_message_details(b"12345")
self.assertEqual(result, return_data)
@patch("pybitmessage.helper_sent.sqlExecute")

View File

@ -43,7 +43,7 @@ handlers=default
cls._files = cls._files[2:] + ('logging.dat',)
cls.log_file = os.path.join(cls.home, 'debug.log')
with open(os.path.join(cls.home, 'logging.dat'), 'wb') as dst:
with open(os.path.join(cls.home, 'logging.dat'), 'w') as dst:
dst.write(cls.conf_template.format(cls.log_file, cls.pattern))
super(TestLogger, cls).setUpClass()

View File

@ -3,11 +3,8 @@
import threading
import time
from .common import skip_python3
from .partial import TestPartialRun
skip_python3()
class TestNetwork(TestPartialRun):
"""A test case for running the network subsystem"""
@ -24,11 +21,14 @@ class TestNetwork(TestPartialRun):
# config variable is still used inside of the network ):
import network
from network import connectionpool, stats
from network.stats import sentBytes, receivedBytes
# beware of singleton
connectionpool.config = cls.config
cls.pool = connectionpool.pool
cls.stats = stats
cls.stats.sentBytes = sentBytes
cls.stats.receivedBytes = receivedBytes
network.start(cls.config, cls.state)

View File

@ -11,6 +11,7 @@ import time
import unittest
import psutil
import six
from .common import cleanup, put_signal_file, skip_python3
@ -22,7 +23,10 @@ class TestProcessProto(unittest.TestCase):
"""Test case implementing common logic for external testing:
it starts pybitmessage in setUpClass() and stops it in tearDownClass()
"""
_process_cmd = ['pybitmessage', '-d']
if six.PY3:
_process_cmd = ['./py3bitmessage', '-d']
else: # assume six.PY2
_process_cmd = ['./pybitmessage', '-d']
_threads_count_min = 15
_threads_count_max = 16
_threads_names = [

View File

@ -46,7 +46,8 @@ class TestShared(unittest.TestCase):
address = sample_address
# if address is in MyAddressbook
mock_sql_query.return_value = [bytes(address)]
TRUE = 1
mock_sql_query.return_value = [TRUE]
return_val = isAddressInMyAddressBook(address)
mock_sql_query.assert_called_once()
self.assertTrue(return_val)
@ -64,7 +65,8 @@ class TestShared(unittest.TestCase):
address = sample_address
# if address is in MySubscriptionsList
mock_sql_query.return_value = [bytes(address)]
TRUE = 1
mock_sql_query.return_value = [TRUE]
return_val = isAddressInMySubscriptionsList(address)
self.assertTrue(return_val)
@ -78,7 +80,7 @@ class TestShared(unittest.TestCase):
def test_reloadBroadcastSendersForWhichImWatching(self, mock_sql_query):
"""Test for reload Broadcast Senders For Which Im Watching"""
mock_sql_query.return_value = [
(bytes(sample_address),),
(bytes(sample_address.encode("utf-8", "replace")),),
]
# before reload
self.assertEqual(len(MyECSubscriptionCryptorObjects), 0)