pytest-aoc


Namepytest-aoc JSON
Version 1.23.4 PyPI version JSON
download
home_page
SummaryDownloads puzzle inputs for Advent of Code and synthesizes PyTest fixtures
upload_time2023-12-02 11:54:23
maintainer
docs_urlNone
author
requires_python>=3.8
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pytest-aoc

This pytest plugin downloads puzzle inputs for [Advent of Code][] and
synthesizes fixtures that you can use in your tests.

[![PyPI](https://img.shields.io/pypi/v/pytest-aoc)][pypi]
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pytest-aoc)][pypi]
[![PyPI - Implementation](https://img.shields.io/pypi/implementation/pytest-aoc)][pypi]
[![GitLab issues by-label](https://img.shields.io/gitlab/issues/open/j0057-git%2Fpuzzle%2Fpytest-aoc)][issues]
[![Static Badge](https://img.shields.io/badge/%40-report_issue_via_email-blue)][issue-email]
[![PyPI - License](https://img.shields.io/pypi/l/pytest-aoc)][license]

[Advent of Code]: https://adventofcode.com/

[pypi]: https://pypi.org/project/pytest-aoc
[issues]: https://gitlab.com/j0057-git/puzzle/pytest-aoc/-/issues
[issue-email]: mailto:contact-project+j0057-git-puzzle-pytest-aoc-50462969-issue-@incoming.gitlab.com
[license]: ./LICENSE

## Does this DDoS the adventofcode.com website?

This plugin tries pretty hard to not hit the adventofcode.com website unless
absolutely necessary. When the test session starts, the puzzle inputs that
should be available are calculated based on the system clock. For every input
that should be available (after 05:00:00 GMT), if no corresponding text file is
found on disk, it gets downloaded and saved, if the HTTP status code is 200 OK.

The personal downloaded puzzle inputs should be committed to source control, so
that pytest doesn't need to hit the adventofcode.com API to run the tests in
another environment.

New in version 1.22.0: the code also sleeps (2.5 seconds by default) after
hitting the server. This can be disabled if you have leaderboard aspirations,
but really, do you have time to be practising TDD in that case?

## Installing and configuring

Installing is easy: `python -m pip install pytest-aoc`. Next you will need to configure
_two_ things: for which event (year) the plugin should download inputs, and a
valid session cookie. These are normally valid for about a month or so.

To set the year, put it in `setup.cfg`:

    [tool:pytest]
    aoc_year = 2018

Better yet, ditch `setup.cfg` and use `pyproject.toml`:

    [tool.pytest.ini_options]
    aoc_year = 2023

Then, put a valid session ID in a file named `.cookie` and also name this file
in your `.gitignore`.

With these two things in place, when running pytest, this plugin will download
any missing inputs, and generate pytest fixtures that you can use in your test
functions, see 'Using' and 'Fixtures', below.

## Using

With this plugin properly configured, you can write tests like this:

    def test_01a(day01_numbers):
        assert sum(day01_numbers) == 123

Here, the parameter `day01_numbers` is a fixture that contains the numbers on
each line in the file `input/day01.txt`.

## Fixtures

These fixtures are synthesized for each available day. They're not executed
until you ask for them in a test.

fixture             | example                                       | help
--------------------|-----------------------------------------------|---------------------------------------------------------------------------------
`dayNN_text`        | `"eggs"`                                      | The text in the input file, but stripped of any leading and trailing whitespace.
`dayNN_raw`         | `"eggs\n"`                                    | The raw text in the input file.
`dayNN_lines`       | `["spam", "eggs", "albatross"]`               | A list of stripped lines.
`dayNN_numbers`     | `[1, 1, 2, 3, 5, 8]`                          | A list of numbers.
`dayNN_number`      | `5`                                           | A single number.
`dayNN_grid`        | `[["spam", "eggs"], ["ham", "albatross"]]`    | A list of lists, representing a grid of textual values.
`dayNN_number_grid` | `[[8, 1, 6], [3, 5, 7], [4, 9, 2]]`           | A list of lists, representing a grid of numbers.

## Command-line and configuration options

You can pass the options from the command line or set them in setup.cfg. The
command line takes precedence.

command line flag       | config file option    | help
------------------------|-----------------------|------------------------------------------------------------------------------------------------------------------------------------
`--aoc-year`            | `aoc_year`            | The year for which to download puzzle inputs. (Mandatory)
`--aoc-session-id`      | -                     | The session ID to use for requesting puzzle inputs. This one has no equivalent setup.cfg key; that's a security feature. (Optional)
`--aoc-session-file`    | `aoc_session_file`    | The file from which to read the session ID. (Optional; default `.cookie`)
`--aoc-input-dir`       | `aoc_input_dir`       | The directory in which inputs are stored. Will be created if it doesn't exist. (Optional; default `input`)
`--aoc_sleep_time`      | `aoc_sleep_time`      | Time to sleep after downloading puzzle input, set to 0 to skip sleeping. (Optional; default `2.5`)

## Developing / testing

Set environment variables using `. .envrc` or by automatically loading them
using `direnv allow`.

Create a virtualenv named `env` and install an editable version of this package
with all extra development dependencies:

    python -m venv env
    python -m pip install -U -e .[dev,test]

Run tests directly, to test against the current Python, or via tox to test
against multiple Python versions:

    python -m pytest
    python -m tox run

## Releasing

The procedure goes like this:

- Set a git tag to let [setuptools-scm][] derive a version from it
- Use [build][] to package up the sdist and the wheel
- Upload sdist and wheel to Pypi using [twine][]
- Create a release on Gitlab using [gitlab-cli][]

### Tagging the release commit

(Optional) Tag the release version (or it will be a dev release on the next version as
derived by `setuptools-scm`) where `x.y.z` is the version:

    git tag -a x.y.z

...or even use bash history to refer to the third argument (`:3`) of the current command (`!#`):

    git tag -a x.y.z -m !#:3

But: prefer to write the release notes in here, so don't actually use `-m` for
non-rc releases.

Check that the version is actually sane:

    python -m setuptools_scm

### Build the package files

Bake an sdist and a wheel into a clean `dist` directory:

    rm -f dist/*
    python -m build

### Upload to PyPI

Upload the goods to PyPI:

    python -m twine upload dist/*

(I tried the `--sign` option once, got an email from PyPI saying GPG signatures
are unsupported on PyPI, and am now [reconsidering some very recent life
choices][pypi-removing-pgp]. Dammit, I went decades without needing a PGP key,
could I not have continued to do without?)

### Create release on Gitlab

Upload the goods to Gitlab, where again `x.y.z` is the version:

    git push gitlab main --tags
    glab release create x.y.z dist/*.{tar.gz,whl}

[setuptools-scm]: https://pypi.org/project/setuptools-scm/
[build]: https://pypi.org/project/build/
[twine]: https://pypi.org/project/twine/
[gitlab-cli]: https://gitlab.com/gitlab-org/cli
[pypi-removing-pgp]: https://blog.pypi.org/posts/2023-05-23-removing-pgp/

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "pytest-aoc",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "",
    "author": "",
    "author_email": "Joost Molenaar <jjm@j0057.nl>",
    "download_url": "https://files.pythonhosted.org/packages/87/e9/2e4463ef0392a714e15a70f1ba426cbfcdc216b5626ff67145215e3f5d22/pytest-aoc-1.23.4.tar.gz",
    "platform": null,
    "description": "# pytest-aoc\n\nThis pytest plugin downloads puzzle inputs for [Advent of Code][] and\nsynthesizes fixtures that you can use in your tests.\n\n[![PyPI](https://img.shields.io/pypi/v/pytest-aoc)][pypi]\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pytest-aoc)][pypi]\n[![PyPI - Implementation](https://img.shields.io/pypi/implementation/pytest-aoc)][pypi]\n[![GitLab issues by-label](https://img.shields.io/gitlab/issues/open/j0057-git%2Fpuzzle%2Fpytest-aoc)][issues]\n[![Static Badge](https://img.shields.io/badge/%40-report_issue_via_email-blue)][issue-email]\n[![PyPI - License](https://img.shields.io/pypi/l/pytest-aoc)][license]\n\n[Advent of Code]: https://adventofcode.com/\n\n[pypi]: https://pypi.org/project/pytest-aoc\n[issues]: https://gitlab.com/j0057-git/puzzle/pytest-aoc/-/issues\n[issue-email]: mailto:contact-project+j0057-git-puzzle-pytest-aoc-50462969-issue-@incoming.gitlab.com\n[license]: ./LICENSE\n\n## Does this DDoS the adventofcode.com website?\n\nThis plugin tries pretty hard to not hit the adventofcode.com website unless\nabsolutely necessary. When the test session starts, the puzzle inputs that\nshould be available are calculated based on the system clock. For every input\nthat should be available (after 05:00:00 GMT), if no corresponding text file is\nfound on disk, it gets downloaded and saved, if the HTTP status code is 200 OK.\n\nThe personal downloaded puzzle inputs should be committed to source control, so\nthat pytest doesn't need to hit the adventofcode.com API to run the tests in\nanother environment.\n\nNew in version 1.22.0: the code also sleeps (2.5 seconds by default) after\nhitting the server. This can be disabled if you have leaderboard aspirations,\nbut really, do you have time to be practising TDD in that case?\n\n## Installing and configuring\n\nInstalling is easy: `python -m pip install pytest-aoc`. Next you will need to configure\n_two_ things: for which event (year) the plugin should download inputs, and a\nvalid session cookie. These are normally valid for about a month or so.\n\nTo set the year, put it in `setup.cfg`:\n\n    [tool:pytest]\n    aoc_year = 2018\n\nBetter yet, ditch `setup.cfg` and use `pyproject.toml`:\n\n    [tool.pytest.ini_options]\n    aoc_year = 2023\n\nThen, put a valid session ID in a file named `.cookie` and also name this file\nin your `.gitignore`.\n\nWith these two things in place, when running pytest, this plugin will download\nany missing inputs, and generate pytest fixtures that you can use in your test\nfunctions, see 'Using' and 'Fixtures', below.\n\n## Using\n\nWith this plugin properly configured, you can write tests like this:\n\n    def test_01a(day01_numbers):\n        assert sum(day01_numbers) == 123\n\nHere, the parameter `day01_numbers` is a fixture that contains the numbers on\neach line in the file `input/day01.txt`.\n\n## Fixtures\n\nThese fixtures are synthesized for each available day. They're not executed\nuntil you ask for them in a test.\n\nfixture             | example                                       | help\n--------------------|-----------------------------------------------|---------------------------------------------------------------------------------\n`dayNN_text`        | `\"eggs\"`                                      | The text in the input file, but stripped of any leading and trailing whitespace.\n`dayNN_raw`         | `\"eggs\\n\"`                                    | The raw text in the input file.\n`dayNN_lines`       | `[\"spam\", \"eggs\", \"albatross\"]`               | A list of stripped lines.\n`dayNN_numbers`     | `[1, 1, 2, 3, 5, 8]`                          | A list of numbers.\n`dayNN_number`      | `5`                                           | A single number.\n`dayNN_grid`        | `[[\"spam\", \"eggs\"], [\"ham\", \"albatross\"]]`    | A list of lists, representing a grid of textual values.\n`dayNN_number_grid` | `[[8, 1, 6], [3, 5, 7], [4, 9, 2]]`           | A list of lists, representing a grid of numbers.\n\n## Command-line and configuration options\n\nYou can pass the options from the command line or set them in setup.cfg. The\ncommand line takes precedence.\n\ncommand line flag       | config file option    | help\n------------------------|-----------------------|------------------------------------------------------------------------------------------------------------------------------------\n`--aoc-year`            | `aoc_year`            | The year for which to download puzzle inputs. (Mandatory)\n`--aoc-session-id`      | -                     | The session ID to use for requesting puzzle inputs. This one has no equivalent setup.cfg key; that's a security feature. (Optional)\n`--aoc-session-file`    | `aoc_session_file`    | The file from which to read the session ID. (Optional; default `.cookie`)\n`--aoc-input-dir`       | `aoc_input_dir`       | The directory in which inputs are stored. Will be created if it doesn't exist. (Optional; default `input`)\n`--aoc_sleep_time`      | `aoc_sleep_time`      | Time to sleep after downloading puzzle input, set to 0 to skip sleeping. (Optional; default `2.5`)\n\n## Developing / testing\n\nSet environment variables using `. .envrc` or by automatically loading them\nusing `direnv allow`.\n\nCreate a virtualenv named `env` and install an editable version of this package\nwith all extra development dependencies:\n\n    python -m venv env\n    python -m pip install -U -e .[dev,test]\n\nRun tests directly, to test against the current Python, or via tox to test\nagainst multiple Python versions:\n\n    python -m pytest\n    python -m tox run\n\n## Releasing\n\nThe procedure goes like this:\n\n- Set a git tag to let [setuptools-scm][] derive a version from it\n- Use [build][] to package up the sdist and the wheel\n- Upload sdist and wheel to Pypi using [twine][]\n- Create a release on Gitlab using [gitlab-cli][]\n\n### Tagging the release commit\n\n(Optional) Tag the release version (or it will be a dev release on the next version as\nderived by `setuptools-scm`) where `x.y.z` is the version:\n\n    git tag -a x.y.z\n\n...or even use bash history to refer to the third argument (`:3`) of the current command (`!#`):\n\n    git tag -a x.y.z -m !#:3\n\nBut: prefer to write the release notes in here, so don't actually use `-m` for\nnon-rc releases.\n\nCheck that the version is actually sane:\n\n    python -m setuptools_scm\n\n### Build the package files\n\nBake an sdist and a wheel into a clean `dist` directory:\n\n    rm -f dist/*\n    python -m build\n\n### Upload to PyPI\n\nUpload the goods to PyPI:\n\n    python -m twine upload dist/*\n\n(I tried the `--sign` option once, got an email from PyPI saying GPG signatures\nare unsupported on PyPI, and am now [reconsidering some very recent life\nchoices][pypi-removing-pgp]. Dammit, I went decades without needing a PGP key,\ncould I not have continued to do without?)\n\n### Create release on Gitlab\n\nUpload the goods to Gitlab, where again `x.y.z` is the version:\n\n    git push gitlab main --tags\n    glab release create x.y.z dist/*.{tar.gz,whl}\n\n[setuptools-scm]: https://pypi.org/project/setuptools-scm/\n[build]: https://pypi.org/project/build/\n[twine]: https://pypi.org/project/twine/\n[gitlab-cli]: https://gitlab.com/gitlab-org/cli\n[pypi-removing-pgp]: https://blog.pypi.org/posts/2023-05-23-removing-pgp/\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Downloads puzzle inputs for Advent of Code and synthesizes PyTest fixtures",
    "version": "1.23.4",
    "project_urls": {
        "Homepage": "https://gitlab.com/j0057-git/puzzle/pytest-aoc",
        "Source": "https://gitlab.com/j0057-git/puzzle/pytest-aoc",
        "Tracker": "https://gitlab.com/j0057-git/puzzle/pytest-aoc/-/issues"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e5b5fbe67b21f87882037cab7fd2cb834013b2b4f57f90235610962e51f333fb",
                "md5": "e5f404a382b86b6be258ef6b3e742e94",
                "sha256": "2e451d8967dd49dde944d7698ba2737e79778222a9a979c57b70f2f797848b23"
            },
            "downloads": -1,
            "filename": "pytest_aoc-1.23.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e5f404a382b86b6be258ef6b3e742e94",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 7151,
            "upload_time": "2023-12-02T11:54:21",
            "upload_time_iso_8601": "2023-12-02T11:54:21.434274Z",
            "url": "https://files.pythonhosted.org/packages/e5/b5/fbe67b21f87882037cab7fd2cb834013b2b4f57f90235610962e51f333fb/pytest_aoc-1.23.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "87e92e4463ef0392a714e15a70f1ba426cbfcdc216b5626ff67145215e3f5d22",
                "md5": "98c7c9f0dadba3e4d7c6139108153cd5",
                "sha256": "78f5d5a57f9864c9b26c48fc98cd03eae4774c7fbdec5952728b9b53cb62224a"
            },
            "downloads": -1,
            "filename": "pytest-aoc-1.23.4.tar.gz",
            "has_sig": false,
            "md5_digest": "98c7c9f0dadba3e4d7c6139108153cd5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 8272,
            "upload_time": "2023-12-02T11:54:23",
            "upload_time_iso_8601": "2023-12-02T11:54:23.305022Z",
            "url": "https://files.pythonhosted.org/packages/87/e9/2e4463ef0392a714e15a70f1ba426cbfcdc216b5626ff67145215e3f5d22/pytest-aoc-1.23.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-02 11:54:23",
    "github": false,
    "gitlab": true,
    "bitbucket": false,
    "codeberg": false,
    "gitlab_user": "j0057-git",
    "gitlab_project": "puzzle",
    "lcname": "pytest-aoc"
}
        
Elapsed time: 0.15567s