Runnable with both Python3 and Python2, with both PyQt5 and PyQt4 by using Qt.py #2250

Open
kashikoibumi wants to merge 127 commits from kashikoibumi/py3qt 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): def isAddressInMyAddressBook(address):
"""Is address in my addressbook?""" """Is address in my addressbook?"""
queryreturn = sqlQuery( queryreturn = sqlQuery(
'''select address from addressbook where address=?''', '''select TRUE from addressbook where address=?''',
dbstr(address)) dbstr(address))
return queryreturn != [] return queryreturn != []
@ -48,7 +48,7 @@ def isAddressInMyAddressBook(address):
def isAddressInMySubscriptionsList(address): def isAddressInMySubscriptionsList(address):
"""Am I subscribed to this address?""" """Am I subscribed to this address?"""
queryreturn = sqlQuery( queryreturn = sqlQuery(
'''select * from subscriptions where address=?''', '''select TRUE from subscriptions where address=?''',
dbstr(address)) dbstr(address))
return queryreturn != [] return queryreturn != []

View File

@ -23,7 +23,10 @@ from .test_process import TestProcessProto
class TestAPIProto(TestProcessProto): class TestAPIProto(TestProcessProto):
"""Test case logic for testing API""" """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 @classmethod
def setUpClass(cls): def setUpClass(cls):
@ -58,6 +61,9 @@ class TestAPIShutdown(TestAPIProto):
class TestAPI(TestAPIProto): class TestAPI(TestAPIProto):
"""Main API test case""" """Main API test case"""
if six.PY3:
_seed = base64.encodebytes(sample_seed)
else: # assume six.PY2
_seed = base64.encodestring(sample_seed) _seed = base64.encodestring(sample_seed)
def _add_random_address(self, label): def _add_random_address(self, label):

View File

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

View File

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

View File

@ -45,10 +45,12 @@ class TestHelperSent(unittest.TestCase):
@patch("pybitmessage.helper_sent.sqlExecute") @patch("pybitmessage.helper_sent.sqlExecute")
def test_delete(self, mock_sql_execute): def test_delete(self, mock_sql_execute):
"""Test delete function""" """Test delete function"""
mock_sql_execute.return_value = 1
delete(b"ack_data") delete(b"ack_data")
self.assertTrue(mock_sql_execute.called) self.assertTrue(mock_sql_execute.called)
import sqlite3
mock_sql_execute.assert_called_once_with( 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") @patch("pybitmessage.helper_sent.sqlQuery")
@ -64,7 +66,7 @@ class TestHelperSent(unittest.TestCase):
) )
] ]
mock_sql_query.return_value = return_data mock_sql_query.return_value = return_data
result = retrieve_message_details("12345") result = retrieve_message_details(b"12345")
self.assertEqual(result, return_data) self.assertEqual(result, return_data)
@patch("pybitmessage.helper_sent.sqlExecute") @patch("pybitmessage.helper_sent.sqlExecute")

View File

@ -43,7 +43,7 @@ handlers=default
cls._files = cls._files[2:] + ('logging.dat',) cls._files = cls._files[2:] + ('logging.dat',)
cls.log_file = os.path.join(cls.home, 'debug.log') 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)) dst.write(cls.conf_template.format(cls.log_file, cls.pattern))
super(TestLogger, cls).setUpClass() super(TestLogger, cls).setUpClass()

View File

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

View File

@ -11,6 +11,7 @@ import time
import unittest import unittest
import psutil import psutil
import six
from .common import cleanup, put_signal_file, skip_python3 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: """Test case implementing common logic for external testing:
it starts pybitmessage in setUpClass() and stops it in tearDownClass() 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_min = 15
_threads_count_max = 16 _threads_count_max = 16
_threads_names = [ _threads_names = [

View File

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