Skip to content

Commit

Permalink
BF(OSX): apparently exceptions could not be compared for identity, us…
Browse files Browse the repository at this point in the history
…e repr
  • Loading branch information
yarikoptic committed Mar 25, 2015
1 parent d28880f commit eb05cd7
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions fail2ban/tests/servertestcase.py
Expand Up @@ -71,19 +71,24 @@ def tearDown(self):
"""Call after every test case."""
self.server.quit()

def setGetTest(self, cmd, inValue, outValue=None, outCode=0, jail=None):
def setGetTest(self, cmd, inValue, outValue=None, outCode=0, jail=None, repr_=False):
setCmd = ["set", cmd, inValue]
getCmd = ["get", cmd]
if jail is not None:
setCmd.insert(1, jail)
getCmd.insert(1, jail)

if outValue is None:
outValue = inValue

self.assertEqual(self.transm.proceed(setCmd), (outCode, outValue))
def v(x):
"""Prepare value for comparison"""
return (repr(x) if repr_ else x)

self.assertEqual(v(self.transm.proceed(setCmd)), v((outCode, outValue)))
if not outCode:
# if we expected to get it set without problem, check new value
self.assertEqual(self.transm.proceed(getCmd), (0, outValue))
self.assertEqual(v(self.transm.proceed(getCmd)), v((0, outValue)))

def setGetTestNOK(self, cmd, inValue, jail=None):
setCmd = ["set", cmd, inValue]
Expand Down Expand Up @@ -794,8 +799,11 @@ def testSyslogSocketNOK(self):
**{True: {}, # should work on Linux
False: dict( # expect to fail otherwise
outCode=1,
outValue=Exception('Failed to change log target'))}
[platform.system() in ('Linux',)])
outValue=Exception('Failed to change log target'),
repr_=True # Exceptions are not comparable apparently
)
}[platform.system() in ('Linux',)]
)

def testLogLevel(self):
self.setGetTest("loglevel", "HEAVYDEBUG")
Expand Down

0 comments on commit eb05cd7

Please sign in to comment.