add freq
[dumbwifi.git] / test / test_sdictlist.py
blobbd94a64b0a286a2f44782958574091be7c52e593
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, sdictlist
14 class TestSdictList(unittest.TestCase):
16 def setUp(self):
17 self.network1 = sdict()
18 self.network1.essid = "linksys"
19 self.network1.bssid = "11:22:33:44:55:66"
20 self.network1.priority = 75
22 self.network2 = sdict()
23 self.network2.essid = "NETGEAR"
25 self.network3 = sdict()
26 self.network3.essid = "Cisco"
27 self.network3.priority = 60
29 self.lst = sdictlist(sort_key="priority")
30 self.lst.append(self.network1)
31 self.lst.append(self.network2)
32 self.lst.append(self.network3)
34 def test_init(self):
35 dl = sdictlist(init_list=[self.network1, self.network2])
36 self.assert_(len(dl) == 2)
38 def test_ordering(self):
39 self.assert_(self.lst.get_top().essid == "linksys")
41 def test_sort(self):
42 s = self.lst.sort(sort_key="bssid")
43 self.assert_(s.get_top().essid == "linksys")
45 def test_merge(self):
46 network4 = sdict()
47 network4.essid = "Sitecom"
49 network5 = sdict()
50 network5.essid = "Cisco"
51 network5.priority = 90
53 dl = sdictlist(init_list=[network4, network5])
54 dl = self.lst.merge(dl, "essid")
56 self.assert_(len(dl) == 4)
57 self.assert_(dl.get_top().essid == "Cisco")
60 def run(verbosity=1):
61 suite = unittest.makeSuite(TestSdictList)
62 unittest.TextTestRunner(verbosity=verbosity).run(suite)
64 if __name__ == "__main__":
65 run()