"""
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

[((485, 601), 'pytest.mark.parametrize', 'pytest.mark.parametrize', (['"""attr, default, result"""', "(('name', 'hhh', 'xiaoming'), ('age', 0, 18), ('score', 0, 0))"], {}), "('attr, default, result', (('name', 'hhh',\n    'xiaoming'), ('age', 0, 18), ('score', 0, 0)))\n", (508, 601), False, 'import pytest\n'), ((820, 913), 'pytest.mark.parametrize', 'pytest.mark.parametrize', (['"""attr, result"""', "(('name', True), ('age', True), ('sex', False))"], {}), "('attr, result', (('name', True), ('age', True), (\n    'sex', False)))\n", (843, 913), False, 'import pytest\n'), ((1114, 1205), 'pytest.mark.parametrize', 'pytest.mark.parametrize', (['"""attr, value"""', "(('name', 'xiaohua'), ('age', 30), ('id', 80))"], {}), "('attr, value', (('name', 'xiaohua'), ('age', 30), (\n    'id', 80)))\n", (1137, 1205), False, 'import pytest\n'), ((1351, 1388), 'dayu_widgets.utils.set_obj_value', 'utils.set_obj_value', (['obj', 'attr', 'value'], {}), '(obj, attr, value)\n', (1370, 1388), False, 'from dayu_widgets import utils\n'), ((764, 803), 'dayu_widgets.utils.get_obj_value', 'utils.get_obj_value', (['obj', 'attr', 'default'], {}), '(obj, attr, default)\n', (783, 803), False, 'from dayu_widgets import utils\n'), ((1067, 1097), 'dayu_widgets.utils.has_obj_value', 'utils.has_obj_value', (['obj', 'attr'], {}), '(obj, attr)\n', (1086, 1097), False, 'from dayu_widgets import utils\n'), ((1404, 1434), 'dayu_widgets.utils.get_obj_value', 'utils.get_obj_value', (['obj', 'attr'], {}), '(obj, attr)\n', (1423, 1434), False, 'from dayu_widgets import utils\n')]