3 # Author: Martin Matusiak <numerodix@gmail.com>
4 # Licensed under the GNU Public License, version 3.
11 from sdict
import sdict
14 class TestSdict(unittest
.TestCase
):
19 'b': 2, # cast to string
20 'c': "", # the following should not be set
25 def test__init__(self
):
26 self
.assert_(self
.d
.a
== "bear")
27 self
.assert_(self
.d
.b
== "2")
29 def test_setitem(self
):
31 self
.assert_(self
.d
['x'] == "5" and self
.d
.x
== "5")
33 def test_delitem(self
):
35 self
.assert_(self
.d
['a'] == None and self
.d
.a
== None)
40 self
.assert_(len(self
.d
) == 0)
41 self
.assert_(self
.d
.items() == [])
43 def test_fromkeys(self
):
44 d
= self
.d
.fromkeys(['x', 'y'], "boo")
45 self
.assert_(d
.items() == [('y', 'boo'), ('x', 'boo')])
48 self
.assert_(self
.d
.items() == [('a', "bear"), ('b', "2")])
51 self
.assert_(self
.d
.keys() == ['a', 'b'])
55 self
.assert_(self
.d
.a
== None)
57 def test_popitem(self
):
58 items
= self
.d
.items()
60 item
= self
.d
.popitem()
62 self
.assert_(item
in items
)
63 self
.assert_(l1
- 1 == l2
)
65 def test_setdefault(self
):
66 self
.d
.setdefault('x', "new")
67 self
.assert_(self
.d
.x
== "new")
69 def test_values(self
):
70 self
.assert_(self
.d
.values() == ["bear", "2"])
73 def test_setattr(self
):
75 self
.assert_(self
.d
['x'] == "5" and self
.d
.x
== "5")
77 def test_delattr(self
):
78 del(self
.d
.__dict
__['a'])
79 self
.assert_(self
.d
['a'] == None and self
.d
.a
== None)
83 suite
= unittest
.makeSuite(TestSdict
)
84 unittest
.TextTestRunner(verbosity
=verbosity
).run(suite
)
86 if __name__
== "__main__":