Skip to content

Commit

Permalink
chore: migrating to pytest
Browse files Browse the repository at this point in the history
chore: migrating to pytest
  • Loading branch information
petereon authored Dec 19, 2024
2 parents 85810b0 + adfc01b commit 55695c8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 24 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ jobs:
python -m pip install poetry poethepoet
poetry install
poetry run pip install -r requirements-dev.txt
- name: Test with ward
- name: Test with pytest
run: |
export PYTHONPATH=$(pwd)
poe test
- name: Test with ward
- name: Test with pytest
run: |
poetry build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ jobs:
python -m pip install "poetry${{ env.POETRY_VERSION }}" poethepoet
poetry install
poetry run pip install -r requirements-dev.txt
- name: Test with ward
- name: Test with pytest
run: |
poe test
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ build-backend = "poetry.core.masonry.api"

[tool.poe.tasks]
lint = { shell = "black ./yakh/ && pylint ./yakh/"}
test = { shell = "ward -p ./tests"}
test = { shell = "pytest ./tests"}
4 changes: 2 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ward==0.68.0b0
ward-coverage==0.3.0
pytest==8.3.4
pytest-pretty==1.2.0
black==24.10.0
pylint==3.3.2
33 changes: 15 additions & 18 deletions tests/keypress_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from unittest import mock
from ward import test
import pytest
from yakh import get_key
from sys import platform

Expand Down Expand Up @@ -52,15 +52,13 @@
"\x1b\r": Keys.OPTION_ENTER,
}

for stdin_repr, key_repr in keys_mapping.items():

@test(f"Should capture `{stdin_repr}`")
def _(stdin_repr=stdin_repr, key_repr=key_repr):
with mock.patch(
"yakh._yakh.__get_key",
lambda *_, **__: stdin_repr,
):
assert get_key() == key_repr
@pytest.mark.parametrize("stdin_repr, key_repr", keys_mapping.items())
def test_key_capture(stdin_repr, key_repr):
with mock.patch(
"yakh._yakh.__get_key",
lambda *_, **__: stdin_repr,
):
assert get_key() == key_repr

elif platform in ("win32", "cygwin"):
keys_mapping = [
Expand Down Expand Up @@ -109,13 +107,12 @@ def _(stdin_repr=stdin_repr, key_repr=key_repr):
(("\x00", "K"), Keys.NUMPAD_LEFT_ARROW),
]

for stdin_repr, key_repr in keys_mapping:
@test(f"Should capture `{stdin_repr}`")
def _(stdin_repr=stdin_repr, key_repr=key_repr):
with mock.patch(
"yakh._yakh.msvcrt.getwch",
side_effect=stdin_repr
):
assert get_key() == key_repr
@pytest.mark.parametrize("stdin_repr, key_repr", keys_mapping)
def test_key_capture(stdin_repr, key_repr):
with mock.patch(
"yakh._yakh.msvcrt.getwch",
side_effect=stdin_repr,
):
assert get_key() == key_repr
else:
raise NotImplementedError(f"Platform `{platform}` is not supported")

0 comments on commit 55695c8

Please sign in to comment.