Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PyPy Support + tests #393

Merged
merged 7 commits into from
Sep 20, 2024
Merged
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
5 changes: 4 additions & 1 deletion .github/workflows/build-and-run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
matrix:
os: [ubuntu-latest]
# All supported python versions on linux
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "pypy3.8", "pypy3.10"]
include:
# Oldest supported python on MacOS
- python-version: "3.7"
Expand All @@ -65,6 +65,9 @@ jobs:
# Newest supported python on Windows
- python-version: "3.13"
os: windows-latest
# PyPy on Windows
- python-version: "pypy3.10"
os: windows-latest
fail-fast: false

steps:
Expand Down
8 changes: 6 additions & 2 deletions DEV.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,12 @@ run code formatting checks.

## Running tests with multiple environments

- Requirement: One or more of the python versions mentioned in the envlist in tox.ini have to be installed and available for tox. Missing python versions are going to be simply skipped. If running on UNIX/macOS,
you may use [pyenv](https://github.com/pyenv/pyenv) to install multiple versions of python.
- Requirement: One or more of the python versions mentioned in the envlist in tox.ini have to be installed and available for tox. Missing python versions are going to be simply skipped. If running on UNIX/macOS, you may use [pyenv](https://github.com/pyenv/pyenv) to install multiple versions of python. In this case, you probably want to use the [pyenv global](https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-global-advanced) to mark multiple versions, as in the example below. Also note that pypy3.7 would be used in place of CPython3.7 with py37 tox marker, if CPython3.7 is not installed.

```
pyenv global 3.12.6 3.10.15 3.7.17 pypy3.10 pypy3.7
```

- To run the tests with multiple python versions, use tox:

```
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Unix above refers to Linux in wakepy 0.9.x, but upcoming releases of wakepy will

## Installing

Wakepy supports CPython 3.7 to 3.13 (PyPy support: [wakepy/#274](https://github.com/fohrloop/wakepy/issues/274)), and may be installed from [PyPI](https://pypi.org/project/wakepy/) with
Wakepy supports CPython 3.7 to 3.13 and PyPy 3.8 to 3.10, and may be installed from [PyPI](https://pypi.org/project/wakepy/) with

```
pip install wakepy
Expand Down Expand Up @@ -241,7 +241,7 @@ Wakepy vision is to support *any*<sup>†</sup> environment which runs Python. T
</tbody>
</table>

In addition, [supporting PyPy](https://github.com/fohrloop/wakepy/issues/274) is on the roadmap. If you have ideas or comments, please post yours on [wakepy/#317](https://github.com/fohrloop/wakepy/discussions/317).
If you have ideas or comments, please post yours on [wakepy/#317](https://github.com/fohrloop/wakepy/discussions/317).

## Licenses

Expand Down
7 changes: 6 additions & 1 deletion docs/source/installing.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Installing

The supported python versions are CPython 3.7, 3.8, 3.9, 3.10, 3.12 and 3.13 (PyPy support: [wakepy/#274](https://github.com/fohrloop/wakepy/issues/274)).
The supported python versions are

- CPython 3.7, 3.8, 3.9, 3.10, 3.12 and 3.13
- [PyPy](https://pypy.org/) 3.8, 3.9 and 3.10 (PyPy 3.7 might work as well [^pypy37])

[^pypy37]: The PyPy 3.7 also passes unit tests but cannot be used with mypy, so it's not officially supported. See: [this comment in wakepy/#393](https://github.com/fohrloop/wakepy/pull/393#issuecomment-2362974437)

## PyPI
Wakepy may be installed from [PyPI](https://pypi.org/project/wakepy/) with pip (or [uv](https://github.com/astral-sh/uv)). For example:
Expand Down
4 changes: 1 addition & 3 deletions requirements/requirements-mypy.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ mypy==1.11.2; python_version>='3.8'
mypy==1.4.1; python_version=='3.7'


# The following installs are for mypy.
# For mypy:
pytest -c requirements-test.txt
time-machine -c requirements-test.txt

types-colorama
types-colorama==0.4.15.12; python_version>='3.7'

4 changes: 0 additions & 4 deletions requirements/requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,5 @@ pytest-cov==5.0.0; python_version>='3.8'
pytest-cov==4.1.0; python_version=='3.7'
coverage-conditional-plugin==0.9.0

# Python 3.7 support dropped in time-machine 2.11.0
time-machine==2.14.0; python_version>='3.8'
time-machine==2.10.0; python_version=='3.7'

# Jeepney is used in the integration tests for creating a D-Bus server
jeepney==0.8.0;sys_platform=='linux'
28 changes: 12 additions & 16 deletions tests/unit/test_core/test_method/test_activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from unittest.mock import patch

import pytest
import time_machine

from tests.unit.test_core.testmethods import (
FAILURE_REASON,
Expand Down Expand Up @@ -227,23 +226,18 @@ def test_enter_mode_missing_heartbeat_failing(self):
assert "The only accepted return value is None" in err_message
assert heartbeat_call_time is None

@time_machine.travel(
dt.datetime(2023, 12, 21, 16, 17, tzinfo=dt.timezone.utc), tick=False
)
@pytest.mark.usefixtures("mock_datetime")
def test_enter_mode_missing_heartbeat_success(self):
"""Tests 4) MS from TABLE 1; enter_mode missing, heartbeat success"""

expected_time = dt.datetime.strptime(
"2023-12-21 16:17:00", "%Y-%m-%d %H:%M:%S"
).replace(tzinfo=dt.timezone.utc)
for method in combinations_of_test_methods(
enter_mode=[METHOD_MISSING],
heartbeat=[None],
exit_mode=METHOD_OPTIONS,
):
res = try_enter_and_heartbeat(method)
# Expecting: Return Success + '' + heartbeat time
assert res == (True, "", expected_time)
assert res == (True, "", self.fake_datetime_now)

def test_enter_mode_success_heartbeat_missing(self):
"""Tests 5) SM from TABLE 1; enter_mode success, heartbeat missing"""
Expand Down Expand Up @@ -307,23 +301,17 @@ def test_enter_mode_success_heartbeat_failing(self):
):
try_enter_and_heartbeat(method)

@time_machine.travel(
dt.datetime(2023, 12, 21, 16, 17, tzinfo=dt.timezone.utc), tick=False
)
@pytest.mark.usefixtures("mock_datetime")
def test_enter_mode_success_heartbeat_success(self):
"""Tests 7) SS from TABLE 1; enter_mode success & heartbeat success"""
expected_time = dt.datetime.strptime(
"2023-12-21 16:17:00", "%Y-%m-%d %H:%M:%S"
).replace(tzinfo=dt.timezone.utc)

for method in combinations_of_test_methods(
enter_mode=[None],
heartbeat=[None],
exit_mode=METHOD_OPTIONS,
):
res = try_enter_and_heartbeat(method)
# Expecting Return Success + '' + heartbeat time
assert res == (True, "", expected_time)
assert res == (True, "", self.fake_datetime_now)

def test_enter_mode_returns_bad_balue(self):
# Case: returning bad value (None return value accepted)
Expand All @@ -343,6 +331,14 @@ def test_heartbeat_returns_bad_balue(self):
assert "The only accepted return value is None" in err_message
assert heartbeat_call_time is None

fake_datetime_now = dt.datetime.strptime("2000-01-01 12:34:56", "%Y-%m-%d %H:%M:%S")

@pytest.fixture
def mock_datetime(self):
with patch("wakepy.core.method.dt.datetime") as datetime:
datetime.now.return_value = self.fake_datetime_now
yield


class TestCanIUseFails:
"""test caniuse_fails"""
Expand Down
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ envlist =
py311
py312
py313
pypy3.7
pypy3.10
check
minversion = 4.8.0

Expand Down