Use common.skip_python3() to skip tests modules not supporting python3

This commit is contained in:
Dmitri Bogomolov 2021-01-29 17:02:55 +02:00 committed by Muzahid
parent dba54841bf
commit eaab6d3f5f
Signed by untrusted user: cis-muzahid
GPG Key ID: 1DC85E7D3AB613EA
11 changed files with 50 additions and 14 deletions

View File

@ -4,6 +4,7 @@ import os
import platform
import shutil
import sys
import unittest
from setuptools import setup, Extension
from setuptools.command.install import install
@ -45,6 +46,11 @@ class InstallCmd(install):
return install.run(self)
def unittest_discover():
"""Explicit test suite creation"""
return unittest.TestLoader().discover('pybitmessage.tests')
if __name__ == "__main__":
here = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(here, 'README.md')) as f:
@ -116,6 +122,7 @@ if __name__ == "__main__":
#keywords='',
install_requires=installRequires,
tests_require=requirements,
test_suite='setup.unittest_discover',
extras_require=EXTRAS_REQUIRE,
classifiers=[
"License :: OSI Approved :: MIT License"

View File

@ -7,7 +7,7 @@ when pybitmessage started in test mode.
import sys
import tempfile
from test_process import put_signal_file
from common import put_signal_file
if __name__ == '__main__':

View File

@ -1,4 +1,7 @@
import os
import sys
import time
import unittest
_files = (
@ -17,3 +20,15 @@ def cleanup(home=None, files=_files):
os.remove(os.path.join(home, pfile))
except OSError:
pass
def skip_python3():
"""Raise unittest.SkipTest() if detected python3"""
if sys.hexversion >= 0x3000000:
raise unittest.SkipTest('Module is not ported to python3')
def put_signal_file(path, filename):
"""Creates file, presence of which is a signal about some event."""
with open(os.path.join(path, filename), 'wb') as outfile:
outfile.write(b'%i' % time.time())

View File

@ -5,9 +5,13 @@ Tests using API.
import base64
import json
import time
import xmlrpclib # nosec
from test_process import TestProcessProto, TestProcessShutdown
try: # nosec
from xmlrpclib import ServerProxy, ProtocolError
except ImportError:
from xmlrpc.client import ServerProxy, ProtocolError
from .test_process import TestProcessProto, TestProcessShutdown
class TestAPIProto(TestProcessProto):
@ -19,7 +23,7 @@ class TestAPIProto(TestProcessProto):
"""Setup XMLRPC proxy for pybitmessage API"""
super(TestAPIProto, cls).setUpClass()
cls.addresses = []
cls.api = xmlrpclib.ServerProxy(
cls.api = ServerProxy(
"http://username:password@127.0.0.1:8442/")
for _ in range(5):
if cls._get_readline('.api_started'):
@ -65,8 +69,8 @@ class TestAPI(TestAPIProto):
def test_user_password(self):
"""Trying to connect with wrong username/password"""
api_wrong = xmlrpclib.ServerProxy("http://test:wrong@127.0.0.1:8442/")
with self.assertRaises(xmlrpclib.ProtocolError):
api_wrong = ServerProxy("http://test:wrong@127.0.0.1:8442/")
with self.assertRaises(ProtocolError):
api_wrong.clientStatus()
def test_connection(self):

View File

@ -6,8 +6,8 @@ import os
import unittest
import tempfile
from .test_process import TestProcessProto
from pybitmessage.bmconfigparser import BMConfigParser
from test_process import TestProcessProto
class TestConfig(unittest.TestCase):

View File

@ -6,8 +6,10 @@ import hashlib
import unittest
from abc import ABCMeta, abstractmethod
from binascii import hexlify, unhexlify
from pybitmessage.pyelliptic import arithmetic
try:
from Crypto.Hash import RIPEMD
except ImportError:

View File

@ -5,7 +5,7 @@ Testing the logger configuration
import os
import tempfile
from test_process import TestProcessProto
from .test_process import TestProcessProto
class TestLogger(TestProcessProto):

View File

@ -3,6 +3,10 @@ Test for network group
"""
import unittest
from .common import skip_python3
skip_python3()
class TestNetworkGroup(unittest.TestCase):
"""

View File

@ -3,9 +3,12 @@ Tests for openclpow module
"""
import hashlib
import unittest
from struct import pack, unpack
from .common import skip_python3
skip_python3() # noqa:E402
from pybitmessage import openclpow

View File

@ -12,13 +12,10 @@ import unittest
import psutil
from common import cleanup
from .common import cleanup, put_signal_file, skip_python3
def put_signal_file(path, filename):
"""Creates file, presence of which is a signal about some event."""
with open(os.path.join(path, filename), 'wb') as outfile:
outfile.write(b'%i' % time.time())
skip_python3()
class TestProcessProto(unittest.TestCase):

View File

@ -4,6 +4,10 @@ Tests for common protocol functions
import unittest
from .common import skip_python3
skip_python3()
class TestProtocol(unittest.TestCase):
"""Main protocol test case"""