Runnable with both Python3 and Python2, with PyQt4 #2249
3
setup.py
3
setup.py
|
@ -4,6 +4,7 @@ import os
|
||||||
import platform
|
import platform
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
|
import six
|
||||||
|
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
from setuptools import setup, Extension
|
from setuptools import setup, Extension
|
||||||
|
@ -83,7 +84,7 @@ if __name__ == "__main__":
|
||||||
'images/kivy/text_images*.png'
|
'images/kivy/text_images*.png'
|
||||||
]}
|
]}
|
||||||
|
|
||||||
if sys.version_info[0] == 3:
|
if six.PY3:
|
||||||
packages.extend(
|
packages.extend(
|
||||||
[
|
[
|
||||||
'pybitmessage.bitmessagekivy',
|
'pybitmessage.bitmessagekivy',
|
||||||
|
|
|
@ -6,6 +6,7 @@ and suggest how it may be installed
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
import six
|
||||||
|
|
||||||
# Only really old versions of Python don't have sys.hexversion. We don't
|
# Only really old versions of Python don't have sys.hexversion. We don't
|
||||||
# support them. The logging module was introduced in Python 2.3
|
# support them. The logging module was introduced in Python 2.3
|
||||||
|
@ -438,7 +439,7 @@ def check_dependencies(verbose=False, optional=False):
|
||||||
'PyBitmessage requires Python 2.7.4 or greater'
|
'PyBitmessage requires Python 2.7.4 or greater'
|
||||||
' (but not Python 3+)')
|
' (but not Python 3+)')
|
||||||
has_all_dependencies = False
|
has_all_dependencies = False
|
||||||
if sys.hexversion >= 0x3000000:
|
if six.PY3:
|
||||||
logger.error(
|
logger.error(
|
||||||
'PyBitmessage does not support Python 3+. Python 2.7.4'
|
'PyBitmessage does not support Python 3+. Python 2.7.4'
|
||||||
' or greater is required. Python 2.7.18 is recommended.')
|
' or greater is required. Python 2.7.18 is recommended.')
|
||||||
|
|
|
@ -53,6 +53,7 @@ import collections
|
||||||
import io
|
import io
|
||||||
import struct
|
import struct
|
||||||
import sys
|
import sys
|
||||||
|
import six
|
||||||
|
|
||||||
__version__ = "2.4.1"
|
__version__ = "2.4.1"
|
||||||
"Module version string"
|
"Module version string"
|
||||||
|
@ -99,9 +100,9 @@ class Ext: # pylint: disable=old-style-class
|
||||||
if not isinstance(type, int) or not (type >= 0 and type <= 127):
|
if not isinstance(type, int) or not (type >= 0 and type <= 127):
|
||||||
raise TypeError("ext type out of range")
|
raise TypeError("ext type out of range")
|
||||||
# Check data is type bytes
|
# Check data is type bytes
|
||||||
elif sys.version_info[0] == 3 and not isinstance(data, bytes):
|
elif six.PY3 and not isinstance(data, bytes):
|
||||||
raise TypeError("ext data is not type \'bytes\'")
|
raise TypeError("ext data is not type \'bytes\'")
|
||||||
elif sys.version_info[0] == 2 and not isinstance(data, str):
|
elif six.PY2 and not isinstance(data, str):
|
||||||
raise TypeError("ext data is not type \'str\'")
|
raise TypeError("ext data is not type \'str\'")
|
||||||
self.type = type
|
self.type = type
|
||||||
self.data = data
|
self.data = data
|
||||||
|
@ -990,7 +991,7 @@ def __init():
|
||||||
_float_precision = "single"
|
_float_precision = "single"
|
||||||
|
|
||||||
# Map packb and unpackb to the appropriate version
|
# Map packb and unpackb to the appropriate version
|
||||||
if sys.version_info[0] == 3:
|
if six.PY3:
|
||||||
pack = _pack3
|
pack = _pack3
|
||||||
packb = _packb3
|
packb = _packb3
|
||||||
dump = _pack3
|
dump = _pack3
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
|
||||||
import time
|
import time
|
||||||
|
import six
|
||||||
|
|
||||||
from six.moves import range
|
from six.moves import range
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ if not re.search(r'\d', time.strftime(time_format)):
|
||||||
|
|
||||||
# It seems some systems lie about the encoding they use
|
# It seems some systems lie about the encoding they use
|
||||||
# so we perform comprehensive decoding tests
|
# so we perform comprehensive decoding tests
|
||||||
elif sys.version_info[0] == 2:
|
elif six.PY2:
|
||||||
try:
|
try:
|
||||||
# Check day names
|
# Check day names
|
||||||
for i in range(7):
|
for i in range(7):
|
||||||
|
@ -118,7 +118,7 @@ def formatTimestamp(timestamp=None):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
timestring = time.strftime(time_format)
|
timestring = time.strftime(time_format)
|
||||||
|
|
||||||
if sys.version_info[0] == 2:
|
if six.PY2:
|
||||||
return timestring.decode(encoding)
|
return timestring.decode(encoding)
|
||||||
return timestring
|
return timestring
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ needed openssl functionality in class _OpenSSL.
|
||||||
"""
|
"""
|
||||||
import ctypes
|
import ctypes
|
||||||
import sys
|
import sys
|
||||||
|
import six
|
||||||
|
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
|
|
||||||
|
@ -745,7 +746,7 @@ class _OpenSSL(object):
|
||||||
"""
|
"""
|
||||||
buffer_ = None
|
buffer_ = None
|
||||||
if data != 0:
|
if data != 0:
|
||||||
if sys.version_info.major == 3 and isinstance(data, type('')):
|
if six.PY3 and isinstance(data, type('')):
|
||||||
data = data.encode()
|
data = data.encode()
|
||||||
buffer_ = self.create_string_buffer(data, size)
|
buffer_ = self.create_string_buffer(data, size)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
import time
|
import time
|
||||||
import unittest
|
import unittest
|
||||||
|
import six
|
||||||
|
|
||||||
|
|
||||||
_files = (
|
_files = (
|
||||||
|
@ -33,7 +33,7 @@ def checkup():
|
||||||
|
|
||||||
def skip_python3():
|
def skip_python3():
|
||||||
"""Raise unittest.SkipTest() if detected python3"""
|
"""Raise unittest.SkipTest() if detected python3"""
|
||||||
if sys.hexversion >= 0x3000000:
|
if six.PY3:
|
||||||
raise unittest.SkipTest('Module is not ported to python3')
|
raise unittest.SkipTest('Module is not ported to python3')
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
|
import six
|
||||||
|
|
||||||
from pybitmessage import pathmagic
|
from pybitmessage import pathmagic
|
||||||
|
|
||||||
|
@ -22,7 +23,7 @@ class TestPartialRun(unittest.TestCase):
|
||||||
import state
|
import state
|
||||||
|
|
||||||
from debug import logger # noqa:F401 pylint: disable=unused-variable
|
from debug import logger # noqa:F401 pylint: disable=unused-variable
|
||||||
if sys.hexversion >= 0x3000000:
|
if six.PY3:
|
||||||
# pylint: disable=no-name-in-module,relative-import
|
# pylint: disable=no-name-in-module,relative-import
|
||||||
from mockbm import network as network_mock
|
from mockbm import network as network_mock
|
||||||
import network
|
import network
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
"""TestAPIThread class definition"""
|
"""TestAPIThread class definition"""
|
||||||
|
|
||||||
import sys
|
|
||||||
import time
|
import time
|
||||||
from binascii import hexlify, unhexlify
|
from binascii import hexlify, unhexlify
|
||||||
from struct import pack
|
from struct import pack
|
||||||
|
import six
|
||||||
|
|
||||||
from six.moves import queue, xmlrpc_client
|
from six.moves import queue, xmlrpc_client
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ class TestAPIThread(TestPartialRun):
|
||||||
def test_client_status(self):
|
def test_client_status(self):
|
||||||
"""Ensure the reply of clientStatus corresponds to mock"""
|
"""Ensure the reply of clientStatus corresponds to mock"""
|
||||||
status = self.api.clientStatus()
|
status = self.api.clientStatus()
|
||||||
if sys.hexversion >= 0x3000000:
|
if six.PY3:
|
||||||
self.assertEqual(status["networkConnections"], 4)
|
self.assertEqual(status["networkConnections"], 4)
|
||||||
self.assertEqual(status["pendingDownload"], 0)
|
self.assertEqual(status["pendingDownload"], 0)
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
"""Tests for l10n module"""
|
"""Tests for l10n module"""
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import sys
|
|
||||||
import time
|
import time
|
||||||
import unittest
|
import unittest
|
||||||
|
import six
|
||||||
|
|
||||||
from pybitmessage import l10n
|
from pybitmessage import l10n
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ class TestL10n(unittest.TestCase):
|
||||||
self.assertFalse(re.search(r'\d', time.strftime("wrong")))
|
self.assertFalse(re.search(r'\d', time.strftime("wrong")))
|
||||||
timestring_type = type(time.strftime(l10n.DEFAULT_TIME_FORMAT))
|
timestring_type = type(time.strftime(l10n.DEFAULT_TIME_FORMAT))
|
||||||
self.assertEqual(timestring_type, str)
|
self.assertEqual(timestring_type, str)
|
||||||
if sys.version_info[0] == 2:
|
if six.PY2:
|
||||||
self.assertEqual(timestring_type, bytes)
|
self.assertEqual(timestring_type, bytes)
|
||||||
|
|
||||||
def test_getWindowsLocale(self):
|
def test_getWindowsLocale(self):
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
"""Tests for logging"""
|
"""Tests for logging"""
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
|
||||||
import unittest
|
import unittest
|
||||||
|
import six
|
||||||
|
|
||||||
from pybitmessage import proofofwork
|
from pybitmessage import proofofwork
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ class TestLog(unittest.TestCase):
|
||||||
"""A test case for logging"""
|
"""A test case for logging"""
|
||||||
|
|
||||||
@unittest.skipIf(
|
@unittest.skipIf(
|
||||||
sys.hexversion < 0x3000000, 'assertLogs is new in version 3.4')
|
six.PY2, 'assertLogs is new in version 3.4')
|
||||||
def test_LogOutput(self):
|
def test_LogOutput(self):
|
||||||
"""Use proofofwork.LogOutput to log output of a shell command"""
|
"""Use proofofwork.LogOutput to log output of a shell command"""
|
||||||
with self.assertLogs('default') as cm: # pylint: disable=no-member
|
with self.assertLogs('default') as cm: # pylint: disable=no-member
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
Tests for common protocol functions
|
Tests for common protocol functions
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
|
||||||
import unittest
|
import unittest
|
||||||
|
import six
|
||||||
|
|
||||||
from pybitmessage import protocol, state
|
from pybitmessage import protocol, state
|
||||||
from pybitmessage.helper_startup import fixSocket
|
from pybitmessage.helper_startup import fixSocket
|
||||||
|
@ -79,7 +79,7 @@ class TestProtocol(TestSocketInet):
|
||||||
self.assertEqual(protocol.checkIPAddress(globalhost), '8.8.8.8')
|
self.assertEqual(protocol.checkIPAddress(globalhost), '8.8.8.8')
|
||||||
|
|
||||||
@unittest.skipIf(
|
@unittest.skipIf(
|
||||||
sys.hexversion >= 0x3000000, 'this is still not working with python3')
|
six.PY3, 'this is still not working with python3')
|
||||||
def test_check_local_socks(self):
|
def test_check_local_socks(self):
|
||||||
"""The SOCKS part of the local check"""
|
"""The SOCKS part of the local check"""
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
|
|
3
tests.py
3
tests.py
|
@ -3,11 +3,12 @@
|
||||||
import random # noseq
|
import random # noseq
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
|
import six
|
||||||
|
|
||||||
|
|
||||||
def unittest_discover():
|
def unittest_discover():
|
||||||
"""Explicit test suite creation"""
|
"""Explicit test suite creation"""
|
||||||
if sys.hexversion >= 0x3000000:
|
if six.PY3:
|
||||||
from pybitmessage import pathmagic
|
from pybitmessage import pathmagic
|
||||||
pathmagic.setup()
|
pathmagic.setup()
|
||||||
loader = unittest.defaultTestLoader
|
loader = unittest.defaultTestLoader
|
||||||
|
|
Reference in New Issue
Block a user