Skip to content

Commit

Permalink
Merge pull request #1994 from minrk/tests-outside
Browse files Browse the repository at this point in the history
move tests outside package
  • Loading branch information
minrk authored May 25, 2024
2 parents afe4248 + 63c7849 commit bf692e1
Show file tree
Hide file tree
Showing 43 changed files with 342 additions and 120 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ jobs:
- name: run tests
run: |
python -m pytest --maxfail 2 --cov zmq -m "not wheel and not new_console" -v zmq/tests
pytest --maxfail 2 --cov zmq -m "not wheel and not new_console" -v
- name: upload coverage
run: codecov
Expand Down
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ exclude = [
]
quote-style = "preserve"

[tool.ruff.isort]
known-first-party = ["zmq", "zmq_test_utils"]

[tool.ruff.lint]
select = [
"E",
Expand All @@ -85,7 +88,7 @@ exclude = ["buildutils/templates/*"]
[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F4", "E4"]
"__init__.pyi" = ["F4", "E4"]
"zmq/tests/*" = ["E4", "F4"]
"tests/*" = ["E4", "F4"]
"docs/source/conf.py" = ["E4"]
"zmq/eventloop/*" = ["E402"]
"zmq/ssh/forward.py" = ["E"]
Expand Down
3 changes: 1 addition & 2 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ markers =
new_console: these tests create a new console
wheel: these tests are for installs from a wheel, not dev-installs
testpaths =
zmq/tests

tests
# automatically run coroutine tests with asyncio
asyncio_mode = auto
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion zmq/tests/test_auth.py → tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import zmq
import zmq.asyncio
import zmq.auth
from zmq.tests import SkipTest, skip_pypy
from zmq_test_utils import SkipTest, skip_pypy

try:
import tornado
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import time
from unittest import TestCase

from zmq.tests import SkipTest
from zmq_test_utils import SkipTest

try:
from zmq.backend.cffi import ( # type: ignore
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion zmq/tests/test_context.py → tests/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from pytest import mark

import zmq
from zmq.tests import PYPY, BaseZMQTestCase, GreenTest, SkipTest
from zmq_test_utils import PYPY, BaseZMQTestCase, GreenTest, SkipTest


class KwargTestSocket(zmq.Socket):
Expand Down
23 changes: 9 additions & 14 deletions zmq/tests/test_cython.py → tests/test_cython.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,19 @@
)
@pytest.mark.parametrize('language_level', [3, 2])
def test_cython(language_level, request, tmpdir):
assert 'zmq.tests.cython_ext' not in sys.modules

importers = pyximport.install(
hook = pyximport.install(
setup_args=dict(include_dirs=zmq.get_includes()),
language_level=language_level,
build_dir=str(tmpdir),
)

cython_ext = None

def unimport():
pyximport.uninstall(*importers)
sys.modules.pop('zmq.tests.cython_ext', None)

request.addfinalizer(unimport)

# this import tests the compilation
from . import cython_ext
# don't actually need the hook, just the finder
pyximport.uninstall(*hook)
finder = hook[1]

# loading the module tests the compilation
spec = finder.find_spec("cython_ext", [HERE])
cython_ext = spec.loader.create_module(spec)
spec.loader.exec_module(cython_ext)

assert hasattr(cython_ext, 'send_recv_test')

Expand Down
2 changes: 1 addition & 1 deletion zmq/tests/test_decorators.py → tests/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import zmq
from zmq.decorators import context, socket
from zmq.tests import BaseZMQTestCase, term_context
from zmq_test_utils import BaseZMQTestCase, term_context

##############################################
# Test cases for @context
Expand Down
2 changes: 1 addition & 1 deletion zmq/tests/test_device.py → tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import zmq
from zmq import devices
from zmq.tests import PYPY, BaseZMQTestCase, GreenTest, SkipTest, have_gevent
from zmq_test_utils import PYPY, BaseZMQTestCase, GreenTest, SkipTest, have_gevent

if PYPY:
# cleanup of shared Context doesn't work on PyPy
Expand Down
2 changes: 1 addition & 1 deletion zmq/tests/test_draft.py → tests/test_draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pytest

import zmq
from zmq.tests import BaseZMQTestCase
from zmq_test_utils import BaseZMQTestCase


class TestDraftSockets(BaseZMQTestCase):
Expand Down
2 changes: 1 addition & 1 deletion zmq/tests/test_error.py → tests/test_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import zmq
from zmq import Again, ContextTerminated, ZMQError, strerror
from zmq.tests import BaseZMQTestCase
from zmq_test_utils import BaseZMQTestCase


class TestZMQError(BaseZMQTestCase):
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion zmq/tests/test_future.py → tests/test_future.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import zmq
from zmq.eventloop import future
from zmq.tests import BaseZMQTestCase
from zmq_test_utils import BaseZMQTestCase


class TestFutureSocket(BaseZMQTestCase):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion zmq/tests/test_log.py → tests/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import zmq
from zmq.log import handlers
from zmq.tests import BaseZMQTestCase
from zmq_test_utils import BaseZMQTestCase


class TestPubLog(BaseZMQTestCase):
Expand Down
2 changes: 1 addition & 1 deletion zmq/tests/test_message.py → tests/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import time

import zmq
from zmq.tests import PYPY, BaseZMQTestCase, SkipTest, skip_pypy
from zmq_test_utils import PYPY, BaseZMQTestCase, SkipTest, skip_pypy

# some useful constants:

Expand Down
2 changes: 1 addition & 1 deletion zmq/tests/test_monitor.py → tests/test_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import zmq
import zmq.asyncio
from zmq.tests import require_zmq_4
from zmq.utils.monitor import recv_monitor_message
from zmq_test_utils import require_zmq_4

pytestmark = require_zmq_4
import pytest
Expand Down
2 changes: 1 addition & 1 deletion zmq/tests/test_monqueue.py → tests/test_monqueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import zmq
from zmq import devices
from zmq.tests import PYPY, BaseZMQTestCase
from zmq_test_utils import PYPY, BaseZMQTestCase

if PYPY or zmq.zmq_version_info() >= (4, 1):
# cleanup of shared Context doesn't work on PyPy
Expand Down
2 changes: 1 addition & 1 deletion zmq/tests/test_multipart.py → tests/test_multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


import zmq
from zmq.tests import BaseZMQTestCase, GreenTest, have_gevent
from zmq_test_utils import BaseZMQTestCase, GreenTest, have_gevent


class TestMultipart(BaseZMQTestCase):
Expand Down
50 changes: 50 additions & 0 deletions tests/test_mypy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""
Test our typing with mypy
"""

import os
import sys
from pathlib import Path
from subprocess import PIPE, STDOUT, Popen

import pytest

pytest.importorskip("mypy")

repo_root = Path(__file__).parents[1]


print(repo_root)
examples_dir = repo_root / "examples"
mypy_dir = repo_root / "mypy_tests"


def run_mypy(*mypy_args):
"""Run mypy for a path
Captures output and reports it on errors
"""
p = Popen(
[sys.executable, "-m", "mypy"] + list(mypy_args), stdout=PIPE, stderr=STDOUT
)
o, _ = p.communicate()
out = o.decode("utf8", "replace")
print(out)
assert p.returncode == 0, out


examples = [path.name for path in examples_dir.glob("*") if path.is_dir()]


@pytest.mark.parametrize("example", examples)
def test_mypy_example(example):
example_dir = examples_dir / example
run_mypy("--disallow-untyped-calls", str(example_dir))


mypy_tests = [p.name for p in mypy_dir.glob("*.py")]


@pytest.mark.parametrize("filename", mypy_tests)
def test_mypy(filename):
run_mypy("--disallow-untyped-calls", str(mypy_dir / filename))
2 changes: 1 addition & 1 deletion zmq/tests/test_pair.py → tests/test_pair.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


import zmq
from zmq.tests import BaseZMQTestCase, GreenTest, have_gevent
from zmq_test_utils import BaseZMQTestCase, GreenTest, have_gevent

x = b' '

Expand Down
2 changes: 1 addition & 1 deletion zmq/tests/test_poll.py → tests/test_poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pytest import mark

import zmq
from zmq.tests import GreenTest, PollZMQTestCase, have_gevent
from zmq_test_utils import GreenTest, PollZMQTestCase, have_gevent


def wait():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import zmq
from zmq import devices
from zmq.tests import PYPY, BaseZMQTestCase, SkipTest
from zmq_test_utils import PYPY, BaseZMQTestCase, SkipTest

if PYPY:
# cleanup of shared Context doesn't work on PyPy
Expand Down
2 changes: 1 addition & 1 deletion zmq/tests/test_pubsub.py → tests/test_pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import time

import zmq
from zmq.tests import BaseZMQTestCase, GreenTest, have_gevent
from zmq_test_utils import BaseZMQTestCase, GreenTest, have_gevent


class TestPubSub(BaseZMQTestCase):
Expand Down
2 changes: 1 addition & 1 deletion zmq/tests/test_reqrep.py → tests/test_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


import zmq
from zmq.tests import BaseZMQTestCase, GreenTest, have_gevent
from zmq_test_utils import BaseZMQTestCase, GreenTest, have_gevent


class TestReqRep(BaseZMQTestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pytest import mark

import zmq
from zmq.tests import BaseZMQTestCase, SkipTest
from zmq_test_utils import BaseZMQTestCase, SkipTest

# Partially based on EINTRBaseTest from CPython 3.5 eintr_tester

Expand Down
2 changes: 1 addition & 1 deletion zmq/tests/test_security.py → tests/test_security.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from threading import Thread

import zmq
from zmq.tests import PYPY, BaseZMQTestCase, SkipTest
from zmq.utils import z85
from zmq_test_utils import PYPY, BaseZMQTestCase, SkipTest

USER = b"admin"
PASS = b"password"
Expand Down
2 changes: 1 addition & 1 deletion zmq/tests/test_socket.py → tests/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pytest import mark

import zmq
from zmq.tests import BaseZMQTestCase, GreenTest, SkipTest, have_gevent, skip_pypy
from zmq_test_utils import BaseZMQTestCase, GreenTest, SkipTest, have_gevent, skip_pypy

pypy = platform.python_implementation().lower() == 'pypy'
windows = platform.platform().lower().startswith('windows')
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion zmq/tests/test_win32_shim.py → tests/test_win32_shim.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

from pytest import mark

from zmq.tests import BaseZMQTestCase
from zmq.utils.win32 import allow_interrupt
from zmq_test_utils import BaseZMQTestCase


def count_calls(f):
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit bf692e1

Please sign in to comment.