diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..13b2de2 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,29 @@ +name: main + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + include: + - python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', 'pypy-3.8'] + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install tox + run: pip install tox + + - name: Test + run: tox -e py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ebe41ac --- /dev/null +++ b/.gitignore @@ -0,0 +1,77 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover +.hypothesis/ +.pytest_cache + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py + +# Flask instance folder +instance/ + +# Sphinx documentation +docs/_build/ + +# MkDocs documentation +/site/ + +# PyBuilder +target/ + +# IPython Notebook +.ipynb_checkpoints + +# pyenv +.python-version + + +# Pycharm +.idea \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..04ab415 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ + +The MIT License (MIT) + +Copyright (c) 2024 Sven Hofstede + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..36a2050 --- /dev/null +++ b/README.rst @@ -0,0 +1,76 @@ +============= +pytest-kuunda +============= + +.. image:: https://img.shields.io/pypi/v/pytest-kuunda.svg + :target: https://pypi.org/project/pytest-kuunda + :alt: PyPI version + +.. image:: https://img.shields.io/pypi/pyversions/pytest-kuunda.svg + :target: https://pypi.org/project/pytest-kuunda + :alt: Python versions + +.. image:: https://github.com/svenhofstede/pytest-kuunda/actions/workflows/main.yml/badge.svg + :target: https://github.com/svenhofstede/pytest-kuunda/actions/workflows/main.yml + :alt: See Build Status on GitHub Actions + +pytest plugin to help with test data setup for PySpark tests + +---- + +This `pytest`_ plugin was generated with `Cookiecutter`_ along with `@hackebrot`_'s `cookiecutter-pytest-plugin`_ template. + + +Features +-------- + +* TODO + + +Requirements +------------ + +* TODO + + +Installation +------------ + +You can install "pytest-kuunda" via `pip`_ from `PyPI`_:: + + $ pip install pytest-kuunda + + +Usage +----- + +* TODO + +Contributing +------------ +Contributions are very welcome. Tests can be run with `tox`_, please ensure +the coverage at least stays the same before you submit a pull request. + +License +------- + +Distributed under the terms of the `MIT`_ license, "pytest-kuunda" is free and open source software + + +Issues +------ + +If you encounter any problems, please `file an issue`_ along with a detailed description. + +.. _`Cookiecutter`: https://github.com/audreyr/cookiecutter +.. _`@hackebrot`: https://github.com/hackebrot +.. _`MIT`: https://opensource.org/licenses/MIT +.. _`BSD-3`: https://opensource.org/licenses/BSD-3-Clause +.. _`GNU GPL v3.0`: https://www.gnu.org/licenses/gpl-3.0.txt +.. _`Apache Software License 2.0`: https://www.apache.org/licenses/LICENSE-2.0 +.. _`cookiecutter-pytest-plugin`: https://github.com/pytest-dev/cookiecutter-pytest-plugin +.. _`file an issue`: https://github.com/svenhofstede/pytest-kuunda/issues +.. _`pytest`: https://github.com/pytest-dev/pytest +.. _`tox`: https://tox.readthedocs.io/en/latest/ +.. _`pip`: https://pypi.org/project/pip/ +.. _`PyPI`: https://pypi.org/project diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..2a80b45 --- /dev/null +++ b/docs/index.md @@ -0,0 +1,3 @@ +# Welcome to pytest-kuunda + +pytest plugin to help with test data setup for PySpark tests diff --git a/mkdocs.yml b/mkdocs.yml new file mode 100644 index 0000000..891288b --- /dev/null +++ b/mkdocs.yml @@ -0,0 +1,10 @@ +site_name: pytest-kuunda +site_description: pytest plugin to help with test data setup for PySpark tests +site_author: Sven Hofstede + +theme: readthedocs + +repo_url: https://github.com/svenhofstede/pytest-kuunda + +pages: +- Home: index.md diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..20fec70 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,43 @@ +[build-system] +requires = [ + "setuptools>=61.0.0", +] +build-backend = "setuptools.build_meta" + +[project] +name = "pytest-kuunda" +description = "pytest plugin to help with test data setup for PySpark tests" +version = "0.1.0" +readme = "README.rst" +requires-python = ">=3.8" +authors = [ + { name = "Sven Hofstede", email = "info@svenhofstede.com" }, +] +maintainers = [ + { name = "Sven Hofstede", email = "info@svenhofstede.com" }, +] +license = {file = "LICENSE"} +classifiers = [ + "Framework :: Pytest", + "Development Status :: 4 - Beta", + "Intended Audience :: Developers", + "Topic :: Software Development :: Testing", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: PyPy", + "License :: OSI Approved :: MIT License", +] +dependencies = [ + "pytest>=6.2.0", +] +[project.urls] +Repository = "https://github.com/svenhofstede/pytest-kuunda" +[project.entry-points.pytest11] +django = "pytest_kuunda.plugin" diff --git a/src/pytest_kuunda/__init__.py b/src/pytest_kuunda/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/pytest_kuunda/plugin.py b/src/pytest_kuunda/plugin.py new file mode 100644 index 0000000..42903ec --- /dev/null +++ b/src/pytest_kuunda/plugin.py @@ -0,0 +1,19 @@ +import pytest + + +def pytest_addoption(parser): + group = parser.getgroup('kuunda') + group.addoption( + '--foo', + action='store', + dest='dest_foo', + default='2024', + help='Set the value for the fixture "bar".' + ) + + parser.addini('HELLO', 'Dummy pytest.ini setting') + + +@pytest.fixture +def bar(request): + return request.config.option.dest_foo diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..bc711e5 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1 @@ +pytest_plugins = 'pytester' diff --git a/tests/test_kuunda.py b/tests/test_kuunda.py new file mode 100644 index 0000000..61f9cd0 --- /dev/null +++ b/tests/test_kuunda.py @@ -0,0 +1,61 @@ +def test_bar_fixture(pytester): + """Make sure that pytest accepts our fixture.""" + + # create a temporary pytest test module + pytester.makepyfile(""" + def test_sth(bar): + assert bar == "europython2015" + """) + + # run pytest with the following cmd args + result = pytester.runpytest( + '--foo=europython2015', + '-v' + ) + + # fnmatch_lines does an assertion internally + result.stdout.fnmatch_lines([ + '*::test_sth PASSED*', + ]) + + # make sure that we get a '0' exit code for the testsuite + assert result.ret == 0 + + +def test_help_message(pytester): + result = pytester.runpytest( + '--help', + ) + # fnmatch_lines does an assertion internally + result.stdout.fnmatch_lines([ + 'kuunda:', + '*--foo=DEST_FOO*Set the value for the fixture "bar".', + ]) + + +def test_hello_ini_setting(pytester): + pytester.makeini(""" + [pytest] + HELLO = world + """) + + pytester.makepyfile(""" + import pytest + + @pytest.fixture + def hello(request): + return request.config.getini('HELLO') + + def test_hello_world(hello): + assert hello == 'world' + """) + + result = pytester.runpytest('-v') + + # fnmatch_lines does an assertion internally + result.stdout.fnmatch_lines([ + '*::test_hello_world PASSED*', + ]) + + # make sure that we get a '0' exit code for the testsuite + assert result.ret == 0 diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..76eb17e --- /dev/null +++ b/tox.ini @@ -0,0 +1,12 @@ +# For more information about tox, see https://tox.readthedocs.io/en/latest/ +[tox] +envlist = py38,py39,py310,py311,py312,pypy3,flake8 + +[testenv] +deps = pytest>=6.2.0 +commands = pytest {posargs:tests} + +[testenv:flake8] +skip_install = true +deps = flake8 +commands = flake8 src tests