Skip to main content

Sorting of nested dicts and lists

Project description

deep-sorted

Testing and linting codecov GitHub release (latest by date including pre-releases) PyPI

Motivation

When validating parsed JSON objects, schemas and other nested data structures in unit tests, order is typically not important. And yet I often find myself manually sorting the target structures when the internals of the tested function is modified such that order is changed. With this package, both the target and the actual structure can be recursively sorted before comparison.

Installation

Using poetry:

poetry add deep-sorted

Using pipenv:

pipenv install deep-sorted

Using pip:

pip install deep-sorted

Usage

from deep_sorted import deep_sorted
from datetime import datetime

one = {
    "id": 9,
    "name": "Ted Chiang",
    "books": [
        {
            "id": 124,
            "published": datetime(1991, 8, 1, 0, 0),
            "title": "Understand",
            "ratings": (6, 6, 3, 5, 6, 6, 0, 6, 0),
        },
        {
            "id": 125,
            "published": datetime(2019, 5, 7, 0, 0),
            "title": "Exhalation",
        },
    ],
}

two = {
    "books": [
        {
            "published": datetime(2019, 5, 7, 0, 0),
            "title": "Exhalation",
            "id": 125,
        },
        {
            "ratings": (3, 0, 0, 6, 6, 6, 6, 5, 6),
            "id": 124,
            "published": datetime(1991, 8, 1, 0, 0),
            "title": "Understand",
        },
    ],
    "id": 9,
    "name": "Ted Chiang",
}

assert deep_sorted(one) == deep_sorted(two)

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

deep_sorted-0.0.3.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

deep_sorted-0.0.3-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file deep_sorted-0.0.3.tar.gz.

File metadata

  • Download URL: deep_sorted-0.0.3.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.0 CPython/3.10.0 Linux/5.15.0-1034-azure

File hashes

Hashes for deep_sorted-0.0.3.tar.gz
Algorithm Hash digest
SHA256 c962117596b7969e992664c673f7c5e300493b16d59f1b75f834e0f5fc1752bb
MD5 f47e4bac9a9e5dfcf05fd53f1f4b63e1
BLAKE2b-256 33d1f3a50a8bd083e2c0d077065763c18197f322706f21f2e5832ce6f05da1bd

See more details on using hashes here.

File details

Details for the file deep_sorted-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: deep_sorted-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 3.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.0 CPython/3.10.0 Linux/5.15.0-1034-azure

File hashes

Hashes for deep_sorted-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a9058f3fcd5d004a29a472271ee41c2d5168063105d5943c18430b4886263a4c
MD5 4bc9d2fce8a034061fc0479a42dca34f
BLAKE2b-256 5d4b83b0d3e8f9bf8590dd2522e8fd5e8102b851e16d383841ca848a2232f9bc

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