diff options
author | Ilya Etingof <etingof@gmail.com> | 2017-07-19 18:50:20 +0200 |
---|---|---|
committer | Ilya Etingof <etingof@gmail.com> | 2017-07-19 18:50:20 +0200 |
commit | e4376cb0707fa88c20eab44e08a1e4baf6d7aa15 (patch) | |
tree | a66e6e042c5f2ef3044d5b36ec2f8d4248983386 /tests | |
parent | 05d5e723bef82c35969b91dab91e03d0003026a4 (diff) | |
download | pyasn1-git-e4376cb0707fa88c20eab44e08a1e4baf6d7aa15.tar.gz |
NamedValues refactored into a dict-like object
Diffstat (limited to 'tests')
-rw-r--r-- | tests/type/test_namedval.py | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/tests/type/test_namedval.py b/tests/type/test_namedval.py index e52f724..6504b34 100644 --- a/tests/type/test_namedval.py +++ b/tests/type/test_namedval.py @@ -18,12 +18,34 @@ class NamedValuesCaseBase(unittest.TestCase): def setUp(self): self.e = namedval.NamedValues(('off', 0), ('on', 1)) - def testIter(self): - off, on = self.e - assert off == ('off', 0) or on == ('on', 1), 'unpack fails' - - def testRepr(self): - assert eval(repr(self.e), {'NamedValues': namedval.NamedValues}) == self.e, 'repr() fails' + 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__]) |