nullpointer
[dumbwifi.git] / test / test_sdict.py
blob43836eeb24c77f09f0eee83e56886d4ca9c5354a
1 #!/usr/bin/env python
3 # Author: Martin Matusiak <numerodix@gmail.com>
4 # Licensed under the GNU Public License, version 3.
6 import sys
7 sys.path.append("..")
9 import unittest
11 from sdict import sdict
14 class TestSdict(unittest.TestCase):
16 def setUp(self):
17 self.d = sdict( {
18 'a': "bear",
19 'b': 2, # cast to string
20 'c': "", # the following should not be set
21 'd': " ",
22 'e': None
23 } )
25 def test__init__(self):
26 self.assert_(self.d.a == "bear")
27 self.assert_(self.d.b == "2")
29 def test_setitem(self):
30 self.d['x'] = "5"
31 self.assert_(self.d['x'] == "5" and self.d.x == "5")
33 def test_delitem(self):
34 del(self.d['a'])
35 self.assert_(self.d['a'] == None and self.d.a == None)
38 def test_clear(self):
39 self.d.clear()
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')])
47 def test_items(self):
48 self.assert_(self.d.items() == [('a', "bear"), ('b', "2")])
50 def test_keys(self):
51 self.assert_(self.d.keys() == ['a', 'b'])
53 def test_pop(self):
54 self.d.pop('a')
55 self.assert_(self.d.a == None)
57 def test_popitem(self):
58 items = self.d.items()
59 l1 = len(self.d)
60 item = self.d.popitem()
61 l2 = len(self.d)
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):
74 self.d.x = "5"
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)
82 def run(verbosity=1):
83 suite = unittest.makeSuite(TestSdict)
84 unittest.TextTestRunner(verbosity=verbosity).run(suite)
86 if __name__ == "__main__":
87 run()