diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 3cb4454..83d4b7e 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -12,11 +12,12 @@ on: jobs: build: - runs-on: ubuntu-20.04 + runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "pypy3.9", "pypy3.10"] + os: ["ubuntu-20.04", "windows-latest"] steps: - uses: actions/checkout@v3 @@ -28,7 +29,6 @@ jobs: run: | python -m pip install --upgrade pip python -m pip install flake8 pytest pytest-asyncio cython - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names diff --git a/tests/test_aio.py b/tests/test_aio.py index d88ac18..b9de45b 100644 --- a/tests/test_aio.py +++ b/tests/test_aio.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- import os +import sys import asyncio # import uvloop import threading @@ -26,6 +27,12 @@ from thriftpy2.transport import TTransportException from thriftpy2.thrift import TApplicationException + +if sys.platform == "win32": + pytest.skip("Unix domain socket is not supported on Windows", + allow_module_level=True) + + addressbook = thriftpy2.load(os.path.join(os.path.dirname(__file__), "addressbook.thrift")) diff --git a/tests/test_all_protocols_binary_field.py b/tests/test_all_protocols_binary_field.py index 39135de..e75e141 100644 --- a/tests/test_all_protocols_binary_field.py +++ b/tests/test_all_protocols_binary_field.py @@ -1,5 +1,6 @@ from __future__ import absolute_import +import sys import time import traceback from multiprocessing import Process @@ -24,6 +25,11 @@ make_client as make_rpc_client from thriftpy2.transport import TBufferedTransportFactory, TCyMemoryBuffer + +if sys.platform == "win32": + pytest.skip("requires fork", allow_module_level=True) + + protocols = [TApacheJSONProtocolFactory, TJSONProtocolFactory, TBinaryProtocolFactory, diff --git a/tests/test_apache_json.py b/tests/test_apache_json.py index 1a2b8d9..85844e1 100644 --- a/tests/test_apache_json.py +++ b/tests/test_apache_json.py @@ -2,6 +2,7 @@ from __future__ import absolute_import import json +import sys import time from multiprocessing import Process @@ -126,6 +127,7 @@ def test(t): json.loads(final_data.decode('utf8'))[4]['0'] +@pytest.mark.skipif(sys.platform == "win32", reason="this test requires fork") @pytest.mark.parametrize('server_func', [(make_rpc_server, make_rpc_client), (make_http_server, make_http_client)]) def test_client(server_func): diff --git a/tests/test_buffered_transport.py b/tests/test_buffered_transport.py index dbe6cb0..69cd715 100644 --- a/tests/test_buffered_transport.py +++ b/tests/test_buffered_transport.py @@ -4,9 +4,11 @@ import logging import multiprocessing +import sys import time - from os import path + +import pytest from unittest import TestCase import thriftpy2 @@ -43,6 +45,7 @@ def get(self, name): return self.registry[name] +@pytest.mark.skipif(sys.platform == "win32", reason="requires fork") class BufferedTransportTestCase(TestCase): TRANSPORT_FACTORY = TBufferedTransportFactory() PROTOCOL_FACTORY = TBinaryProtocolFactory() diff --git a/tests/test_cytransport.py b/tests/test_cytransport.py index 41379db..d147db0 100644 --- a/tests/test_cytransport.py +++ b/tests/test_cytransport.py @@ -2,14 +2,15 @@ import pytest -from thriftpy2._compat import PYPY +from thriftpy2._compat import CYTHON -pytestmark = pytest.mark.skipif(PYPY, reason="cython not enabled in pypy.") -if not PYPY: +if CYTHON: from thriftpy2.transport.framed import TCyFramedTransport from thriftpy2.transport.buffered import TCyBufferedTransport from thriftpy2.transport import TMemoryBuffer, TTransportException +else: + pytest.skip("cython not enabled.", allow_module_level=True) def test_transport_mismatch(): diff --git a/tests/test_framed_transport.py b/tests/test_framed_transport.py index 8959408..19d0096 100644 --- a/tests/test_framed_transport.py +++ b/tests/test_framed_transport.py @@ -4,15 +4,18 @@ import logging import socket +import sys import threading import time from os import path from unittest import TestCase +import pytest from tornado import ioloop import thriftpy2 +from thriftpy2._compat import CYTHON from thriftpy2.tornado import make_server from thriftpy2.rpc import make_client from thriftpy2.transport.framed import TFramedTransportFactory @@ -23,7 +26,12 @@ except ImportError: asyncio = None -from thriftpy2._compat import CYTHON + +if sys.platform == "win32": + pytest.skip("add_socket is not implemented on Windiws", + allow_module_level=True) + + logging.basicConfig(level=logging.INFO) addressbook = thriftpy2.load(path.join(path.dirname(__file__), diff --git a/tests/test_http.py b/tests/test_http.py index 5d27cb6..6d7493a 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -5,6 +5,7 @@ import os import multiprocessing import socket +import sys import time import uuid @@ -21,6 +22,10 @@ "addressbook.thrift")) +if sys.platform == "win32": + pytest.skip("requires fork", allow_module_level=True) + + class Dispatcher(): def __init__(self): self.ab = addressbook.AddressBook() diff --git a/tests/test_multiplexed.py b/tests/test_multiplexed.py index d625115..3f38abf 100644 --- a/tests/test_multiplexed.py +++ b/tests/test_multiplexed.py @@ -2,8 +2,9 @@ from __future__ import absolute_import -import os import multiprocessing +import os +import sys import time import pytest @@ -19,6 +20,10 @@ from thriftpy2.transport import TBufferedTransportFactory, TServerSocket +if sys.platform == "win32": + pytest.skip("requires fork", allow_module_level=True) + + mux = thriftpy2.load(os.path.join(os.path.dirname(__file__), "multiplexed.thrift")) sock_path = "/tmp/thriftpy_test.sock" diff --git a/tests/test_oneway.py b/tests/test_oneway.py index 812cfda..fcf88ba 100644 --- a/tests/test_oneway.py +++ b/tests/test_oneway.py @@ -1,9 +1,17 @@ +import sys +import time + +import pytest + import multiprocessing import thriftpy2 -import time from thriftpy2.rpc import make_client, make_server +if sys.platform == "win32": + pytest.skip("requires fork", allow_module_level=True) + + class Dispatcher(object): def Test(self, req): print("Get req msg: %s" % req) diff --git a/tests/test_protocol_binary.py b/tests/test_protocol_binary.py index 98f7f57..d4cf41f 100644 --- a/tests/test_protocol_binary.py +++ b/tests/test_protocol_binary.py @@ -173,7 +173,7 @@ def test_write_huge_struct(): proto.TBinaryProtocol(b).write_struct(item) -@pytest.mark.skipif(_compat.PYPY, reason="cybin can't be used in pypy") +@pytest.mark.skipif(not _compat.CYTHON, reason="cybin required") def test_string_binary_equivalency(): from thriftpy2.protocol.binary import TBinaryProtocolFactory from thriftpy2.protocol.cybin import TCyBinaryProtocolFactory diff --git a/tests/test_protocol_cybinary.py b/tests/test_protocol_cybinary.py index b71a770..997bb5b 100644 --- a/tests/test_protocol_cybinary.py +++ b/tests/test_protocol_cybinary.py @@ -7,16 +7,16 @@ import pytest -from thriftpy2._compat import PYPY +from thriftpy2._compat import CYTHON from thriftpy2.thrift import TDecodeException, TPayload, TType from thriftpy2.transport import TServerSocket, TSocket from thriftpy2.utils import hexlify -if not PYPY: +if CYTHON: from thriftpy2.protocol import cybin as proto from thriftpy2.transport.buffered import TCyBufferedTransport from thriftpy2.transport.memory import TCyMemoryBuffer else: - pytest.skip("cython not enabled in pypy.", allow_module_level=True) + pytest.skip("cython not enabled.", allow_module_level=True) class TItem(TPayload): diff --git a/tests/test_rpc.py b/tests/test_rpc.py index ba20828..e7b2283 100644 --- a/tests/test_rpc.py +++ b/tests/test_rpc.py @@ -2,11 +2,12 @@ from __future__ import absolute_import -import os import multiprocessing +import os import socket -import time import ssl +import sys +import time import pytest @@ -19,6 +20,10 @@ from thriftpy2.thrift import TApplicationException # noqa +if sys.platform == "win32": + pytest.skip("requires unix domain socket", allow_module_level=True) + + addressbook = thriftpy2.load(os.path.join(os.path.dirname(__file__), "addressbook.thrift")) unix_sock = "/tmp/thriftpy_test.sock" diff --git a/tests/test_socket.py b/tests/test_socket.py index 5532ffc..49755f6 100644 --- a/tests/test_socket.py +++ b/tests/test_socket.py @@ -115,6 +115,8 @@ def test_inet6_socket(): @pytest.mark.skipif( sys.platform == 'darwin' and os.getuid() != 0, reason='os.mknod() requires super-user privileges on darwin') +@pytest.mark.skipif(sys.platform == "win32", + reason="os.mknod is missing on Windows") def test_unix_domain_socket(): sock_file = "/tmp/thriftpy_test.sock" diff --git a/tests/test_tornado.py b/tests/test_tornado.py index 83bf354..5135909 100644 --- a/tests/test_tornado.py +++ b/tests/test_tornado.py @@ -10,6 +10,7 @@ import logging import socket + import pytest from tornado import gen, testing import thriftpy2 @@ -17,6 +18,10 @@ from thriftpy2.tornado import make_server from thriftpy2.transport import TTransportException + if sys.platform == "win32": + pytest.skip("add_socket is not implemented on Windiws", + allow_module_level=True) + logging.basicConfig(level=logging.INFO) addressbook = thriftpy2.load(path.join(path.dirname(__file__), diff --git a/tests/test_tracking.py b/tests/test_tracking.py index d4e9752..9d71d4d 100644 --- a/tests/test_tracking.py +++ b/tests/test_tracking.py @@ -23,6 +23,7 @@ import pickle import random import socket +import sys import tempfile import time @@ -57,6 +58,11 @@ else: cleanup_on_sigterm() + +if sys.platform == "win32": + pytest.skip("requires fork", allow_module_level=True) + + addressbook = thriftpy2.load(os.path.join(os.path.dirname(__file__), "addressbook.thrift")) _, db_file = tempfile.mkstemp()