From a5c62df551d2ff8404dd081a616601cc4f838af6 Mon Sep 17 00:00:00 2001 From: Justin Flannery Date: Fri, 5 May 2023 14:17:03 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20freeze=20tests=20in=20time?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 3 +++ requirements/requirements-dev.txt | 39 +++++++++++++++++++++++++++++- requirements/requirements-prod.txt | 16 +++++++++++- tests/conftest.py | 16 ++++++++++++ 4 files changed, 72 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index fa626795..8c7ecce0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -74,6 +74,7 @@ dependencies = [ "pytest-mock~=3.10.0", "pytest-vcr~=1.0.2", "pytest-xdist~=3.2.1", + "freezegun~=1.2.1", "mkdocs~=1.4.2", "mkdocs-material~=9.1.6", "mkdocs-click~=0.8.0", @@ -87,7 +88,9 @@ dependencies = [ "pandas-stubs~=2.0.0.230412", "pip-tools~=6.13.0" ] +features = ["all"] pre-install-commands = ["pip install -U --no-deps -r requirements/requirements-dev.txt"] +python = "3.9" [tool.hatch.envs.default.env-vars] PUSHOVER_PUSH_TOKEN = "{env:PUSHOVER_PUSH_TOKEN:placeholder}" diff --git a/requirements/requirements-dev.txt b/requirements/requirements-dev.txt index 57d4bb86..59a1e807 100644 --- a/requirements/requirements-dev.txt +++ b/requirements/requirements-dev.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.11 +# This file is autogenerated by pip-compile with Python 3.9 # by the following command: # # pip-compile --all-extras --generate-hashes --output-file=requirements/requirements-dev.txt --resolver=backtracking @@ -192,6 +192,10 @@ coverage[toml]==7.2.3 \ --hash=sha256:fd214917cabdd6f673a29d708574e9fbdb892cb77eb426d0eae3490d95ca7859 \ --hash=sha256:fff5aaa6becf2c6a1699ae6a39e2e6fb0672c2d42eca8eb0cafa91cf2e9bd312 # via pytest-cov +exceptiongroup==1.1.1 \ + --hash=sha256:232c37c63e4f682982c8b6459f33a8981039e5fb8756b2074364e5055c498c9e \ + --hash=sha256:d484c3090ba2889ae2928419117447a14daf3c1231d5e30d0aae34f354f01785 + # via pytest execnet==1.9.0 \ --hash=sha256:8f694f3ba9cc92cab508b152dcfe322153975c29bda272e2fd7f3f00f36e47c5 \ --hash=sha256:a295f7cc774947aac58dde7fdc85f4aa00c42adf5d8f5468fc630c1acf30a142 @@ -200,6 +204,10 @@ fake-useragent==1.1.3 \ --hash=sha256:1c06f0aa7d6e4894b919b30b9c7ebd72ff497325191057fbb5df3d5db06b93fc \ --hash=sha256:695d3b1bf7d11d04ab0f971fb73b0ca8de98b78bbadfbc8bacbc9a48423f7531 # via camply (pyproject.toml) +freezegun==1.2.2 \ + --hash=sha256:cd22d1ba06941384410cd967d8a99d5ae2442f57dfafeff2fda5de8dc5c05446 \ + --hash=sha256:ea1b963b993cb9ea195adbd893a48d573fda951b0da64f60883d7e988b606c9f + # via camply (pyproject.toml) ghp-import==2.1.0 \ --hash=sha256:8337dd7b50877f163d4c0289bc1f1c7f127550241988d568c1db512c4324a619 \ --hash=sha256:9c535c4c61193c2df8871222567d7fd7e5014d835f97dc7b7439069e2413d343 @@ -214,6 +222,16 @@ idna==3.4 \ # via # requests # yarl +importlib-metadata==6.6.0 \ + --hash=sha256:43dd286a2cd8995d5eaef7fee2066340423b818ed3fd70adf0bad5f1fac53fed \ + --hash=sha256:92501cdf9cc66ebd3e612f1b4f0c0765dfa42f0fa38ffb319b6bd84dd675d705 + # via + # markdown + # mkdocs +importlib-resources==5.12.0 \ + --hash=sha256:4be82589bf5c1d7999aedf2a45159d10cb3ca4f19b2271f8792bc8e6da7b22f6 \ + --hash=sha256:7b1deeebbf351c7578e09bf2f63fa2ce8b5ffec296e0d349139d43cca061a81a + # via fake-useragent iniconfig==2.0.0 \ --hash=sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3 \ --hash=sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374 @@ -639,6 +657,7 @@ python-dateutil==2.8.2 \ --hash=sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86 \ --hash=sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9 # via + # freezegun # ghp-import # pandas python-dotenv==1.0.0 \ @@ -821,6 +840,16 @@ tenacity==8.2.2 \ --hash=sha256:2f277afb21b851637e8f52e6a613ff08734c347dc19ade928e519d7d2d8569b0 \ --hash=sha256:43af037822bd0029025877f3b2d97cc4d7bb0c2991000a3d59d71517c5c969e0 # via camply (pyproject.toml) +tomli==2.0.1 \ + --hash=sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc \ + --hash=sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f + # via + # black + # build + # coverage + # mypy + # pyproject-hooks + # pytest twilio==7.17.0 \ --hash=sha256:312e25b0a1ca782974a359d95123f270574e6e4b195b0e2095a156219ad7b7ec \ --hash=sha256:f43de32cdc27f8853bb02ab0b8703a487beffbb9dcc8118398b6757e1376e6ed @@ -833,6 +862,8 @@ typing-extensions==4.5.0 \ --hash=sha256:5cb5f4a79139d699607b3ef622a1dedafa84e115ab0024e0d9c044a9479ca7cb \ --hash=sha256:fb33085c39dd998ac16d1431ebc293a8b3eedd00fd4a32de0ff79002c19511b4 # via + # black + # mkdocstrings # mypy # pydantic urllib3==1.26.15 \ @@ -1029,6 +1060,12 @@ yarl==1.9.1 \ --hash=sha256:f878a78ed2ccfbd973cab46dd0933ecd704787724db23979e5731674d76eb36f \ --hash=sha256:f8e73f526140c1c32f5fca4cd0bc3b511a1abcd948f45b2a38a95e4edb76ca72 # via vcrpy +zipp==3.15.0 \ + --hash=sha256:112929ad649da941c23de50f356a2b5570c954b65150642bccdd66bf194d224b \ + --hash=sha256:48904fc76a60e542af151aded95726c1a5c34ed43ab4134b597665c86d7ad556 + # via + # importlib-metadata + # importlib-resources # WARNING: The following packages were not pinned, but pip requires them to be # pinned when the requirements file includes hashes. Consider using the --allow-unsafe flag. diff --git a/requirements/requirements-prod.txt b/requirements/requirements-prod.txt index 956a20fb..2abdc8ef 100644 --- a/requirements/requirements-prod.txt +++ b/requirements/requirements-prod.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.11 +# This file is autogenerated by pip-compile with Python 3.9 # by the following command: # # pip-compile --all-extras --generate-hashes --output-file=requirements/requirements-prod.txt --resolver=backtracking @@ -106,6 +106,14 @@ idna==3.4 \ --hash=sha256:814f528e8dead7d329833b91c5faa87d60bf71824cd12a7530b5526063d02cb4 \ --hash=sha256:90b77e79eaa3eba6de819a0c442c0b4ceefc341a7a2ab77d7562bf49f425c5c2 # via requests +importlib-metadata==6.6.0 \ + --hash=sha256:43dd286a2cd8995d5eaef7fee2066340423b818ed3fd70adf0bad5f1fac53fed \ + --hash=sha256:92501cdf9cc66ebd3e612f1b4f0c0765dfa42f0fa38ffb319b6bd84dd675d705 + # via markdown +importlib-resources==5.12.0 \ + --hash=sha256:4be82589bf5c1d7999aedf2a45159d10cb3ca4f19b2271f8792bc8e6da7b22f6 \ + --hash=sha256:7b1deeebbf351c7578e09bf2f63fa2ce8b5ffec296e0d349139d43cca061a81a + # via fake-useragent markdown==3.4.3 \ --hash=sha256:065fd4df22da73a625f14890dd77eb8040edcbd68794bcd35943be14490608b2 \ --hash=sha256:8bf101198e004dc93e84a12a7395e31aac6a9c9942848ae1d99b9d72cf9b3520 @@ -331,3 +339,9 @@ urllib3==1.26.15 \ --hash=sha256:8a388717b9476f934a21484e8c8e61875ab60644d29b9b39e11e4b9dc1c6b305 \ --hash=sha256:aa751d169e23c7479ce47a0cb0da579e3ede798f994f5816a74e4f4500dcea42 # via requests +zipp==3.15.0 \ + --hash=sha256:112929ad649da941c23de50f356a2b5570c954b65150642bccdd66bf194d224b \ + --hash=sha256:48904fc76a60e542af151aded95726c1a5c34ed43ab4134b597665c86d7ad556 + # via + # importlib-metadata + # importlib-resources diff --git a/tests/conftest.py b/tests/conftest.py index 3afea598..792104a7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -9,6 +9,7 @@ import pytest from click.testing import CliRunner, Result +from freezegun import freeze_time from camply import AvailableCampsite from camply.cli import camply_command_line @@ -25,6 +26,21 @@ module_scope = pytest.fixture(scope="module") +@pytest.fixture(autouse=True) +def freeze_current_time(): + """ + Freeze the Current Time to April 28, 2023 at Noon + + Since camply saves the responses of the API calls, we need to freeze the time + to ensure the responses are the same across all tests. + """ + year = 2023 + time_of_year = [4, 28, 12, 0, 0] # April 28th + frozen_time = datetime.datetime(year, *time_of_year) + with freeze_time(frozen_time, tick=True): + yield + + class CamplyRunner(CliRunner): """ Custom CLI Runner for Camply