Passed
Push — main ( da19e4...14c1e8 )
by Eran
01:21
created

test_tools.test_import_from_string()   A

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
import dataclasses
2
3
import graphinate.tools.mutators
4
import pytest
5
6
7
@dataclasses.dataclass
8
class Data:
9
    a: int
10
    b: str
11
12
13
data = Data(1, 'alpha')
14
15
dictify_cases = [
16
    ([0.5, 0.5, 0.5], [0.5, 0.5, 0.5]),
17
    ({'a': 1, 'b': 2}, {'a': 1, 'b': 2}),
18
    ((1, 2, 3, 4, 'a'), [1, 2, 3, 4, 'a']),
19
    (data, {'a': 1, 'b': 'alpha'})
20
]
21
22
23
@pytest.mark.parametrize(('case', 'expected'), dictify_cases)
24
def test_dictify(case, expected):
25
    actual = graphinate.tools.mutators.dictify(case)
26
    assert actual == expected
27
28
29
dictify_value_as_str_cases = [
30
    ([0.5, 0.5, 0.5], ['0.5', '0.5', '0.5']),
31
    ({'a': 1, 'b': 2}, {'a': '1', 'b': '2'}),
32
    ((1, 2, 3, 4, 'a'), ['1', '2', '3', '4', 'a']),
33
    (data, {'a': '1', 'b': 'alpha'})
34
]
35
36
37
@pytest.mark.parametrize(('case', 'expected'), dictify_value_as_str_cases)
38
def test_dictify__value_to_str(case, expected):
39
    actual = graphinate.tools.mutators.dictify(case, value_converter=str)
40
    assert actual == expected
41