Skip to content

Commit

Permalink
SetupTest should run at version of python currently installed (resp. …
Browse files Browse the repository at this point in the history
…active one), skip if started with another version.
  • Loading branch information
sebres committed Jul 22, 2015
1 parent 328e904 commit a14bc85
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions fail2ban/tests/misctestcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ def testFormatExceptionConvertArgs(self):
self.assertEqual(args, "('Very bad', None)")


def _getSysPythonVersion():
import subprocess, locale
sysVerCmd = "python -c 'import sys; print(tuple(sys.version_info))'"
if sys.version_info >= (2,7):
sysVer = subprocess.check_output(sysVerCmd, shell=True)
else:
sysVer = subprocess.Popen(sysVerCmd, shell=True, stdout=subprocess.PIPE).stdout.read()
if sys.version_info >= (3,):
sysVer = sysVer.decode(locale.getpreferredencoding(), 'replace')
return str(sysVer).rstrip()

class SetupTest(unittest.TestCase):

def setUp(self):
Expand All @@ -66,6 +77,12 @@ def setUp(self):
raise unittest.SkipTest(
"Seems to be running not out of source distribution"
" -- cannot locate setup.py")
# compare current version of python installed resp. active one:
sysVer = _getSysPythonVersion()
if sysVer != str(tuple(sys.version_info)):
raise unittest.SkipTest(
"Seems to be running with python distribution %s"
" -- install can be tested only with system distribution %s" % (str(tuple(sys.version_info)), sysVer))

def testSetupInstallRoot(self):
if not self.setup:
Expand Down

0 comments on commit a14bc85

Please sign in to comment.