Skip to main content

No project description provided

Project description

# pytest-dictsdiff


## Installation

$ pip install pytest-dictsdiff

## Usage


At your test use `dicts_are_same` fixture and use it to compare two
objects:

```python

def test_dicts(dicts_are_same):
dict1 = {'a': 1, 'b': 2, 'c': {'d': 4, 'e': 5}}
dict2 = {'a': 100, 'f': 2, 'c': {'d': 400, 'g': 5}}
assert dicts_are_same(dict1, dict2)
```

## Todos

- [ ] Use `pprint` instead of `json` when showing objects (currently it would fail
if data would contain any non-json-serializable objects)


## Example

Save following snippet as `dicts.py` and run `pytest dicts.py`.

```python
from collections import OrderedDict


RESULT = OrderedDict({
"cell": "(056)-022-8631",
"dob": {
"age": 44,
"date": "1983-11-04T01:21:14Z"
},
"email": "zeyneb.elfring@example.com",
"gender": "female",
"id": {
"name": "BSN",
"value": "36180866"
},
"location": {
"city": "tholen",
"coordinates": {
"latitude": "46.8823",
"longitude": "175.8856"
},
"postcode": 64504,
"state": "groningen",
"street": "2074 adriaen van ostadelaan",
"timezone": {
"description": "Adelaide, Darwin",
"offset": "+9:30"
}
},
"login": {
"md5": "bafe8cf9d37806a7b13edc218d5ff762",
"password": "ontario",
"salt": "QVBKgEjy",
"sha1": "cacef09ff61072d1c55732963766fa84e919aa7a",
"sha256": "cc86af47aedbdbb1de73ff10484996fe9785c47c0fc191b7c67eaf71e0782300",
"username": "smallgorilla897",
"uuid": "37e30c59-bc79-4172-aac6-e2c640e165fa"
},
"name": {
"first": "zeyneb",
"last": "elfring",
"title": "mrs"
},
"nat": "NL",
"phone": "(209)-143-9697",
"picture": {
"large": "https://randomuser.me/api/portraits/women/37.jpg",
"medium": "https://randomuser.me/api/portraits/med/women/37.jpg",
"thumbnail": "https://randomuser.me/api/portraits/thumb/women/37.jpg"
},
"registered": {
"age": 3,
"date": "2014-12-07T06:54:14Z"
}
})

EXPECTED_DATA = {
"cell": "(056)-022-8631",
"dob": {
"age": 34,
"date": "1953-11-04T01:21:04Z"
},
"email": "zeyneb.elfring@example.com",
"gender": "female",
"id": {
"name": "BSN",
"value": "36180866"
},
"location": {
"city": "Tholen",
"coordinates": {
"latitude": "46.8823",
"longitude": "175.8856"
},
"postcode": 64509,
"state": "groningen",
"street": "2074 adriaen van ostadelaan",
"timezone": {
"description": "Adelaide, Darwin",
"offset": "+9:30"
}
},
"login": {
"md5": "bafe8cf9d37806a7b13edc218d5ff762",
"password": "ontario",
"salt": "QVBKgEjy",
"sha1": "cacef09ff61072d1c55732963766fa84e919aa7a",
"sha256": "cc86af47aedbdbb1de73ff10484996fe9785c47c0fc191b7c67eaf71e0782300",
"username": "smallgorilla897",
"uuid": "37e30c59-bc79-4172-aac6-e2c640e165fa"
},
"name": {
"first": "Zeyneb",
"last": "Elfring",
"title": "mrs"
},
"nat": "NL",
"phone": "(209)-143-9697",
"picture": {
"large": "https://randomuser.me/api/portraits/women/37.jpg",
"medium": "https://randomuser.me/api/portraits/med/women/37.jpg",
"thumbnail": "https://randomuser.me/api/portraits/thumb/women/37.jpg"
},
"registered": {
"age": 3,
"date": "2014-12-07T06:54:14Z"
}
}


def test_compare_dicts(dicts_are_same):
assert dicts_are_same(RESULT, EXPECTED_DATA)

```

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-dictsdiff-0.5.6.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

pytest_dictsdiff-0.5.6-py2.py3-none-any.whl (3.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pytest-dictsdiff-0.5.6.tar.gz.

File metadata

  • Download URL: pytest-dictsdiff-0.5.6.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.6

File hashes

Hashes for pytest-dictsdiff-0.5.6.tar.gz
Algorithm Hash digest
SHA256 3ae48c58f22046c5467454ab9955d38e55a9422d9e802b33b2a49dc504e286ca
MD5 7454191d4a5c29cbb0c905c055f6ee64
BLAKE2b-256 81fa1a04661396d3bf09e89d08a2039481b44c9dd9ca00a547972bb5a0850c0b

See more details on using hashes here.

File details

Details for the file pytest_dictsdiff-0.5.6-py2.py3-none-any.whl.

File metadata

  • Download URL: pytest_dictsdiff-0.5.6-py2.py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for pytest_dictsdiff-0.5.6-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5a3e319d98712c15b1014aab5d261cfffb58516b5131be5f0256b22016d186fe
MD5 5b1e07d17a3cc9d7f56cc3464a8634f5
BLAKE2b-256 09ebf988bb4d896a8af560ac8f81b3afc3730b3b7c85718e645b298b7338c202

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