#
# This file is part of pyasn1 software.
#
# Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com>
# License: http://snmplabs.com/pyasn1/license.html
#
import sys

try:
    import unittest2 as unittest

except ImportError:
    import unittest

from tests.base import BaseTestCase

from pyasn1.type import namedval


class NamedValuesCaseBase(BaseTestCase):
    def setUp(self):
        BaseTestCase.setUp(self)
        self.e = namedval.NamedValues(('off', 0), ('on', 1))

    def testDict(self):
        assert set(self.e.items()) == set([('off', 0), ('on', 1)])
        assert set(self.e.keys()) == set(['off', 'on'])
        assert set(self.e) == set(['off', 'on'])
        assert set(self.e.values()) == set([0, 1])
        assert 'on' in self.e and 'off' in self.e and 'xxx' not in self.e
        assert 0 in self.e and 1 in self.e and 2 not in self.e

    def testInit(self):
        assert namedval.NamedValues(off=0, on=1) == {'off': 0, 'on': 1}
        assert namedval.NamedValues('off', 'on') == {'off': 0, 'on': 1}
        assert namedval.NamedValues(('c', 0)) == {'c': 0}
        assert namedval.NamedValues('a', 'b', ('c', 0), d=1) == {'c': 0, 'd': 1, 'a': 2, 'b': 3}

    def testLen(self):
        assert len(self.e) == 2
        assert len(namedval.NamedValues()) == 0

    def testAdd(self):
        assert namedval.NamedValues(off=0) + namedval.NamedValues(on=1) == {'off': 0, 'on': 1}

    def testClone(self):
        assert namedval.NamedValues(off=0).clone(('on', 1)) == {'off': 0, 'on': 1}
        assert namedval.NamedValues(off=0).clone(on=1) == {'off': 0, 'on': 1}

    def testStrRepr(self):
        assert str(self.e)
        assert repr(self.e)


suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])

if __name__ == '__main__':
    unittest.TextTestRunner(verbosity=2).run(suite)

[((22, 8, 22, 32), 'tests.base.BaseTestCase.setUp', 'BaseTestCase.setUp', ({(22, 27, 22, 31): 'self'}, {}), '(self)', False, 'from tests.base import BaseTestCase\n'), ((23, 17, 23, 60), 'pyasn1.type.namedval.NamedValues', 'namedval.NamedValues', ({(23, 38, 23, 48): "('off', 0)", (23, 50, 23, 59): "('on', 1)"}, {}), "(('off', 0), ('on', 1))", False, 'from pyasn1.type import namedval\n'), ((55, 8, 55, 29), 'unittest.TestLoader', 'unittest.TestLoader', ({}, {}), '()', False, 'import unittest\n'), ((34, 15, 34, 48), 'pyasn1.type.namedval.NamedValues', 'namedval.NamedValues', (), '', False, 'from pyasn1.type import namedval\n'), ((35, 15, 35, 48), 'pyasn1.type.namedval.NamedValues', 'namedval.NamedValues', ({(35, 36, 35, 41): '"""off"""', (35, 43, 35, 47): '"""on"""'}, {}), "('off', 'on')", False, 'from pyasn1.type import namedval\n'), ((36, 15, 36, 45), 'pyasn1.type.namedval.NamedValues', 'namedval.NamedValues', ({(36, 36, 36, 44): "('c', 0)"}, {}), "(('c', 0))", False, 'from pyasn1.type import namedval\n'), ((37, 15, 37, 60), 'pyasn1.type.namedval.NamedValues', 'namedval.NamedValues', (), '', False, 'from pyasn1.type import namedval\n'), ((58, 4, 58, 40), 'unittest.TextTestRunner', 'unittest.TextTestRunner', (), '', False, 'import unittest\n'), ((41, 19, 41, 41), 'pyasn1.type.namedval.NamedValues', 'namedval.NamedValues', ({}, {}), '()', False, 'from pyasn1.type import namedval\n'), ((44, 15, 44, 42), 'pyasn1.type.namedval.NamedValues', 'namedval.NamedValues', (), '', False, 'from pyasn1.type import namedval\n'), ((44, 45, 44, 71), 'pyasn1.type.namedval.NamedValues', 'namedval.NamedValues', (), '', False, 'from pyasn1.type import namedval\n'), ((47, 15, 47, 42), 'pyasn1.type.namedval.NamedValues', 'namedval.NamedValues', (), '', False, 'from pyasn1.type import namedval\n'), ((48, 15, 48, 42), 'pyasn1.type.namedval.NamedValues', 'namedval.NamedValues', (), '', False, 'from pyasn1.type import namedval\n')]