summaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
authorBohuslav Kabrda <bkabrda@redhat.com>2014-12-12 11:04:40 +0100
committerJakub Hrozek <jhrozek@redhat.com>2015-02-13 18:36:50 +0100
commit9687d7db79e15846de385537a99525d11cae6a15 (patch)
treed8d201e1a95841acd1cd1e8b0b2d92038590b053 /src/tests
parentdc13b1aff629b0271eb6b75a9f3bdb43c9767093 (diff)
downloadsssd-9687d7db79e15846de385537a99525d11cae6a15.tar.gz
sssd-9687d7db79e15846de385537a99525d11cae6a15.tar.xz
sssd-9687d7db79e15846de385537a99525d11cae6a15.zip
Python3 support in SSSD
https://fedorahosted.org/sssd/ticket/2017 (cherry picked from commit 341a00311680a440d7f979f06c34c70d86c9367a)
Diffstat (limited to 'src/tests')
-rwxr-xr-xsrc/tests/pyhbac-test.py9
-rwxr-xr-xsrc/tests/pysss_murmur-test.py7
-rw-r--r--src/tests/python-test.py33
3 files changed, 31 insertions, 18 deletions
diff --git a/src/tests/pyhbac-test.py b/src/tests/pyhbac-test.py
index c4228368a..b7f27026b 100755
--- a/src/tests/pyhbac-test.py
+++ b/src/tests/pyhbac-test.py
@@ -1,15 +1,20 @@
#!/usr/bin/python2
+from __future__ import print_function
import unittest
import sys
import os
import copy
+import sys
srcdir = os.getenv('builddir')
if not srcdir:
srcdir = "."
MODPATH = srcdir + "/.libs" #FIXME - is there a way to get this from libtool?
+if sys.version_info[0] > 2:
+ unicode = str
+
def compat_assertItemsEqual(this, expected_seq, actual_seq, msg=None):
return this.assertEqual(sorted(expected_seq), sorted(actual_seq))
@@ -37,8 +42,8 @@ class PyHbacImport(unittest.TestCase):
" Import the module and assert it comes from tree "
try:
import pyhbac
- except ImportError, e:
- print >>sys.stderr, "Could not load the pyhbac module. Please check if it is compiled"
+ except ImportError as e:
+ print("Could not load the pyhbac module. Please check if it is compiled", file=sys.stderr)
raise e
self.assertEqual(pyhbac.__file__, MODPATH + "/pyhbac.so")
diff --git a/src/tests/pysss_murmur-test.py b/src/tests/pysss_murmur-test.py
index ee0e8b8a0..41cb350f7 100755
--- a/src/tests/pysss_murmur-test.py
+++ b/src/tests/pysss_murmur-test.py
@@ -17,6 +17,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+from __future__ import print_function
import unittest
import sys
@@ -46,6 +47,8 @@ class PySssMurmurImport(unittest.TestCase):
" Make sure we load the in-tree module "
self.system_path = sys.path[:]
sys.path = [ MODPATH ]
+ print (os.getcwd())
+ print(MODPATH)
def tearDown(self):
" Restore the system path "
@@ -55,8 +58,8 @@ class PySssMurmurImport(unittest.TestCase):
" Import the module and assert it comes from tree "
try:
import pysss_murmur
- except ImportError, e:
- print >>sys.stderr, "Could not load the pysss_murmur module. Please check if it is compiled"
+ except ImportError as e:
+ print("Could not load the pysss_murmur module. Please check if it is compiled", file=sys.stderr)
raise e
self.assertEqual(pysss_murmur.__file__, MODPATH + "/pysss_murmur.so")
diff --git a/src/tests/python-test.py b/src/tests/python-test.py
index 81e09c4bb..9967d1b5f 100644
--- a/src/tests/python-test.py
+++ b/src/tests/python-test.py
@@ -24,7 +24,7 @@ import os
import tempfile
import shutil
import unittest
-import commands
+import subprocess
import errno
# module under test
@@ -37,14 +37,17 @@ class LocalTest(unittest.TestCase):
self.local = pysss.local()
def _run_and_check(self, runme):
- (status, output) = commands.getstatusoutput(runme)
+ (status, output) = subprocess.call(runme, shell=True)
self.failUnlessEqual(status, 0, output)
def _get_object_info(self, name, subtree, domain):
search_dn = "dn=name=%s,cn=%s,cn=%s,cn=sysdb" % (name, subtree, domain)
- (status, output) = commands.getstatusoutput("ldbsearch -H %s %s" % (self.local_path,search_dn))
-
- if status: return {}
+ try:
+ output = subprocess.check_call("ldbsearch -H %s %s" % (self.local_path,search_dn),
+ shell=True)
+ output = output.decode('utf-8')
+ except subprocess.CalledProcessError:
+ return {}
kw = {}
for key, value in [ l.split(':') for l in output.split('\n') if ":" in l ]:
@@ -82,9 +85,11 @@ class LocalTest(unittest.TestCase):
def _get_object_membership(self, name, subtree, domain):
search_dn = "dn=name=%s,cn=%s,cn=%s,cn=sysdb" % (name, subtree, domain)
- (status, output) = commands.getstatusoutput("ldbsearch -H %s %s" % (self.local_path,search_dn))
-
- if status:
+ try:
+ output = subprocess.check_call("ldbsearch -H %s %s" % (self.local_path,search_dn),
+ shell=True)
+ output = output.decode('utf-8')
+ except subprocess.CalledProcessError:
return []
members = [ value.strip() for key, value in [ l.split(':') for l in output.split('\n') if ":" in l ] if key == "memberof" ]
@@ -227,7 +232,7 @@ class UseraddTestNegative(LocalTest):
self.local.useradd(self.username)
try:
self.local.useradd(self.username)
- except IOError, e:
+ except IOError as e:
self.assertEquals(e.errno, errno.EEXIST)
else:
self.fail("Was expecting exception")
@@ -240,7 +245,7 @@ class UseraddTestNegative(LocalTest):
self.local.useradd(self.username, uid=1025)
try:
self.local.useradd("testUseraddUIDAlreadyExists2", uid=1025)
- except IOError, e:
+ except IOError as e:
self.assertEquals(e.errno, errno.EEXIST)
else:
self.fail("Was expecting exception")
@@ -270,7 +275,7 @@ class UserdelTest(LocalTest):
self.validate_no_user("testUserdelNegative")
try:
self.local.userdel("testUserdelNegative")
- except IOError, e:
+ except IOError as e:
self.assertEquals(e.errno, errno.ENOENT)
else:
fail("Was expecting exception")
@@ -365,7 +370,7 @@ class GroupaddTestNegative(LocalTest):
self.local.groupadd(self.groupname)
try:
self.local.groupadd(self.groupname)
- except IOError, e:
+ except IOError as e:
self.assertEquals(e.errno, errno.EEXIST)
else:
self.fail("Was expecting exception")
@@ -378,7 +383,7 @@ class GroupaddTestNegative(LocalTest):
self.local.groupadd(self.groupname, gid=1025)
try:
self.local.groupadd("testGroupaddGIDAlreadyExists2", gid=1025)
- except IOError, e:
+ except IOError as e:
self.assertEquals(e.errno, errno.EEXIST)
else:
self.fail("Was expecting exception")
@@ -396,7 +401,7 @@ class GroupdelTest(LocalTest):
self.validate_no_group("testGroupdelNegative")
try:
self.local.groupdel("testGroupdelNegative")
- except IOError, e:
+ except IOError as e:
self.assertEquals(e.errno, errno.ENOENT)
else:
fail("Was expecting exception")