Skip to main content

Collection of helper utilities for testing.

Project description

cykooz.testing is collection of helper utilities for testing.

Utilities

Dict

A dict object that can be compared with other dict object without regard to keys that did not presents in the Dict instance.

>>> from cykooz.testing import Dict
>>> d1 = Dict(a=1, b='foo')
>>> d2 = {'a': 1, 'b': 'foo', 'c': True}
>>> d1 == d2
True
>>> d2 == d1
True
>>> d1 != d2
False
>>> d3 = {'a': 1, 'c': True}
>>> d1 == d3
False
>>> d3 == d1
False
>>> d1 != d3
True
>>> Dict({'a': 1})
Dict({'a': 1})

Short alias:

>>> from cykooz.testing import D
>>> {'a': 1, 'b': 'foo'} == D({'a': 1})
True

List

A list object that can be compared with other list object without regard to extra items contains in the other list object.

>>> from cykooz.testing import List
>>> l1 = List([1, 'foo'])
>>> l2 = [1, 'foo', True]
>>> l1 == l2
True
>>> l2 == l1
True
>>> l1 != l2
False
>>> l3 = [1, True]
>>> l1 == l3
False
>>> l3 == l1
False
>>> l1 != l3
True
>>> l1 == [1]
False
>>> List([1, 'foo', True])
List([1, 'foo', True])
>>> List([Dict(), Dict()]) == [{'a': 1}, {'b': 2}]
True

Short alias:

>>> from cykooz.testing import L
>>> [1, 'foo', True] == L([1, 'foo'])
True

AnyValue

Instance of this class is equal to any other values.

>>> from cykooz.testing import AnyValue
>>> v = AnyValue()
>>> v == 1
True
>>> 1 == v
True
>>> v != 1
False
>>> v == {'a': 1, 'b': 'foo'}
True
>>> v == [1, 2, 3, 'b']
True
>>> v == AnyValue()
True
>>> v
<any value>
>>> {v: 1}
Traceback (most recent call last):
...
TypeError: unhashable type: 'AnyValue'
>>> [v, v, v] == [1, 2, 'foo']
True
>>> [v, v, 1] == [1, 2, 'foo']
False
>>> [v, v] == [1, 2, 'foo']
False
>>> {'a': v, 'b': 2} == {'a': 1, 'b': 2}
True

Short alias:

>>> from cykooz.testing import ANY
>>> 1 == ANY
True

RegExpString

Instance of this class is equal to any other values if it is matched to give regexp pattern.

>>> from cykooz.testing import RegExpString
>>> v = RegExpString('first.*')
>>> v == 1
False
>>> 1 == v
False
>>> v != 1
True
>>> v == 'first class'
True
>>> 'first class' == v
True
>>> v != 'first class'
False
>>> v
<RegExpString: first.*>
>>> {v: 1}
Traceback (most recent call last):
...
TypeError: unhashable type: 'RegExpString'
>>> [v, v, v] == [1, 2, 'first class']
False
>>> [v, v, v] == ['first class', 'first bus', 'first time']
True

Short alias:

>>> from cykooz.testing import R
>>> 'first class' == R('first.*')
True

Url

A url object that can be compared with other url objects without regard to the vagaries of encoding, escaping, and ordering of parameters in query strings.

>>> from cykooz.testing import Url
>>> url1 = Url('http://domain.com/container?limit=6&offset=0')
>>> url2 = Url('http://domain.com/container?offset=0&limit=6')
>>> url1 == url2
True
>>> url2 = Url('http://domain.com/container?limit=6')
>>> url1 == url2
False
>>> url1 == 'http://domain.com/container?offset=0&limit=6'
True
>>> 'http://domain.com/container?offset=0&limit=6' == url1
True
>>> {'key': 'http://domain.com/container?offset=0&limit=6'} == {'key': url1}
True

Json

An instance of this class will be equal to any ‘bytes’ or ‘str’ value if object decoded by JSON-decoder from this value is equal to the first argument of this class.

>>> from cykooz.testing import Json
>>> v = Json({'foo': 1, 'bar': 'hello'})
>>> other = '{"bar": "hello", "foo": 1}'
>>> v == other
True
>>> other == v
True
>>> other != v
False
>>> v == 1
False
>>> 1 == v
False
>>> v != 1
True
>>> v == 'not json'
False
>>> 'not json' == v
False
>>> v != 'not json'
True
>>> v
<Json: {'foo': 1, 'bar': 'hello'}>
>>> {v: 1}
Traceback (most recent call last):
...
TypeError: unhashable type: 'Json'
>>> [v, v, v] == [other, 2, 'first class']
False
>>> [v, v, v] == [other, other, other]
True
>>> '"json str"' == Json('json str')
True

Complex example

>>> from cykooz.testing import D, L, R, J, Url, ANY
>>> some_value = {
...     'created': '2020-04-14T12:34:00.002000+00:00',
...     'is_active': True,
...     'items': [
...         {'key': 'a', 'value': 1},
...         {'key': 'b', 'value': 2},
...         {'key': 'c', 'value': 3},
...     ],
...     'source': 'https://domain.com/item?p=0&t=total',
...     'response': '{"status": 200, "body": "OK"}',
...     'size': 1024,
... }
>>> some_value == D({
...     'created': R('^2020-04.*'),
...     'is_active': True,
...     'items': L([
...         {'key': 'a', 'value': 1},
...         D({'value': ANY}),
...     ]),
...     'source': Url('https://domain.com/item?t=total&p=0'),
...     'response': J({'status': 200, 'body': ANY}),
... })
True

CHANGELOG

1.1.2 (2020-04-14)

Bug Fixes

  • Added new helper into __all__.

1.1 (2020-04-14)

Features

  • Added new helper Json.

1.0.3 (2020-03-20)

Bug Fixes

  • Fixed namespace declaration.

1.0.1 (2019-07-12)

Bug Fixes

  • Fixed “Development Status” of package.

1.0 (2019-07-12)

Features

  • Initial release.

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

cykooz.testing-1.1.2.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

cykooz.testing-1.1.2-py2.py3-none-any.whl (6.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file cykooz.testing-1.1.2.tar.gz.

File metadata

  • Download URL: cykooz.testing-1.1.2.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.0

File hashes

Hashes for cykooz.testing-1.1.2.tar.gz
Algorithm Hash digest
SHA256 5908d3db68824eed67dc58b20104c66b85883c3faf276eca5c3920b6d143c41e
MD5 e8d32a1144ad32e607c7a5256e867bbc
BLAKE2b-256 35c7c125b883bddb21fdaba4e5bfe1b4b3dc702a2b6643558c471e10072a1f95

See more details on using hashes here.

File details

Details for the file cykooz.testing-1.1.2-py2.py3-none-any.whl.

File metadata

  • Download URL: cykooz.testing-1.1.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.0

File hashes

Hashes for cykooz.testing-1.1.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 bc15d8076440e02987b4324b27606cd97bc1cadcdafd054a566acc787b709d32
MD5 9074d6c3b2b93ec8a3c9ad3f2dc181f8
BLAKE2b-256 ce15447df2ef24221b8e1d91a294740bd1c4dad95d23fef23d0620b65ef4fe8c

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