krb5 commit: Fix some broken tests for Python 3

Greg Hudson ghudson at mit.edu
Wed Jul 18 17:19:44 EDT 2018


https://github.com/krb5/krb5/commit/d1fb3551c0dff5c3e6555b31fcbf04ff04d577fe
commit d1fb3551c0dff5c3e6555b31fcbf04ff04d577fe
Author: Robbie Harwood <rharwood at redhat.com>
Date:   Mon Jul 16 16:44:01 2018 -0400

    Fix some broken tests for Python 3
    
    Remove python2 dependencies in .travis.yml and add python3-paste.
    Convert t_daemon.py and jsonwalker.py to python3.  csjon has no
    python3 version, so replace it with python's built-in JSON module.
    
    python3-pyrad isn't available for Trusty, so krad and OTP tests are
    currently not exercised by Travis.
    
    [ghudson at mit.edu: squashed commits; edited commit message]
    
    ticket: 8710

 .travis.yml              |    2 +-
 src/lib/krad/t_daemon.py |    2 +-
 src/tests/jsonwalker.py  |   16 +++++-----------
 3 files changed, 7 insertions(+), 13 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index a7980d7..f093899 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -10,7 +10,7 @@ matrix:
 
 before_install:
   - sudo apt-get update -qq
-  - sudo apt-get install -y bison dejagnu gettext keyutils ldap-utils libldap2-dev libkeyutils-dev libssl-dev python-cjson python-paste python-pyrad slapd tcl-dev tcsh
+  - sudo apt-get install -y bison dejagnu gettext keyutils ldap-utils libldap2-dev libkeyutils-dev libssl-dev python3-paste slapd tcl-dev tcsh
   - mkdir -p cmocka/build
   - cd cmocka
   - wget https://cmocka.org/files/1.1/cmocka-1.1.1.tar.xz
diff --git a/src/lib/krad/t_daemon.py b/src/lib/krad/t_daemon.py
index 7d7a5d0..7668cd7 100755
--- a/src/lib/krad/t_daemon.py
+++ b/src/lib/krad/t_daemon.py
@@ -23,7 +23,7 @@
 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-import StringIO
+from io import StringIO
 import os
 import sys
 import signal
diff --git a/src/tests/jsonwalker.py b/src/tests/jsonwalker.py
index 7a0675e..1880363 100644
--- a/src/tests/jsonwalker.py
+++ b/src/tests/jsonwalker.py
@@ -1,10 +1,5 @@
 import sys
-try:
-    import cjson
-except ImportError:
-    print("Warning: skipping audit log verification because the cjson module" \
-          " is unavailable")
-    sys.exit(0)
+import json
 from collections import defaultdict
 from optparse import OptionParser
 
@@ -72,7 +67,7 @@ class Parser(object):
         """
         Generator that works through dictionary.
         """
-        for a,v in adict.iteritems():
+        for a,v in adict.items():
             if isinstance(v,dict):
                 for (attrpath,u) in self._walk(v):
                     yield (a+'.'+attrpath,u)
@@ -93,17 +88,16 @@ if __name__ == '__main__':
         with open(options.filename, 'r') as f:
             content = list()
             for l in f:
-                content.append(cjson.decode(l.rstrip()))
+                content.append(json.loads(l.rstrip()))
         f.close()
     else:
-        print('Input file in jason format is required')
+        print('Input file in JSON format is required')
         exit()
 
     defaults = None
     if options.defaults is not None:
         with open(options.defaults, 'r') as f:
-            defaults = cjson.decode(f.read())
-        f.close()
+            defaults = json.load(f)
 
     # run test
     p = Parser(defaults)


More information about the cvs-krb5 mailing list