Skip to main content

A library providing dictionary types for interspecting code behavior during test or debugging.

Project description

Testionary

Python 3.10+ License: MIT

A library providing tools to inspect dicionaries during testing.

Installation

Using pip:

pip install testionary

or using uv for project management:

uv add testionary

Usage

Read and Modified attributes

Accessing a value using e.g. the []-operator or dict.get() method will cause the key to be added to TrackingDict.accessed_keys. Setting a value e.g. using assignment together with the []-operator will get tracked using TrackingDict.modified_keys. Here is a small example:

# My library code:
>>> def set_danger(enemy):
...     if enemy["type"] == "Rabbit":
...         enemy["danger"] = 9000


# My test:
>>> from testionary.tracking_dict import TrackingDict
>>> tracked_dict = TrackingDict({"type": "Rabbit", "danger": 42})
>>> set_danger(tracked_dict)
>>> "type" in tracked_dict.accessed_keys
True
>>> "danger" in tracked_dict.modified_keys
True

Tracked Access methods

  • []
  • .get

Tracked Modification methods

  • [] =
  • .update()
  • |=

Iteration

When iterating over dictionary, e.g. when using dictionary comprehension, you might be accessing a few or all of the items. However, in these scenarios it is common to actually interate over all the key-value pairs while filtering on some condition. Instead of attemting to track each access with TrackingDict.accessed_keys, a boolean attribute, TrackingDict.has_been_iterated, is used instead. Here is an example of this being used:

# Libray code
>>> def vals_as_str(_dict):
...    return {k: str(v) for k,v in _dict.items()}

# My test:
>>> from testionary.tracking_dict import TrackingDict

>>> tracked_dict = TrackingDict({"type": "Rabbit", "danger": 42, "hp": 100, "armor": 100})
>>> vals_as_str(tracked_dict)
{'type': 'Rabbit', 'danger': '42', 'hp': '100', 'armor': '100'}
>>> tracked_dict.has_been_iterated
True

Tracked Iteration Methods

  • __iter__() called by iter() and for
  • __contains__(), called by in operator in e.g. if "key" in my_dict
  • .keys()
  • .values()
  • .items()

For .keys(), .values(), and .items(), iteration is assumed following calls to these methods. The returned dict-views are not inspected.

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

testionary-0.2.0.tar.gz (2.6 kB view details)

Uploaded Source

Built Distribution

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

testionary-0.2.0-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file testionary-0.2.0.tar.gz.

File metadata

  • Download URL: testionary-0.2.0.tar.gz
  • Upload date:
  • Size: 2.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.19

File hashes

Hashes for testionary-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f8575565ed69eff6e2590cbdda31e736f99261859712ac592fd24375c26c5356
MD5 935d33906d58bf0704ef10fd66a02d45
BLAKE2b-256 e723cdd65e2aa4c0b1eeab250a8d915913054f913c0b5fd3a5b653dec18980bf

See more details on using hashes here.

File details

Details for the file testionary-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for testionary-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 deb7db711fba6fd879edae780aa6cc5e29bb2f71901fe5f3534d568009c957ef
MD5 60d1b579428a58d5e1207a903bf44009
BLAKE2b-256 211f4f14f85183235099d792114b250980ef1fec60dc4dd2ee7c302d373d3e58

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