From 6734323535dbf54408144b2d309d2eb8a6d441b7 Mon Sep 17 00:00:00 2001 From: Jacco Flenter Date: Tue, 11 Apr 2023 11:17:46 +0200 Subject: [PATCH] Update test --- .github/workflows/build.yml | 7 +++- README.md | 27 +++++++++++++- poetry.lock | 74 +++++++++++++++++++++++++++++++++++-- pyproject.toml | 1 + src/test_prometheus_url.py | 10 +++-- 5 files changed, 107 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0730264..32ad29b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,6 +20,9 @@ jobs: cache: "poetry" - name: Install dependencies run: poetry install --no-interaction --no-root --with dev - - uses: psf/black@stable - - name: Run pyright + - name: Check code formatting + uses: psf/black@stable + - name: Lint code run: poetry run pyright + - name: run test + run: poetry run pytest diff --git a/README.md b/README.md index 3178c1e..faf007a 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,29 @@ This package uses [poetry](https://python-poetry.org) as a package manager, with By default, poetry will only install required dependencies, if you want to run examples, install using this command: -`poetry install --with examples` +```sh +poetry install --with examples +``` + +Code in this repository is: + +- formatted using [black](https://black.readthedocs.io/en/stable/). +- contains type definitions (which are linted by [pyright](https://microsoft.github.io/pyright/)) +- tested using [pytest](https://docs.pytest.org/) + +In order to run these tools locally you have to install them, you can install them using poetry: -Code in this repository is formatted using [black](https://black.readthedocs.io/en/stable/) and contains type definitions (which are linted by [pyright](https://microsoft.github.io/pyright/)) +```sh +poetry install --with dev +``` + +After that you can run the tools individually + +```sh +# Formatting using black +poetry run black . +# Lint using pyright +poetry run pyright +# Run the tests using pytest +poetry run pytest +``` diff --git a/poetry.lock b/poetry.lock index 55f171d..d7ca949 100644 --- a/poetry.lock +++ b/poetry.lock @@ -319,6 +319,21 @@ files = [ {file = "docutils-0.19.tar.gz", hash = "sha256:33995a6753c30b7f577febfc2c50411fec6aac7f7ffeb7c4cfe5991072dcf9e6"}, ] +[[package]] +name = "exceptiongroup" +version = "1.1.1" +description = "Backport of PEP 654 (exception groups)" +category = "dev" +optional = false +python-versions = ">=3.7" +files = [ + {file = "exceptiongroup-1.1.1-py3-none-any.whl", hash = "sha256:232c37c63e4f682982c8b6459f33a8981039e5fb8756b2074364e5055c498c9e"}, + {file = "exceptiongroup-1.1.1.tar.gz", hash = "sha256:d484c3090ba2889ae2928419117447a14daf3c1231d5e30d0aae34f354f01785"}, +] + +[package.extras] +test = ["pytest (>=6)"] + [[package]] name = "fastapi" version = "0.95.0" @@ -404,6 +419,18 @@ zipp = {version = ">=3.1.0", markers = "python_version < \"3.10\""} docs = ["furo", "jaraco.packaging (>=9)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-lint"] testing = ["flake8 (<5)", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.3)", "pytest-flake8", "pytest-mypy (>=0.9.1)"] +[[package]] +name = "iniconfig" +version = "2.0.0" +description = "brain-dead simple config-ini parsing" +category = "dev" +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 = "jaraco-classes" version = "3.2.3" @@ -517,7 +544,7 @@ files = [ name = "nodeenv" version = "1.7.0" description = "Node.js virtual environment builder" -category = "main" +category = "dev" optional = false python-versions = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*" files = [ @@ -555,6 +582,22 @@ files = [ [package.extras] testing = ["pytest", "pytest-cov"] +[[package]] +name = "pluggy" +version = "1.0.0" +description = "plugin and hook calling mechanisms for python" +category = "dev" +optional = false +python-versions = ">=3.6" +files = [ + {file = "pluggy-1.0.0-py2.py3-none-any.whl", hash = "sha256:74134bbf457f031a36d68416e1509f34bd5ccc019f0bcc952c7b909d06b37bd3"}, + {file = "pluggy-1.0.0.tar.gz", hash = "sha256:4224373bacce55f955a878bf9cfa763c1e360858e330072059e10bad68531159"}, +] + +[package.extras] +dev = ["pre-commit", "tox"] +testing = ["pytest", "pytest-benchmark"] + [[package]] name = "prometheus-client" version = "0.16.0" @@ -669,7 +712,7 @@ tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""} name = "pyright" version = "1.1.302" description = "Command line wrapper for pyright" -category = "main" +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -684,6 +727,29 @@ nodeenv = ">=1.6.0" all = ["twine (>=3.4.1)"] dev = ["twine (>=3.4.1)"] +[[package]] +name = "pytest" +version = "7.3.0" +description = "pytest: simple powerful testing with Python" +category = "dev" +optional = false +python-versions = ">=3.7" +files = [ + {file = "pytest-7.3.0-py3-none-any.whl", hash = "sha256:933051fa1bfbd38a21e73c3960cebdad4cf59483ddba7696c48509727e17f201"}, + {file = "pytest-7.3.0.tar.gz", hash = "sha256:58ecc27ebf0ea643ebfdf7fb1249335da761a00c9f955bcd922349bcb68ee57d"}, +] + +[package.dependencies] +colorama = {version = "*", markers = "sys_platform == \"win32\""} +exceptiongroup = {version = ">=1.0.0rc8", markers = "python_version < \"3.11\""} +iniconfig = "*" +packaging = "*" +pluggy = ">=0.12,<2.0" +tomli = {version = ">=1.0.0", markers = "python_version < \"3.11\""} + +[package.extras] +testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "xmlschema"] + [[package]] name = "python-dotenv" version = "1.0.0" @@ -823,7 +889,7 @@ jeepney = ">=0.6" name = "setuptools" version = "67.6.1" description = "Easily download, build, install, upgrade, and uninstall Python packages" -category = "main" +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -993,4 +1059,4 @@ testing = ["big-O", "flake8 (<5)", "jaraco.functools", "jaraco.itertools", "more [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "90aeb247a71d500a324409a2d7ae33e9d8150665f5851d8e0428f4905f146f20" +content-hash = "0387b1f4d7f8e51e6d5e58c7e6d5808d82e9cd33dc7d7ef4be7a44323581bf19" diff --git a/pyproject.toml b/pyproject.toml index c06785b..e7c5d38 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,6 +24,7 @@ optional = true [tool.poetry.group.dev.dependencies] pyright = "^1.1.302" +pytest = "^7.3.0" [tool.poetry.group.examples] optional = true diff --git a/src/test_prometheus_url.py b/src/test_prometheus_url.py index d06991e..dd45c40 100644 --- a/src/test_prometheus_url.py +++ b/src/test_prometheus_url.py @@ -4,10 +4,13 @@ # Defaults to localhost:9090 class TestPrometheusUrlGeneratorDefault(unittest.TestCase): + """Test the prometheus url generator with default values.""" + def setUp(self): self.generator = Generator("myFunction", "myModule") def test_create_prometheus_url(self): + """Test that the prometheus url is created correctly.""" url = self.generator.create_prometheus_url("myQuery") self.assertTrue( url.startswith("http://localhost:9090/graph?g0.expr=") @@ -17,18 +20,17 @@ def test_create_prometheus_url(self): # Creates proper urls when given a custom base URL class TestPrometheusUrlGeneratorCustomUrl(unittest.TestCase): + """Test the prometheus url generator with a custom base URL.""" + def setUp(self): self.generator = Generator( "myFunction", "myModule", base_url="http://localhost:9091" ) def test_create_prometheus_url(self): + """Test that the prometheus url is created correctly.""" url = self.generator.create_prometheus_url("myQuery") self.assertTrue( url.startswith("http://localhost:9091/graph?g0.expr=") ) # Make sure the base URL is correct self.assertIn("myQuery", url) # Make sure the query is included in the URL - - -if __name__ == "__main__": - unittest.main()