Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@ name: Build pytest-tcpclient

on: pull_request
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Upgrade pip
run: python -m pip install --upgrade pip
- name: Install tox
run: pip install tox
- name: Run tox
run: tox -e py
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Install the latest version of uv and set the python version
uses: astral-sh/setup-uv@v7
with:
python-version: "3.14"
activate-environment: "true"
- name: Test with nox
run: |
uv pip install nox
uv run --frozen nox
58 changes: 25 additions & 33 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,29 @@ on:
tags:
- "[0-9]+.[0-9]+.[0-9]+"
workflow_dispatch:
jobs:
publish:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8"]
steps:
- uses: actions/checkout@v3

- name: Set up Python ${{matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Upgrade pip
run: python -m pip install --upgrade pip

- name: Install tox
run: pip install -rdev_dependencies.txt

- name: Run tox
run: tox -e py

- name: Build dist
run: python -m build

- name: Check build
run: twine check --strict dist/*

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.pypi_token }}
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5

- name: Install the latest version of uv and set the python version
uses: astral-sh/setup-uv@v7
with:
python-version: "3.14"

- name: Test with nox
run: uv run --frozen nox

- name: Build dist
run: uv run python -m build

- name: Check build
run: uv run twine check --strict dist/*

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.pypi_token }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ coverage.xml
*.py,cover
.hypothesis/
.pytest_cache/
lcov.info

# Translations
*.mo
Expand Down
20 changes: 12 additions & 8 deletions DEV_README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ Development

If you want to use a virtual environment, do that first and activate it. You
can use any virtual environment system you like. However, if you want to use
``virtualenv`` (and you already have ``virtualenv`` installed) you could do this:
``uv`` (and you already have ``uv`` installed) you could do this:

.. code-block:: sh

$ virtualenv -p3.8 venv
$ uv venv --python 3.14 venv

Next, make the project:

Expand All @@ -18,6 +18,7 @@ Next, make the project:
That will do the following:

- Install all the dependencies
- Run code formatting and linting with ruff and black
- Run the tests
- Generate a coverage report
- Fail if the coverage is below 100%
Expand All @@ -36,8 +37,8 @@ Packages that ``pytest-tcpclient`` requires to run are listed in ``pyproject.tom
Packages required for development (testing, coverage and linting) are listed in
``dev_dependencies.txt``.

``tox`` has been configured (in ``tox.ini``) to install those packages before running
the tests.
``nox`` has been configured (in ``noxfile.py``) to install those packages before running
the tests, linting, and formatting.

``setuptools`` has been configured to supply the option ``dev`` for those extra packages.
For example, the ``Makefile`` has the following command to initialise the virtual
Expand All @@ -51,12 +52,15 @@ Default ``make`` target is ``style_and_test``
+++++++++++++++++++++++++++++++++++++++++++++

The default target in the ``Makfile`` is ``style_and_test`` which first calls
the linter, then runs the tests and, finally, checks that code coverage is 100%
the code formatter and linter (using ruff and black), then runs the tests and,
finally, checks that code coverage is 100%

``tox``
``nox``
+++++++

``tox`` is only used for CI builds. See ``.github/workflows/build.yml``.
``nox`` is used for running tests, linting, and formatting in isolated environments.
It supports multiple Python versions and is used for both local development and CI builds.
See ``.github/workflows/build.yml``.

``make`` detects changes to configuration files
+++++++++++++++++++++++++++++++++++++++++++++++
Expand All @@ -67,7 +71,7 @@ Continuous Integration and Deployment
+++++++++++++++++++++++++++++++++++++

There is a workflow (``.github/workflows/build.yml``) that will build and test pull
requests with ``tox``.
requests with ``nox``.

There is another workflow (``.github/workflows/publish.yml``) that is triggered
by the appearance of new version tags on the ``main`` branch. It will
Expand Down
32 changes: 18 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ message = @echo "\033[1;38;5:123m$1\033[0m"
BUILD_CONFIG := pyproject.toml dev_dependencies.txt

.make/venv_refreshed: $(BUILD_CONFIG)
python -m pip install -e .[dev]
uv pip install -e .[dev]
mkdir -p ${@D}
touch $@

Expand Down Expand Up @@ -38,33 +38,37 @@ run_examples: refresh_env

.PHONY: clean
clean:
rm -rf build dist .pytest_cache .tox .make .coverage examples_output
rm -rf build dist .pytest_cache .make .coverage examples_output
find . -name __pycache__ | xargs rm -rf
find . -name '*.egg-info' | xargs rm -rf
$(MAKE) -C docs clean

.PHONY: distclean
distclean: clean
rm -rf venv
rm -rf .venv

.PHONY: style
style: | refresh_env
pycodestyle src tests
nox -s formatter lint

#------------------------------------------------------------------------------
# tox
# nox

tox_initialised := .make/tox_initialised
.PHONY: nox
nox: | refresh_env
nox

.PHONY: tox
tox: ${tox_initialised} | refresh_env
tox
.PHONY: nox-test
nox-test: | refresh_env
nox -s test

${tox_initialised}: tox.ini $(BUILD_CONFIG) | refresh_env
$(call message,Building tox environment...)
mkdir -p ${@D}
tox -r --notest
touch $@
.PHONY: nox-lint
nox-lint: | refresh_env
nox -s lint

.PHONY: nox-format
nox-format: | refresh_env
nox -s formatter

#------------------------------------------------------------------------------
# distribution
Expand Down
10 changes: 6 additions & 4 deletions dev_dependencies.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
# in `dependencies.txt`

build>=0.8.0
coverage>=5.3.1,<6
pycodestyle>=2.5.0,<3
pytest-cov>=4.0.0,<5
coverage>=6
pytest-cov>=5
rst-include~=2.1
tox>=3.14.6,<4
nox[uv]
twine>=3.1.1
black
ruff
mypy
15 changes: 7 additions & 8 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,21 @@
# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'pytest-tcpclient'
copyright = '2022, Anders Lindstrom'
author = 'Anders Lindstrom'
project = "pytest-tcpclient"
copyright = "2022, Anders Lindstrom"
author = "Anders Lindstrom"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = []

templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

templates_path = ["_templates"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]


# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'alabaster'
html_static_path = ['_static']
html_theme = "alabaster"
html_static_path = ["_static"]
6 changes: 4 additions & 2 deletions examples/test_connection_reset_error.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import asyncio

import pytest

from pytest_tcpclient.plugin import MockTcpServer

@pytest.mark.asyncio()
async def test_connection_reset_error(tcpserver):

@pytest.mark.asyncio
async def test_connection_reset_error(tcpserver: MockTcpServer) -> None:
# Somehow, the following scenario causes a connection reset error to be raised in the
# mock server. Probably it will run differently on platforms other than Python 3.8 on Linux.

Expand Down
4 changes: 2 additions & 2 deletions examples/test_delayed_join.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import asyncio

import pytest


@pytest.mark.asyncio()
@pytest.mark.asyncio
async def test_delayed_join(tcpserver):

# `join` not called until right at the end. This was written to expose a bug that
# is now fixed.

Expand Down
4 changes: 2 additions & 2 deletions examples/test_early_error_doesnt_hang_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import asyncio

import pytest


@pytest.mark.asyncio()
@pytest.mark.asyncio
async def test_early_error_doesnt_hang_test(tcpserver):

reader, writer = await asyncio.open_connection(None, tcpserver.service_port)

tcpserver.expect_connect()
Expand Down
4 changes: 2 additions & 2 deletions examples/test_expect_bytes_connection_closed.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import asyncio

import pytest


@pytest.mark.asyncio()
@pytest.mark.asyncio
async def test_expect_bytes_connection_closed(tcpserver):

# Server expectations
tcpserver.expect_connect()
reader, writer = await asyncio.open_connection(None, tcpserver.service_port)
Expand Down
4 changes: 2 additions & 2 deletions examples/test_expect_bytes_success.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import asyncio

import pytest


@pytest.mark.asyncio()
@pytest.mark.asyncio
async def test_expect_bytes_success(tcpserver):

# --------------------------------------------------------------------------
# Server expectations

Expand Down
4 changes: 2 additions & 2 deletions examples/test_expect_bytes_times_out.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import asyncio

import pytest


@pytest.mark.asyncio()
@pytest.mark.asyncio
async def test_expect_bytes_times_out(tcpserver):

# --------------------------------------------------------------------------
# Server expectations. The server just expects the client to connect, send
# a message and then disconnect.
Expand Down
6 changes: 4 additions & 2 deletions examples/test_expect_bytes_wrong_bytes_sent.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import asyncio

import pytest

from pytest_tcpclient.plugin import MockTcpServer

@pytest.mark.asyncio()
async def test_expect_bytes_wrong_bytes_sent(tcpserver):

@pytest.mark.asyncio
async def test_expect_bytes_wrong_bytes_sent(tcpserver: MockTcpServer) -> None:
tcpserver.expect_connect()
reader, writer = await asyncio.open_connection(None, tcpserver.service_port)

Expand Down
4 changes: 2 additions & 2 deletions examples/test_expect_connect_is_absent.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import asyncio

import pytest


@pytest.mark.asyncio()
@pytest.mark.asyncio
async def test_expect_absent_expect_connection(tcpserver):

reader, writer = await asyncio.open_connection(None, tcpserver.service_port)

tcpserver.expect_bytes(b"Hello, world")
Expand Down
4 changes: 2 additions & 2 deletions examples/test_expect_connect_minimal.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import asyncio

import pytest


@pytest.mark.asyncio()
@pytest.mark.asyncio
async def test_expect_connect_minimal(tcpserver):

tcpserver.expect_connect()

reader, writer = await asyncio.open_connection(None, tcpserver.service_port)
Expand Down
Loading