From ee449e8b933d8284266dc7db197e8d048d53a4af Mon Sep 17 00:00:00 2001 From: Johannes Nussbaum <39048939+jnussbaum@users.noreply.github.com> Date: Wed, 17 Apr 2024 09:42:56 +0200 Subject: [PATCH] chore: use pytest instead of unittest / tooling / formatting (#93) --- .github/workflows/pr-tests.yml | 4 +- dsp_permissions_scripts/models/group.py | 1 - poetry.lock | 70 ++++++++++++++++++++++++- pyproject.toml | 9 ++++ tests/test_ap.py | 1 + tests/test_ap_serialization.py | 1 + tests/test_doap_serialization.py | 1 + tests/test_helpers.py | 1 + 8 files changed, 84 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pr-tests.yml b/.github/workflows/pr-tests.yml index 2b8b9fce..9fa50d89 100644 --- a/.github/workflows/pr-tests.yml +++ b/.github/workflows/pr-tests.yml @@ -29,7 +29,7 @@ jobs: run: poetry install - name: Formatting with ruff - run: poetry run ruff format . + run: poetry run ruff format --check . - name: Linting with ruff run: poetry run ruff check . @@ -38,6 +38,6 @@ jobs: run: poetry run mypy . - name: unittests - run: poetry run python -m unittest discover tests + run: poetry run pytest -s tests diff --git a/dsp_permissions_scripts/models/group.py b/dsp_permissions_scripts/models/group.py index 3d9c6ed4..3814963d 100644 --- a/dsp_permissions_scripts/models/group.py +++ b/dsp_permissions_scripts/models/group.py @@ -8,7 +8,6 @@ class Group(BaseModel): - model_config = ConfigDict(frozen=True) val: str diff --git a/poetry.lock b/poetry.lock index e3701f28..7c204bec 100644 --- a/poetry.lock +++ b/poetry.lock @@ -132,6 +132,17 @@ files = [ {file = "charset_normalizer-3.3.2-py3-none-any.whl", hash = "sha256:3e4d1f6587322d2788836a99c69062fbb091331ec940e02d12d179c1d53e25fc"}, ] +[[package]] +name = "colorama" +version = "0.4.6" +description = "Cross-platform colored terminal text." +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" +files = [ + {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, + {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, +] + [[package]] name = "distlib" version = "0.3.8" @@ -184,6 +195,17 @@ files = [ {file = "idna-3.7.tar.gz", hash = "sha256:028ff3aadf0609c1fd278d8ea3089299412a7a8b9bd005dd08b9f8285bcb5cfc"}, ] +[[package]] +name = "iniconfig" +version = "2.0.0" +description = "brain-dead simple config-ini parsing" +optional = false +python-versions = ">=3.7" +files = [ + {file = "iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"}, + {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, +] + [[package]] name = "mypy" version = "1.9.0" @@ -255,6 +277,17 @@ files = [ [package.dependencies] setuptools = "*" +[[package]] +name = "packaging" +version = "24.0" +description = "Core utilities for Python packages" +optional = false +python-versions = ">=3.7" +files = [ + {file = "packaging-24.0-py3-none-any.whl", hash = "sha256:2ddfb553fdf02fb784c234c7ba6ccc288296ceabec964ad2eae3777778130bc5"}, + {file = "packaging-24.0.tar.gz", hash = "sha256:eb82c5e3e56209074766e6885bb04b8c38a0c015d0a30036ebe7ece34c9989e9"}, +] + [[package]] name = "platformdirs" version = "4.2.0" @@ -270,6 +303,21 @@ files = [ docs = ["furo (>=2023.9.10)", "proselint (>=0.13)", "sphinx (>=7.2.6)", "sphinx-autodoc-typehints (>=1.25.2)"] test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=7.4.3)", "pytest-cov (>=4.1)", "pytest-mock (>=3.12)"] +[[package]] +name = "pluggy" +version = "1.4.0" +description = "plugin and hook calling mechanisms for python" +optional = false +python-versions = ">=3.8" +files = [ + {file = "pluggy-1.4.0-py3-none-any.whl", hash = "sha256:7db9f7b503d67d1c5b95f59773ebb58a8c1c288129a88665838012cfb07b8981"}, + {file = "pluggy-1.4.0.tar.gz", hash = "sha256:8c85c2876142a764e5b7548e7d9a0e0ddb46f5185161049a79b7e974454223be"}, +] + +[package.extras] +dev = ["pre-commit", "tox"] +testing = ["pytest", "pytest-benchmark"] + [[package]] name = "pre-commit" version = "3.7.0" @@ -398,6 +446,26 @@ files = [ [package.dependencies] typing-extensions = ">=4.6.0,<4.7.0 || >4.7.0" +[[package]] +name = "pytest" +version = "8.1.1" +description = "pytest: simple powerful testing with Python" +optional = false +python-versions = ">=3.8" +files = [ + {file = "pytest-8.1.1-py3-none-any.whl", hash = "sha256:2a8386cfc11fa9d2c50ee7b2a57e7d898ef90470a7a34c4b949ff59662bb78b7"}, + {file = "pytest-8.1.1.tar.gz", hash = "sha256:ac978141a75948948817d360297b7aae0fcb9d6ff6bc9ec6d514b85d5a65c044"}, +] + +[package.dependencies] +colorama = {version = "*", markers = "sys_platform == \"win32\""} +iniconfig = "*" +packaging = "*" +pluggy = ">=1.4,<2.0" + +[package.extras] +testing = ["argcomplete", "attrs (>=19.2)", "hypothesis (>=3.56)", "mock", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"] + [[package]] name = "python-dotenv" version = "1.0.1" @@ -589,4 +657,4 @@ test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess [metadata] lock-version = "2.0" python-versions = "^3.12.0" -content-hash = "1a10cbba17cab64c9b73631fecdf215770aa7b1ec3df3cee1fdd162b50c352a5" +content-hash = "eced2fcc562d11991fade44a74f72135337b5d9136f090b57df52ba08472a9d7" diff --git a/pyproject.toml b/pyproject.toml index 3544d3ff..b6226883 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,6 +18,7 @@ types-requests = "^2.31.0.20240406" python-dotenv = "^1.0.1" ruff = "^0.3.7" pre-commit = "^3.7.0" +pytest = "^8.1.1" [build-system] build-backend = "poetry.core.masonry.api" @@ -52,6 +53,14 @@ select = [ "B023", # flake8-bugbear: function-uses-loop-variable "FIX", # flake8-fixme: checks for FIXME, TODO, XXX, etc. ] +ignore = [ + "ISC001", # flake8-implicit-str-concat: single-line-implicit-string-concatenation # incompatible with the formatter +] + +[tool.ruff.lint.per-file-ignores] +"tests/*" = [ + "S101", # flake8-bandit: use of assert +] [tool.ruff.lint.pydocstyle] convention = "google" diff --git a/tests/test_ap.py b/tests/test_ap.py index b853eeb8..5fba5cff 100644 --- a/tests/test_ap.py +++ b/tests/test_ap.py @@ -7,6 +7,7 @@ # ruff: noqa: PT009 (pytest-unittest-assertion) (remove this line when pytest is used instead of unittest) # ruff: noqa: PT027 (pytest-unittest-raises-assertion) (remove this line when pytest is used instead of unittest) + class TestAp(unittest.TestCase): ap = Ap( forGroup=group.UNKNOWN_USER, diff --git a/tests/test_ap_serialization.py b/tests/test_ap_serialization.py index 3773d241..2e33ea60 100644 --- a/tests/test_ap_serialization.py +++ b/tests/test_ap_serialization.py @@ -12,6 +12,7 @@ # ruff: noqa: PT009 (pytest-unittest-assertion) (remove this line when pytest is used instead of unittest) + class TestApSerialization(unittest.TestCase): shortcode = "1234" project_iri = "http://rdfh.ch/projects/MsOaiQkcQ7-QPxsYBKckfQ" diff --git a/tests/test_doap_serialization.py b/tests/test_doap_serialization.py index ee21ff97..d0a9b5c0 100644 --- a/tests/test_doap_serialization.py +++ b/tests/test_doap_serialization.py @@ -13,6 +13,7 @@ # ruff: noqa: PT009 (pytest-unittest-assertion) (remove this line when pytest is used instead of unittest) + class TestDoapSerialization(unittest.TestCase): shortcode = "1234" diff --git a/tests/test_helpers.py b/tests/test_helpers.py index c0fe3773..83733c06 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -5,6 +5,7 @@ # ruff: noqa: PT009 (pytest-unittest-assertion) (remove this line when pytest is used instead of unittest) + class TestHelpers(unittest.TestCase): def test_sort_groups(self) -> None: groups_original = [