"""
Test get_obj_value set_obj_value has_obj_value
"""
import pytest
from dayu_widgets import utils


class _HasNameAgeObject(object):
    def __init__(self, name, age):
        super(_HasNameAgeObject, self).__init__()
        self.name = name
        self.age = age


@pytest.mark.parametrize('obj', (
    {'name': 'xiaoming', 'age': 18},
    _HasNameAgeObject('xiaoming', 18)
))
class TestObjValue(object):
    """Test get_obj_value has_obj_value set_obj_value collection."""

    @pytest.mark.parametrize('attr, default, result', (
        ('name', 'hhh', 'xiaoming'),
        ('age', 0, 18),
        ('score', 0, 0)
    ))
    def test_get_obj_value(self, obj, attr, default, result):
        """Test get_obj_value with dict/object as arg. """
        assert utils.get_obj_value(obj, attr, default) == result

    @pytest.mark.parametrize('attr, result', (
        ('name', True),
        ('age', True),
        ('sex', False),
    ))
    def test_has_obj_value(self, obj, attr, result):
        """Test has_obj_value with dict/object as arg. """
        assert utils.has_obj_value(obj, attr) == result

    @pytest.mark.parametrize('attr, value', (
        ('name', 'xiaohua'),
        ('age', 30),
        ('id', 80),
    ))
    def test_set_obj_value(self, obj, attr, value):
        """Test set_obj_value with dict/object as arg. """
        utils.set_obj_value(obj, attr, value)
        assert utils.get_obj_value(obj, attr) == value

[((22, 5, 26, 6), 'pytest.mark.parametrize', 'pytest.mark.parametrize', ({(22, 29, 22, 52): '"""attr, default, result"""', (22, 54, 26, 5): "(('name', 'hhh', 'xiaoming'), ('age', 0, 18), ('score', 0, 0))"}, {}), "('attr, default, result', (('name', 'hhh',\n    'xiaoming'), ('age', 0, 18), ('score', 0, 0)))", False, 'import pytest\n'), ((31, 5, 35, 6), 'pytest.mark.parametrize', 'pytest.mark.parametrize', ({(31, 29, 31, 43): '"""attr, result"""', (31, 45, 35, 5): "(('name', True), ('age', True), ('sex', False))"}, {}), "('attr, result', (('name', True), ('age', True), (\n    'sex', False)))", False, 'import pytest\n'), ((40, 5, 44, 6), 'pytest.mark.parametrize', 'pytest.mark.parametrize', ({(40, 29, 40, 42): '"""attr, value"""', (40, 44, 44, 5): "(('name', 'xiaohua'), ('age', 30), ('id', 80))"}, {}), "('attr, value', (('name', 'xiaohua'), ('age', 30), (\n    'id', 80)))", False, 'import pytest\n'), ((47, 8, 47, 45), 'dayu_widgets.utils.set_obj_value', 'utils.set_obj_value', ({(47, 28, 47, 31): 'obj', (47, 33, 47, 37): 'attr', (47, 39, 47, 44): 'value'}, {}), '(obj, attr, value)', False, 'from dayu_widgets import utils\n'), ((29, 15, 29, 54), 'dayu_widgets.utils.get_obj_value', 'utils.get_obj_value', ({(29, 35, 29, 38): 'obj', (29, 40, 29, 44): 'attr', (29, 46, 29, 53): 'default'}, {}), '(obj, attr, default)', False, 'from dayu_widgets import utils\n'), ((38, 15, 38, 45), 'dayu_widgets.utils.has_obj_value', 'utils.has_obj_value', ({(38, 35, 38, 38): 'obj', (38, 40, 38, 44): 'attr'}, {}), '(obj, attr)', False, 'from dayu_widgets import utils\n'), ((48, 15, 48, 45), 'dayu_widgets.utils.get_obj_value', 'utils.get_obj_value', ({(48, 35, 48, 38): 'obj', (48, 40, 48, 44): 'attr'}, {}), '(obj, attr)', False, 'from dayu_widgets import utils\n')]