Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

pytest-aoc

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

PyPI - Implementation PyPI - Python Version PyPI GitHub issues PyPI - License

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

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.

  • dayNN_text: The text in the input file, but stripped of any leading and trailing whitespace. ~ "spam"

  • dayNN_raw: The raw text in the input file. ~ "eggs\n"

  • dayNN_lines: A list of stripped lines. ~ ["spam", "eggs", "albatross"]

  • dayNN_numbers: A list of numbers. ~ [1, 1, 2, 3, 5, 8]

  • dayNN_number: A single number. ~ 5

  • dayNN_grid: A list of lists, representing a grid of textual values. ~ [["spam", "eggs"], ["ham", "albatross"]]

  • dayNN_number_grid: A list of lists, representing a grid of numbers. ~ [[8, 1, 6], [3, 5, 7], [4, 9, 2]]

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.

  • --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)

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

Releasing

This package uses setuptools-scm to derive the version from tags in the Git history. I use twine to upload the distribution files to PyPI and github-cli to create releases on GitHub.

The procedure goes like this:

(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

Check that the version is actually sane:

./setup.py --version

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

rm -f dist/*
python -m build

Upload the goods to PyPI:

python -m twine upload dist/*

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

v=$(./setup.py --version)
git push github master --tags
gh release create --prerelease --title $v $v dist/* 

(Leave out the --prerelease flag as necessary.)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-aoc-1.21.1.dev16.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_aoc-1.21.1.dev16-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file pytest-aoc-1.21.1.dev16.tar.gz.

File metadata

  • Download URL: pytest-aoc-1.21.1.dev16.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for pytest-aoc-1.21.1.dev16.tar.gz
Algorithm Hash digest
SHA256 d77bdf98eae6e9844db76484f643ce761748aa024fe343e2f0a1ed8bd15c7a51
MD5 38e5308d9b0ee92e914deff39e3cbdef
BLAKE2b-256 5f59fd5da1302a6600858bbc83cad71182bb9141a376db3a1c782d1aaef17bb8

See more details on using hashes here.

File details

Details for the file pytest_aoc-1.21.1.dev16-py3-none-any.whl.

File metadata

  • Download URL: pytest_aoc-1.21.1.dev16-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for pytest_aoc-1.21.1.dev16-py3-none-any.whl
Algorithm Hash digest
SHA256 877ddc608239fe0ea7de89145701139e615b28a6350a360a28d0c2130e03e673
MD5 01cd3d6070d4fc6fe5f830a4a5cfedf4
BLAKE2b-256 b686724eaa55e1de3a276dd441c442d1ea78c4ecd94cad92253dfe7af8d18bd6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page