Skip to main content

No project description provided

Project description

Pydiction: Deep Comparison and Assertion Library

Pydiction is a Python library for deep comparisons and assertions on complex data structures. It provides a flexible and customizable way to compare dictionaries and lists while supporting various comparison scenarios, including nested comparisons and negative tests.

Getting Started

These instructions will help you get started with using Pydiction for comparing data structures in your Python projects.

Prerequisites

Pydiction has the following prerequisites:

  • Python 3.x

Installation

You can install Pydiction using pip:

pip install pydiction

Usage

Simple Usage

Here's a basic example of how to use Pydiction for deep comparisons:

from pydiction import Matcher, Contains

# Create a Matcher instance
matcher = Matcher()

# Define your actual and expected data structures
actual = {"a": 1, "b": 2}
expected = Contains({"a": 1})

# Perform the comparison and handle errors
try:
    matcher.assert_declarative_object(actual, expected)
except AssertionError as e:
    print(f"AssertionError: {e}")

Advanced

from pydiction import ANY_NOT_NONE, Matcher, ANY, Contains, DoesntContains, Expect, ExpectNot

matcher = Matcher()
actual = {

    "name": "John",
    "email": "john@example.com",
    "age": 25,
    "friends": [
        {

            "name": "Alice",
            "email": "alice@example.com",
            "age": 21,
        }
    ],
    "comments": [{ "text": "Great post!"}],
    "likes": [
        {

            "title": "First Post",
            "content": "This is my first post!",

        },
        { "text": "Great post!"},
    ],
}

expected = {
    "name": "John",
    "age": Expect(10).__gt__,
    "comments": DoesntContains([{"text": "not existing post!"}]),
    "email": ExpectNot("gmail.com").__contains__,
    "friends": [
        {
            "age": ANY_NOT_NONE,
            "email": ANY_NOT_NONE,
            "name": "Alice",

        }
    ],
    "likes": Contains(
        [
            {

                "content": "This is my first post!",
                "title": "First Post",

            },
        ]
    ),

}

matcher.assert_declarative_object(actual, expected)

Contributing

If you'd like to contribute to Pydiction or report issues, please follow these guidelines:

  1. Fork the repository on GitHub.
  2. Clone your forked repository to your local machine.
  3. Create a new branch for your feature or bug fix.
  4. Make your changes and commit them with clear and concise commit messages.
  5. Push your changes to your forked repository.
  6. Create a pull request against the main repository.

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

pydiction-0.1.0.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

pydiction-0.1.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file pydiction-0.1.0.tar.gz.

File metadata

  • Download URL: pydiction-0.1.0.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for pydiction-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9f93d7bd2e2a9f9be7e10ead3d9e8ea75ef3257a2c2452f0b2a775dddcd29206
MD5 7e76909fc28dbe94d691095f0556eaaf
BLAKE2b-256 b70c6e8a8040390185f1bf30a579c2e9a98e42dbf379e846c615ba2bffd86bca

See more details on using hashes here.

File details

Details for the file pydiction-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pydiction-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for pydiction-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 58f3679ceff25967ddc3fb9bfb2a5ac5f200d8317fe03021d11083cd75112a3c
MD5 eb0b7428d85eb9db28ac6beb0e6fee83
BLAKE2b-256 3720a6b5a97d17a8845d5a6a54c4d09fefa6d73d20aa1e1b634e95c2e75d09f2

See more details on using hashes here.

Supported by

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