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
parent b3c341951d
commit f8844f4d74
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13
11 changed files with 50 additions and 14 deletions

View File

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

View File

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

View File

@ -1,4 +1,7 @@
import os import os
import sys
import time
import unittest
_files = ( _files = (
@ -17,3 +20,15 @@ def cleanup(home=None, files=_files):
os.remove(os.path.join(home, pfile)) os.remove(os.path.join(home, pfile))
except OSError: except OSError:
pass 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 base64
import json import json
import time 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): class TestAPIProto(TestProcessProto):
@ -19,7 +23,7 @@ class TestAPIProto(TestProcessProto):
"""Setup XMLRPC proxy for pybitmessage API""" """Setup XMLRPC proxy for pybitmessage API"""
super(TestAPIProto, cls).setUpClass() super(TestAPIProto, cls).setUpClass()
cls.addresses = [] cls.addresses = []
cls.api = xmlrpclib.ServerProxy( cls.api = ServerProxy(
"http://username:password@127.0.0.1:8442/") "http://username:password@127.0.0.1:8442/")
for _ in range(5): for _ in range(5):
if cls._get_readline('.api_started'): if cls._get_readline('.api_started'):
@ -65,8 +69,8 @@ class TestAPI(TestAPIProto):
def test_user_password(self): def test_user_password(self):
"""Trying to connect with wrong username/password""" """Trying to connect with wrong username/password"""
api_wrong = xmlrpclib.ServerProxy("http://test:wrong@127.0.0.1:8442/") api_wrong = ServerProxy("http://test:wrong@127.0.0.1:8442/")
with self.assertRaises(xmlrpclib.ProtocolError): with self.assertRaises(ProtocolError):
api_wrong.clientStatus() api_wrong.clientStatus()
def test_connection(self): def test_connection(self):

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -12,13 +12,10 @@ import unittest
import psutil import psutil
from common import cleanup from .common import cleanup, put_signal_file, skip_python3
def put_signal_file(path, filename): skip_python3()
"""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())
class TestProcessProto(unittest.TestCase): class TestProcessProto(unittest.TestCase):

View File

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