示例#1
0
 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)
示例#2
0
 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)
示例#3
0
 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)
示例#4
0
 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)
示例#5
0
  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)
示例#6
0
 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)
示例#7
0
 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)])])
示例#8
0
 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)
示例#9
0
 def test_choose_nonetwork(self):
   with testctx() as tmpdir:
     ouimgr = OuiMgr(tmpdir)
     cache = Random.cache()
     ouimgr.save(cache)
     smokechoice(self,ouimgr.choose())
示例#10
0
 def test_ensure_network(self):
   with testctx() as tmpdir:
     ouimgr = OuiMgr(tmpdir)
     ouimgr.ensure()
     smokecache(self,ouimgr.cache)
示例#11
0
 def test_load(self):
   with testctx() as tmpdir:
     ouimgr = OuiMgr(tmpdir)
     self.assertIs(ouimgr.load(),None)
示例#12
0
 def test_fetch_network(self):
   smokecache(self,OuiMgr.fetch())
示例#13
0
 def test_parseoui(self):
   x = OuiMgr.parseoui('00-10-ff')
   expect = 0,16,255
   self.assertEquals(x,expect)
示例#14
0
 def test_serializeoui(self):
   x = OuiMgr.serializeoui((0,16,255))
   expect = '00-10-ff'
   self.assertEquals(x,expect)