def test_serialize(self): name = 'Way Cool, TM, Inc.' cache = [(name,[(1,2,3),(0,16,255)])] with closing(StringIO()) as io: OuiMgr.serialize(io,cache) expect = '%s\t01-02-03 00-10-ff\n' % name self.assertEquals(io.getvalue(),expect)
def test_expire(self): with testctx() as tmpdir: ouimgr = OuiMgr(tmpdir) cache = Random.cache() ouimgr.save(cache) # Let it expire. time.sleep(shortthresh + 1) self.assertIs(ouimgr.load(),None)
def test_save(self): with testctx() as tmpdir: ouimgr = OuiMgr(tmpdir) cache = Random.cache() ouimgr.save(cache) x = ouimgr.load() smokecache(self,x) self.assertEquals(x,cache)
def test_compose_parse(self): for _ in xrange(100): cache = Random.cache() with closing(StringIO()) as io: OuiMgr.serialize(io,cache) io.seek(0) x = OuiMgr.parse(io) self.assertEquals(x,cache)
def test_compose_oui(self): for _ in xrange(1000): oui = Random.oui() x = OuiMgr.parseoui(OuiMgr.serializeoui(oui)) self.assertEquals(oui,x) soui = Random.soui() x = OuiMgr.serializeoui(OuiMgr.parseoui(soui)) self.assertEquals(soui,x)
def test_choose_network(self): with testctx() as tmpdir: ouimgr = OuiMgr(tmpdir) # This will kick off a network fetch. smokechoice(self,ouimgr.choose()) smokecache(self,ouimgr.cache) # Make sure we can load back the parsed result of the network # fetch from disk. ouimgr = OuiMgr(tmpdir) smokechoice(self,ouimgr.choose()) smokecache(self,ouimgr.cache)
def test_parse(self): name = 'Way Cool, TM, Inc.' x = '%s\t01-02-03 00-10-ff\n' % name with closing(StringIO()) as io: io.write(x) io.seek(0) cache = OuiMgr.parse(io) self.assertEquals(cache,[(name,[(1,2,3),(0,16,255)])])
def test_ensure_nonetwork(self): with testctx() as tmpdir: ouimgr = OuiMgr(tmpdir) cache = Random.cache() ouimgr.save(cache) ouimgr = OuiMgr(tmpdir) ouimgr.ensure() smokecache(self,ouimgr.cache)
def test_choose_nonetwork(self): with testctx() as tmpdir: ouimgr = OuiMgr(tmpdir) cache = Random.cache() ouimgr.save(cache) smokechoice(self,ouimgr.choose())
def test_ensure_network(self): with testctx() as tmpdir: ouimgr = OuiMgr(tmpdir) ouimgr.ensure() smokecache(self,ouimgr.cache)
def test_load(self): with testctx() as tmpdir: ouimgr = OuiMgr(tmpdir) self.assertIs(ouimgr.load(),None)
def test_fetch_network(self): smokecache(self,OuiMgr.fetch())
def test_parseoui(self): x = OuiMgr.parseoui('00-10-ff') expect = 0,16,255 self.assertEquals(x,expect)
def test_serializeoui(self): x = OuiMgr.serializeoui((0,16,255)) expect = '00-10-ff' self.assertEquals(x,expect)