From 74724b87fe484249fdec5c7d9b839f34501a49f9 Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Mon, 29 Jul 2024 16:33:30 -0500 Subject: [PATCH] chore: wire up some basic python unit tests Hook up pytest to run tests for the package --- .github/workflows/code-test.yaml | 32 ++++++++ python/understack-workflows/poetry.lock | 73 ++++++++++++++++++- python/understack-workflows/pyproject.toml | 18 +++++ .../understack-workflows/tests/test_models.py | 10 +++ 4 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/code-test.yaml create mode 100644 python/understack-workflows/tests/test_models.py diff --git a/.github/workflows/code-test.yaml b/.github/workflows/code-test.yaml new file mode 100644 index 000000000..0f0ee23ac --- /dev/null +++ b/.github/workflows/code-test.yaml @@ -0,0 +1,32 @@ +name: code tests + +on: + push: + branches: + - main + paths: + - "python/**" + - ".github/workflows/code-test.yaml" + pull_request: + paths: + - "python/**" + - ".github/workflows/code-test.yaml" + workflow_dispatch: + +jobs: + understack-workflows: + runs-on: ubuntu-latest + defaults: + run: + working-directory: ./python/understack-workflows + + steps: + - uses: actions/checkout@v4 + - run: pipx install poetry==1.7.1 && poetry self add 'poetry-dynamic-versioning[plugin]' + - uses: actions/setup-python@v5 + with: + python-version-file: python/understack-workflows/pyproject.toml + cache: "poetry" + - run: poetry install --sync --with test + - run: poetry build + - run: poetry run pytest diff --git a/python/understack-workflows/poetry.lock b/python/understack-workflows/poetry.lock index 47055cf68..e7ca0b74e 100644 --- a/python/understack-workflows/poetry.lock +++ b/python/understack-workflows/poetry.lock @@ -255,6 +255,17 @@ dev = ["codecov", "doc8", "flake8", "invoke", "mypy", "nox", "pytest (>=4.6)", " test = ["codecov", "coverage", "gnureadline", "pytest (>=4.6)", "pytest-cov", "pytest-mock"] validate = ["flake8", "mypy", "types-pkg-resources"] +[[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 = "cryptography" version = "43.0.0" @@ -358,6 +369,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 = "iso8601" version = "2.1.0" @@ -653,6 +675,21 @@ docs = ["furo (>=2023.9.10)", "proselint (>=0.13)", "sphinx (>=7.2.6)", "sphinx- test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=7.4.3)", "pytest-cov (>=4.1)", "pytest-mock (>=3.12)"] type = ["mypy (>=1.8)"] +[[package]] +name = "pluggy" +version = "1.5.0" +description = "plugin and hook calling mechanisms for python" +optional = false +python-versions = ">=3.8" +files = [ + {file = "pluggy-1.5.0-py3-none-any.whl", hash = "sha256:44e1ad92c8ca002de6377e165f3e0f1be63266ab4d554740532335b9d75ea669"}, + {file = "pluggy-1.5.0.tar.gz", hash = "sha256:2cffa88e94fdc978c4c574f15f9e59b7f4201d439195c3715ca9e2486f1d0cf1"}, +] + +[package.extras] +dev = ["pre-commit", "tox"] +testing = ["pytest", "pytest-benchmark"] + [[package]] name = "prettytable" version = "3.10.2" @@ -851,6 +888,40 @@ files = [ {file = "pyreadline3-3.4.1.tar.gz", hash = "sha256:6f3d1f7b8a31ba32b73917cefc1f28cc660562f39aea8646d30bd6eff21f7bae"}, ] +[[package]] +name = "pytest" +version = "7.4.4" +description = "pytest: simple powerful testing with Python" +optional = false +python-versions = ">=3.7" +files = [ + {file = "pytest-7.4.4-py3-none-any.whl", hash = "sha256:b090cdf5ed60bf4c45261be03239c2c1c22df034fbffe691abe93cd80cea01d8"}, + {file = "pytest-7.4.4.tar.gz", hash = "sha256:2cf0005922c6ace4a3e2ec8b4080eb0d9753fdc93107415332f50ce9e7994280"}, +] + +[package.dependencies] +colorama = {version = "*", markers = "sys_platform == \"win32\""} +iniconfig = "*" +packaging = "*" +pluggy = ">=0.12,<2.0" + +[package.extras] +testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"] + +[[package]] +name = "pytest-github-actions-annotate-failures" +version = "0.2.0" +description = "pytest plugin to annotate failed tests with a workflow command for GitHub Actions" +optional = false +python-versions = ">=3.7" +files = [ + {file = "pytest-github-actions-annotate-failures-0.2.0.tar.gz", hash = "sha256:844ab626d389496e44f960b42f0a72cce29ae06d363426d17ea9ae1b4bef2288"}, + {file = "pytest_github_actions_annotate_failures-0.2.0-py3-none-any.whl", hash = "sha256:8bcef65fed503faaa0524b59cfeccc8995130972dd7b008d64193cc41b9cde85"}, +] + +[package.dependencies] +pytest = ">=4.0.0" + [[package]] name = "python-dateutil" version = "2.9.0.post0" @@ -1301,4 +1372,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "~3.11.0" -content-hash = "2e21e9915c10b206b66c345c02a96eaab2e425c254f4a1b0851d9caad3dac1fb" +content-hash = "e68102a6ff1f7c22b36ebbf7f52a639e562a8d780fe4c6a686ddbee6a238c4b5" diff --git a/python/understack-workflows/pyproject.toml b/python/understack-workflows/pyproject.toml index 3c218bfa2..91b1f7b7b 100644 --- a/python/understack-workflows/pyproject.toml +++ b/python/understack-workflows/pyproject.toml @@ -32,12 +32,30 @@ sushy = "^5" # required by sushy but not depended on by it setuptools = "^70" +[tool.peotry.group.test] +optional = true + +[tool.poetry.group.test.dependencies] +pytest = "^7" +pytest-github-actions-annotate-failures = "*" + [tool.poetry.scripts] synchronize-interfaces = "understack_workflows.main.synchronize_interfaces:main" synchronize-obm-creds = "understack_workflows.main.synchronize_obm_creds:main" synchronize-server = "understack_workflows.main.synchronize_server:main" sync-nautobot-interfaces = "understack_workflows.main.sync_nautobot_interfaces:main" +[tool.setuptools.packages.find] +# avoid packaging up our tests +exclude = ["tests*"] + +[tool.pytest.ini_options] +minversion = "6.0" +addopts = "-ra -q" +testpaths = [ + "tests", +] + [tool.ruff] target-version = "py311" fix = true diff --git a/python/understack-workflows/tests/test_models.py b/python/understack-workflows/tests/test_models.py new file mode 100644 index 000000000..102d2eb2f --- /dev/null +++ b/python/understack-workflows/tests/test_models.py @@ -0,0 +1,10 @@ +from understack_workflows.models import NIC + + +def test_nic(): + value = "test" + a = NIC(name=value, location=value, interfaces=[], model=value) + + assert a.name == value + assert a.location == value + assert a.model == value