Skip to content
Snippets Groups Projects
Commit 55d530e4 authored by Bert Palm's avatar Bert Palm 🎇
Browse files

structured tests

parent 9cc3a151
No related branches found
No related tags found
1 merge request!2Develop
from test.test_setup import *
def test__len__(datetime_series, maxlen=10):
dios = DictOfSeries()
assert len(dios) == 0
for i in range(maxlen):
dios[f'c{i}'] = datetime_series.copy()
assert len(dios) == i + 1
for i in reversed(range(maxlen)):
assert len(dios) == i + 1
del dios[f'c{i}']
assert len(dios) == 0
from test.test_setup import *
def test_copy_copy_empty(getDtDiosAligned):
dios = getDtDiosAligned.copy()
shallow = dios.copy(deep=False)
deep = dios.copy(deep=True)
empty = dios.copy_empty()
assert dios is not shallow
assert dios is not deep
assert dios is not empty
assert dios.itype == shallow.itype
assert dios.itype == deep.itype
assert dios.itype == empty.itype
for i in dios:
assert dios[i].index is shallow[i].index
assert dios[i].index is not deep[i].index
dios[i][0] = 999999
assert dios[i][0] == shallow[i][0]
assert dios[i][0] != deep[i][0]
@pytest.mark.parametrize('left', diosFromMatr(DATA_UNALIGNED))
@pytest.mark.parametrize('op', OPCOMP)
def test_all(left, op):
# we use comp ops just to get some noise in the data
a = left
ser = (op(a, a)).all()
assert isinstance(ser, pd.Series)
res = [e for e in ser]
exp = [op(a[col], a[col]) for col in a]
for i in range(len(res)):
assert isinstance(exp[i], pd.Series)
assert (res[i] == exp[i]).all()
#!/usr/bin/env python
import pytest
from dios import *
from dios.lib import _OP1_MAP, _OP2_DIV_MAP, _OP2_ARITH_MAP, _OP2_BOOL_MAP, _OP2_COMP_MAP
from test.test_setup import *
import pandas as pd
import numpy as np
from copy import deepcopy
from pandas.tests.series.conftest import datetime_series
__author__ = "Bert Palm"
__email__ = "bert.palm@ufz.de"
__copyright__ = "Copyright 2018, Helmholtz-Centrum für Umweltforschung GmbH - UFC"
def get_dios(ser, i):
dios = DictOfSeries()
for i in range(i):
dios[f'c{i}'] = ser.copy() * (i + 1) // 2
return dios
O = [[0, 0, 0], [0, 0, 0]]
I = [[1, 1, 1], [1, 1, 1]]
A = [[1, 2, 3], [4, 5, 6]]
B = [[0, 2, 2], [5, 5, 5]]
C = [[3, 2, 0], [1, 0, 3]]
D = [[6, 5, 4], [3, 2, 1]]
DATA_ALIGNED = [O, I, A, B, C, D]
# outer lists could have differnet length, but this would
# make the checks to complicated
EEE = [[], [], []]
O = [[0, 0], [0, 0, 0], [0, 0, 0, 0]]
I = [[1, 1, 1], [1, 1, 1], [1]]
A = [[1], [2, 3], [4, 5, 6]]
B = [[0, 2, 2], [5], [5, 5]]
C = [[3, 2, 0], [1, 0, 3], [0, 0, 0]]
D = [[6], [2], [9]]
DATA_UNALIGNED = [O, I, A, B, C, D, EEE]
# only use if a single matrix is used
ALL = DATA_ALIGNED + DATA_UNALIGNED
OPCOMP = list(_OP2_COMP_MAP)
OPNOCOMP = list(_OP2_ARITH_MAP) + list(_OP2_BOOL_MAP) + list(_OP2_DIV_MAP)
OP2 = OPCOMP + OPNOCOMP
OP1 = list(_OP1_MAP)
def _diosmatr(mlist):
l = []
for m in mlist:
m = np.array(m)
l.append(DictOfSeries(m.copy()))
return tuple(l)
@pytest.fixture()
def dictofseries(datetime_series):
return get_dios(datetime_series, 5)
def test_len__len__(datetime_series, maxlen=10):
dios = DictOfSeries()
assert len(dios) == 0
for i in range(maxlen):
dios[f'c{i}'] = datetime_series.copy()
assert len(dios) == i + 1
for i in reversed(range(maxlen)):
assert len(dios) == i + 1
del dios[f'c{i}']
assert len(dios) == 0
def test_copy_copy_empty__copy__(dictofseries):
dios = dictofseries.copy()
shallow = dios.copy(deep=False)
deep = dios.copy(deep=True)
empty = dios.copy_empty()
assert dios is not shallow
assert dios is not deep
assert dios is not empty
assert dios.itype == shallow.itype
assert dios.itype == deep.itype
assert dios.itype == empty.itype
for i in dios:
assert dios[i].index is shallow[i].index
assert dios[i].index is not deep[i].index
dios[i][0] = 999999
assert dios[i][0] == shallow[i][0]
assert dios[i][0] != deep[i][0]
@pytest.mark.parametrize('left', _diosmatr(DATA_ALIGNED))
@pytest.mark.parametrize('right', _diosmatr(DATA_ALIGNED))
@pytest.mark.parametrize('left', diosFromMatr(DATA_ALIGNED))
@pytest.mark.parametrize('right', diosFromMatr(DATA_ALIGNED))
def test__eq__(left, right):
a, b = left, right
_test = a == b
......@@ -112,22 +21,8 @@ def test__eq__(left, right):
assert res == exp
@pytest.mark.parametrize('left', _diosmatr(DATA_UNALIGNED))
@pytest.mark.parametrize('op', OPCOMP)
def test_all(left, op):
# we use comp ops just to get some noise in the data
a = left
ser = (op(a, a)).all()
assert isinstance(ser, pd.Series)
res = [e for e in ser]
exp = [op(a[col], a[col]) for col in a]
for i in range(len(res)):
assert isinstance(exp[i], pd.Series)
assert (res[i] == exp[i]).all()
@pytest.mark.parametrize('left', _diosmatr(DATA_ALIGNED))
@pytest.mark.parametrize('right', _diosmatr(DATA_ALIGNED))
@pytest.mark.parametrize('left', diosFromMatr(DATA_ALIGNED))
@pytest.mark.parametrize('right', diosFromMatr(DATA_ALIGNED))
@pytest.mark.parametrize('op', OP2)
def test__op2__aligningops(left, right, op):
a, b = left, right
......@@ -143,8 +38,8 @@ def test__op2__aligningops(left, right, op):
assert res == exp
@pytest.mark.parametrize('left', _diosmatr(DATA_UNALIGNED))
@pytest.mark.parametrize('right', _diosmatr(DATA_UNALIGNED))
@pytest.mark.parametrize('left', diosFromMatr(DATA_UNALIGNED))
@pytest.mark.parametrize('right', diosFromMatr(DATA_UNALIGNED))
@pytest.mark.parametrize('op', OPNOCOMP)
def test__op2__UNaligningops(left, right, op):
try:
......@@ -163,7 +58,7 @@ def test__op2__UNaligningops(left, right, op):
pytest.skip('ZeroDivisionError')
@pytest.mark.parametrize('data', _diosmatr(ALL))
@pytest.mark.parametrize('data', diosFromMatr(ALL))
@pytest.mark.parametrize('op', OP1)
def test__op1__(data, op):
test = op(data)
......
import pytest
from dios import *
from dios.lib import _OP1_MAP, _OP2_DIV_MAP, _OP2_ARITH_MAP, _OP2_BOOL_MAP, _OP2_COMP_MAP
import pandas as pd
import numpy as np
from copy import deepcopy
from pandas.tests.series.conftest import datetime_series
O = [[0, 0, 0], [0, 0, 0]]
I = [[1, 1, 1], [1, 1, 1]]
A = [[1, 2, 3], [4, 5, 6]]
B = [[0, 2, 2], [5, 5, 5]]
C = [[3, 2, 0], [1, 0, 3]]
D = [[6, 5, 4], [3, 2, 1]]
DATA_ALIGNED = [O, I, A, B, C, D]
# outer lists could have differnet length, but this would
# make the checks to complicated
EEE = [[], [], []]
O = [[0, 0], [0, 0, 0], [0, 0, 0, 0]]
I = [[1, 1, 1], [1, 1, 1], [1]]
A = [[1], [2, 3], [4, 5, 6]]
B = [[0, 2, 2], [5], [5, 5]]
C = [[3, 2, 0], [1, 0, 3], [0, 0, 0]]
D = [[6], [2], [9]]
DATA_UNALIGNED = [O, I, A, B, C, D, EEE]
# only use if a single matrix is used
ALL = DATA_ALIGNED + DATA_UNALIGNED
OPCOMP = list(_OP2_COMP_MAP)
OPNOCOMP = list(_OP2_ARITH_MAP) + list(_OP2_BOOL_MAP) + list(_OP2_DIV_MAP)
OP2 = OPCOMP + OPNOCOMP
OP1 = list(_OP1_MAP)
def diosFromMatr(mlist):
l = []
for m in mlist:
m = np.array(m)
l.append(DictOfSeries(m.copy()))
return tuple(l)
def _get_dios(ser, i):
dios = DictOfSeries()
for i in range(i):
dios[f'c{i}'] = ser.copy() * (i + 1) // 2
return dios
@pytest.fixture()
def getDtDiosAligned(datetime_series):
return _get_dios(datetime_series, 5)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment