Browse Source

add a few more test cases for cmpbits.. fix a bug from the new

test cases..
ssh-lenovo
John-Mark Gurney 5 years ago
parent
commit
436a647de2
1 changed files with 19 additions and 5 deletions
  1. +19
    -5
      vlanmang.py

+ 19
- 5
vlanmang.py View File

@@ -67,7 +67,7 @@ class SwitchConfig(object):
res.update(self._vlanconf[id].get('t', []))

# add in the ignore ports
res.update(self._ignports)
res.update(self.ignports)

# filter out the strings
strports = set(x for x in res if isinstance(x, str))
@@ -95,12 +95,21 @@ def _intstobits(*ints):
return ''.join(r)

def _cmpbits(a, b):
last1a = a.rindex('1')
last1b = b.rindex('1')
try:
last1a = a.rindex('1')
except ValueError:
last1a = -1
a = ''
try:
last1b = b.rindex('1')
except ValueError:
last1b = -1
b = ''

if last1a != -1:
a = a[:last1a]
a = a[:last1a + 1]
if last1b != -1:
b = b[:last1b]
b = b[:last1b + 1]

return a == b

@@ -342,8 +351,13 @@ class _TestMisc(unittest.TestCase):
self.assertTrue(_cmpbits('111000', '111'))
self.assertTrue(_cmpbits('000111000', '000111'))
self.assertTrue(_cmpbits('11', '11'))
self.assertTrue(_cmpbits('0', '000'))
self.assertFalse(_cmpbits('0011', '11'))
self.assertFalse(_cmpbits('11', '0011'))
self.assertFalse(_cmpbits('10', '000'))
self.assertFalse(_cmpbits('0', '1000'))
self.assertFalse(_cmpbits('00010', '000'))
self.assertFalse(_cmpbits('0', '001000'))

def test_pvidegressuntagged(self):
data = {


Loading…
Cancel
Save