Skip to main content

Downloads puzzle inputs for Advent of Code and synthesizes PyTest fixtures

Project description

pytest-aoc

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

Installing and configuring

Installing is easy: 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.
  • dayNN_raw: The raw text in the input file.
  • dayNN_lines: A list of lines.
  • dayNN_numbers: A list of numbers.
  • dayNN_number: A single number.
  • dayNN_grid: A list of lists, representing a grid of textual values.
  • dayNN_number_grid: 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.

  • --aoc-year/aoc_year: The year for which to download puzzle inputs. (Mandatory)
  • --aoc-session-id/aoc_session_id: The session ID to use for requesting puzzle inputs. (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)

Project details


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-0.1.dev13.tar.gz (3.3 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-0.1.dev13-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file pytest-aoc-0.1.dev13.tar.gz.

File metadata

  • Download URL: pytest-aoc-0.1.dev13.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for pytest-aoc-0.1.dev13.tar.gz
Algorithm Hash digest
SHA256 fbd0caf2ca234a6a5d0acf888977189a48a56bbfd2515e337f33dd9b5784a541
MD5 221475a9dee93a8d8eb94f98904e93ca
BLAKE2b-256 2242ee0a795fa2e7ab04a7caea1f45b999f290e02cd7d5a1040b8050f113ea83

See more details on using hashes here.

File details

Details for the file pytest_aoc-0.1.dev13-py3-none-any.whl.

File metadata

  • Download URL: pytest_aoc-0.1.dev13-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for pytest_aoc-0.1.dev13-py3-none-any.whl
Algorithm Hash digest
SHA256 713bd27f1a154e492ade9e1f4017e75d921baeada7c34b9baa83217082c436a9
MD5 946f6c255bab51eb8a07796f0aa33d87
BLAKE2b-256 aa7e4fe30225182e5508e486f953e0a3ec043c8b891b5e7b72600640f09be3e9

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