diff --git a/start3.sh b/py3start.sh similarity index 100% rename from start3.sh rename to py3start.sh diff --git a/src/py3bitmessage b/src/py3bitmessage new file mode 100755 index 00000000..6277ea32 --- /dev/null +++ b/src/py3bitmessage @@ -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) diff --git a/src/pybitmessage b/src/pybitmessage old mode 100644 new mode 100755 diff --git a/src/shared.py b/src/shared.py index ca0b9306..f710d56d 100644 --- a/src/shared.py +++ b/src/shared.py @@ -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 != [] diff --git a/src/tests/test_api.py b/src/tests/test_api.py index db52cc9c..3ae547d3 100644 --- a/src/tests/test_api.py +++ b/src/tests/test_api.py @@ -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,7 +61,10 @@ class TestAPIShutdown(TestAPIProto): class TestAPI(TestAPIProto): """Main API test case""" - _seed = base64.encodestring(sample_seed) + if six.PY3: + _seed = base64.encodebytes(sample_seed) + else: # assume six.PY2 + _seed = base64.encodestring(sample_seed) def _add_random_address(self, label): addr = self.api.createRandomAddress(base64.encodestring(label)) diff --git a/src/tests/test_config_process.py b/src/tests/test_config_process.py index 9322a2f0..b221aa6f 100644 --- a/src/tests/test_config_process.py +++ b/src/tests/test_config_process.py @@ -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): diff --git a/src/tests/test_helper_inbox.py b/src/tests/test_helper_inbox.py index 8ff60e18..31ccc208 100644 --- a/src/tests/test_helper_inbox.py +++ b/src/tests/test_helper_inbox.py @@ -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) diff --git a/src/tests/test_helper_sent.py b/src/tests/test_helper_sent.py index 36bb8bb7..27e5d970 100644 --- a/src/tests/test_helper_sent.py +++ b/src/tests/test_helper_sent.py @@ -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") diff --git a/src/tests/test_logger.py b/src/tests/test_logger.py index 636a209f..6e4068fc 100644 --- a/src/tests/test_logger.py +++ b/src/tests/test_logger.py @@ -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() diff --git a/src/tests/test_network.py b/src/tests/test_network.py index 206117e0..e54f737f 100644 --- a/src/tests/test_network.py +++ b/src/tests/test_network.py @@ -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) diff --git a/src/tests/test_process.py b/src/tests/test_process.py index 37b34541..9101fe7c 100644 --- a/src/tests/test_process.py +++ b/src/tests/test_process.py @@ -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 = [ diff --git a/src/tests/test_shared.py b/src/tests/test_shared.py index 073f94e7..f53930a1 100644 --- a/src/tests/test_shared.py +++ b/src/tests/test_shared.py @@ -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)