File: testcomparator.py

package info (click to toggle)
python-param 2.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,048 kB
  • sloc: python: 17,980; makefile: 3
file content (44 lines) | stat: -rw-r--r-- 906 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import datetime
import decimal

import pytest

from param.parameterized import Comparator

try:
    import numpy as np
except ImportError:
    np = None
try:
    import pandas as pd
except ImportError:
    pd = None

_now = datetime.datetime.now()
_today = datetime.date.today()

_supported = {
    'str': 'test',
    'float': 1.2,
    'int': 1,
    'decimal': decimal.Decimal(1) / decimal.Decimal(7),
    'bytes': (1024).to_bytes(2, byteorder='big'),
    'None': None,
    'list': [1, 2],
    'tuple': (1, 2),
    'set': {1, 2},
    'dict': {'a': 1, 'b': 2},
    'date': _today,
    'datetime': _now,
}

if np:
    _supported.update({
        'np.datetime64': np.datetime64(_now),
    })
if pd:
    _supported.update({'pd.Timestamp': pd.Timestamp(_now)})

@pytest.mark.parametrize('obj', _supported.values(), ids=_supported.keys())
def test_comparator_equal(obj):
    assert Comparator.is_equal(obj, obj)