Utilities to aid in testing for equality.
Project description
This package is pre-alpha. The API may change.
When comparing structures like this dict:
assert actual == { 'id': 123, 'created': "2017-11-10T23:59:58", 'field1': 1, ... }
This fails because ‘id’ and ‘created’ are different every test run. Fix this using:
assert actual == { 'id': AnyInt(), 'created': AnyTimestamp(datetime.now(), seconds=3), 'field1': 1, ... }
AnyInt
compares equal to any integer. Timestamp
compares equal
to string timestamps that are within the given number of seconds.
Compatibility
Python 3.6 and 2.7.
Known Problems
If timestamps are generated locally, in-process, then it’s easier to patch out datetime.now(). But if this is an end-to-end test that hits other services, that might not be an option. That’s when I find AnyTimestamp useful.
This is all hot off the press, so is doubtless full of mistakes.
Alternatives
This doubtless duplicates better work elsewhere. In particular the package ‘equals’ looks very nice, but it’s missing the central feature of ‘equality’, approximate comparison of string timestamps.
Contact
- Users:
Downloads & documentation: http://pypi.python.org/pypi/equality/
- Contributors:
Souce & issues: https://github.com/tartley/equality/
- The author:
Jonathan Hartley, email: tartley at domain tartley.com, Twitter: @tartley.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file equality-0.0.11.tar.gz
.
File metadata
- Download URL: equality-0.0.11.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00f936342c09c75e0d4cb8f9b849ccd29036e80fcb716c41a54ad058f389f7a4 |
|
MD5 | 422f173cf15044db0eb7f1b9a9546d29 |
|
BLAKE2b-256 | fe86953234b5e42f4f8f0623224927b5c4acb7852e5ff4048365499a43881d10 |