From afc25217fa2a3bf9c95f969d56454f987756fd9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niko=20F=C3=B6hr?= Date: Thu, 19 Sep 2024 23:01:53 +0300 Subject: [PATCH 1/7] add pypy3.7 adn pypy3.10 to tox.ini --- tox.ini | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tox.ini b/tox.ini index 42918879..b46df7de 100644 --- a/tox.ini +++ b/tox.ini @@ -7,6 +7,8 @@ envlist = py311 py312 py313 + pypy3.7 + pypy3.10 check minversion = 4.8.0 From a7b5e3f9b42b345da54a83b1fc3b9d6f149fec1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niko=20F=C3=B6hr?= Date: Fri, 20 Sep 2024 09:04:56 +0300 Subject: [PATCH 2/7] replace time-machine with unittest mock --- requirements/requirements-mypy.txt | 4 +--- requirements/requirements-test.txt | 4 ---- .../test_core/test_method/test_activation.py | 16 +++++++--------- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/requirements/requirements-mypy.txt b/requirements/requirements-mypy.txt index 2b7c86c2..c6bc79fc 100644 --- a/requirements/requirements-mypy.txt +++ b/requirements/requirements-mypy.txt @@ -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' diff --git a/requirements/requirements-test.txt b/requirements/requirements-test.txt index ce82f0e0..ab8dfa32 100644 --- a/requirements/requirements-test.txt +++ b/requirements/requirements-test.txt @@ -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' \ No newline at end of file diff --git a/tests/unit/test_core/test_method/test_activation.py b/tests/unit/test_core/test_method/test_activation.py index 518d6d93..057e17b9 100644 --- a/tests/unit/test_core/test_method/test_activation.py +++ b/tests/unit/test_core/test_method/test_activation.py @@ -8,7 +8,6 @@ from unittest.mock import patch import pytest -import time_machine from tests.unit.test_core.testmethods import ( FAILURE_REASON, @@ -227,15 +226,15 @@ 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 - ) - def test_enter_mode_missing_heartbeat_success(self): + @patch("wakepy.core.method.dt.datetime") + def test_enter_mode_missing_heartbeat_success(self, mock_datetime): """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) + mock_datetime.now.return_value = expected_time + for method in combinations_of_test_methods( enter_mode=[METHOD_MISSING], heartbeat=[None], @@ -307,14 +306,13 @@ 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 - ) - def test_enter_mode_success_heartbeat_success(self): + @patch("wakepy.core.method.dt.datetime") + def test_enter_mode_success_heartbeat_success(self, mock_datetime): """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) + mock_datetime.now.return_value = expected_time for method in combinations_of_test_methods( enter_mode=[None], From 0cb0f3211fd76df24b9541a21436bc5fab8f19f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niko=20F=C3=B6hr?= Date: Fri, 20 Sep 2024 09:25:56 +0300 Subject: [PATCH 3/7] refactor the tests --- .../test_core/test_method/test_activation.py | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/tests/unit/test_core/test_method/test_activation.py b/tests/unit/test_core/test_method/test_activation.py index 057e17b9..e41a250e 100644 --- a/tests/unit/test_core/test_method/test_activation.py +++ b/tests/unit/test_core/test_method/test_activation.py @@ -226,15 +226,10 @@ 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 - @patch("wakepy.core.method.dt.datetime") - def test_enter_mode_missing_heartbeat_success(self, mock_datetime): + @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) - mock_datetime.now.return_value = expected_time - for method in combinations_of_test_methods( enter_mode=[METHOD_MISSING], heartbeat=[None], @@ -242,7 +237,7 @@ def test_enter_mode_missing_heartbeat_success(self, mock_datetime): ): 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""" @@ -306,14 +301,9 @@ def test_enter_mode_success_heartbeat_failing(self): ): try_enter_and_heartbeat(method) - @patch("wakepy.core.method.dt.datetime") - def test_enter_mode_success_heartbeat_success(self, mock_datetime): + @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) - mock_datetime.now.return_value = expected_time - for method in combinations_of_test_methods( enter_mode=[None], heartbeat=[None], @@ -321,7 +311,7 @@ def test_enter_mode_success_heartbeat_success(self, mock_datetime): ): 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) @@ -341,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""" From afdebb253432043042a89715d2f219afbcf1acc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niko=20F=C3=B6hr?= Date: Fri, 20 Sep 2024 09:53:50 +0300 Subject: [PATCH 4/7] add pypy to gh actions test matrix --- .github/workflows/build-and-run-tests.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-and-run-tests.yml b/.github/workflows/build-and-run-tests.yml index 1b2e07d2..29919990 100644 --- a/.github/workflows/build-and-run-tests.yml +++ b/.github/workflows/build-and-run-tests.yml @@ -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.7", "pypy3.10"] include: # Oldest supported python on MacOS - python-version: "3.7" @@ -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: From 6431127643c38eb74fea2a98b41deaece3822206 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niko=20F=C3=B6hr?= Date: Fri, 20 Sep 2024 10:30:28 +0300 Subject: [PATCH 5/7] Replace pypy3.7 with pypy3.8 in CI pipelines The pypy3.7 does not support typed-ast which is a requirement in the mypy version supporting Python 3.7 --- .github/workflows/build-and-run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-run-tests.yml b/.github/workflows/build-and-run-tests.yml index 29919990..d9a98e43 100644 --- a/.github/workflows/build-and-run-tests.yml +++ b/.github/workflows/build-and-run-tests.yml @@ -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", "pypy3.7", "pypy3.10"] + 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" From cc61939774b5f44e36e781ae2998043713e610df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niko=20F=C3=B6hr?= Date: Fri, 20 Sep 2024 10:41:10 +0300 Subject: [PATCH 6/7] update docs about PyPy --- README.md | 4 ++-- docs/source/installing.md | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cafa222f..1aec957c 100644 --- a/README.md +++ b/README.md @@ -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 @@ -241,7 +241,7 @@ Wakepy vision is to support *any* environment which runs Python. T -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 diff --git a/docs/source/installing.md b/docs/source/installing.md index 08ec4b31..9c5970b2 100644 --- a/docs/source/installing.md +++ b/docs/source/installing.md @@ -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: From d0507b16072f38e47deacd18f0457894420eb215 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niko=20F=C3=B6hr?= Date: Fri, 20 Sep 2024 10:49:51 +0300 Subject: [PATCH 7/7] update DEV.md for PyPy --- DEV.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/DEV.md b/DEV.md index a72493b8..f5c88e8d 100644 --- a/DEV.md +++ b/DEV.md @@ -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: ```