diff options
Diffstat (limited to 'src/tests')
-rwxr-xr-x | src/tests/pyhbac-test.py | 9 | ||||
-rwxr-xr-x | src/tests/pysss_murmur-test.py | 7 | ||||
-rw-r--r-- | src/tests/python-test.py | 33 |
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") |