LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Jeremy Cline <jeremy@jcline.org>
To: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
	"Herton R . Krzesinski" <herton@redhat.com>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
	Jeremy Cline <jeremy@jcline.org>
Subject: [PATCH 8/8] perf tests: Add Python 3 support to attr.py
Date: Tue, 8 May 2018 21:27:50 +0000	[thread overview]
Message-ID: <0100016341a7413b-a8e15991-fe45-42e9-9209-8143734f0511-000000@email.amazonses.com> (raw)
In-Reply-To: <cover.1525811971.git.jeremy@jcline.org>

Support both Python 2 and Python 3 in attr.py. This should have no
functional change.

Signed-off-by: Jeremy Cline <jeremy@jcline.org>
---
 tools/perf/tests/attr.py | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

diff --git a/tools/perf/tests/attr.py b/tools/perf/tests/attr.py
index ff9b60b99f52..15fbf38450fe 100644
--- a/tools/perf/tests/attr.py
+++ b/tools/perf/tests/attr.py
@@ -1,6 +1,8 @@
 #! /usr/bin/python
 # SPDX-License-Identifier: GPL-2.0
 
+from __future__ import print_function
+
 import os
 import sys
 import glob
@@ -8,7 +10,11 @@ import optparse
 import tempfile
 import logging
 import shutil
-import ConfigParser
+try:
+    import ConfigParser as configparser
+except ImportError:
+    # Python 3 renamed ConfigParser to configparser
+    import configparser
 
 def data_equal(a, b):
     # Allow multiple values in assignment separated by '|'
@@ -100,23 +106,23 @@ class Event(dict):
     def equal(self, other):
         for t in Event.terms:
             log.debug("      [%s] %s %s" % (t, self[t], other[t]));
-            if not self.has_key(t) or not other.has_key(t):
+            if t not in self or t not in other:
                 return False
             if not data_equal(self[t], other[t]):
                 return False
         return True
 
     def optional(self):
-        if self.has_key('optional') and self['optional'] == '1':
+        if 'optional' in self and self['optional'] == '1':
             return True
         return False
 
     def diff(self, other):
         for t in Event.terms:
-            if not self.has_key(t) or not other.has_key(t):
+            if t not in self or t not in other:
                 continue
             if not data_equal(self[t], other[t]):
-		log.warning("expected %s=%s, got %s" % (t, self[t], other[t]))
+                log.warning("expected %s=%s, got %s" % (t, self[t], other[t]))
 
 # Test file description needs to have following sections:
 # [config]
@@ -134,7 +140,7 @@ class Event(dict):
 #   - expected values assignments
 class Test(object):
     def __init__(self, path, options):
-        parser = ConfigParser.SafeConfigParser()
+        parser = configparser.SafeConfigParser()
         parser.read(path)
 
         log.warning("running '%s'" % path)
@@ -193,7 +199,7 @@ class Test(object):
         return True
 
     def load_events(self, path, events):
-        parser_event = ConfigParser.SafeConfigParser()
+        parser_event = configparser.SafeConfigParser()
         parser_event.read(path)
 
         # The event record section header contains 'event' word,
@@ -207,7 +213,7 @@ class Test(object):
             # Read parent event if there's any
             if (':' in section):
                 base = section[section.index(':') + 1:]
-                parser_base = ConfigParser.SafeConfigParser()
+                parser_base = configparser.SafeConfigParser()
                 parser_base.read(self.test_dir + '/' + base)
                 base_items = parser_base.items('event')
 
@@ -322,9 +328,9 @@ def run_tests(options):
     for f in glob.glob(options.test_dir + '/' + options.test):
         try:
             Test(f, options).run()
-        except Unsup, obj:
+        except Unsup as obj:
             log.warning("unsupp  %s" % obj.getMsg())
-        except Notest, obj:
+        except Notest as obj:
             log.warning("skipped %s" % obj.getMsg())
 
 def setup_log(verbose):
@@ -373,7 +379,7 @@ def main():
     setup_log(options.verbose)
 
     if not options.test_dir:
-        print 'FAILED no -d option specified'
+        print('FAILED no -d option specified')
         sys.exit(-1)
 
     if not options.test:
@@ -382,8 +388,8 @@ def main():
     try:
         run_tests(options)
 
-    except Fail, obj:
-        print "FAILED %s" % obj.getMsg();
+    except Fail as obj:
+        print("FAILED %s" % obj.getMsg())
         sys.exit(-1)
 
     sys.exit(0)
-- 
2.17.0

  parent reply	other threads:[~2018-05-08 21:28 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1525811971.git.jeremy@jcline.org>
2018-05-08 21:27 ` [PATCH 1/8] perf tools: Generate a Python script compatible with Python 2 and 3 Jeremy Cline
2018-07-12 13:57   ` [tip:perf/urgent] " tip-bot for Jeremy Cline
2018-05-08 21:27 ` [PATCH 3/8] perf scripts python: Add Python 3 support to SchedGui.py Jeremy Cline
2018-07-12 13:58   ` [tip:perf/urgent] " tip-bot for Jeremy Cline
2018-05-08 21:27 ` [PATCH 2/8] perf scripts python: Add Python 3 support to Core.py Jeremy Cline
2018-07-12 13:58   ` [tip:perf/urgent] " tip-bot for Jeremy Cline
2018-05-08 21:27 ` [PATCH 4/8] perf scripts python: Add Python 3 support to Util.py Jeremy Cline
2018-07-12 13:59   ` [tip:perf/urgent] " tip-bot for Jeremy Cline
2018-05-08 21:27 ` [PATCH 6/8] perf scripts python: Add Python 3 support to sched-migration.py Jeremy Cline
2018-07-12 13:59   ` [tip:perf/urgent] " tip-bot for Jeremy Cline
2018-05-08 21:27 ` [PATCH 5/8] perf scripts python: Add Python 3 support to EventClass.py Jeremy Cline
2018-07-12 14:00   ` [tip:perf/urgent] " tip-bot for Jeremy Cline
2018-05-08 21:27 ` Jeremy Cline [this message]
2018-05-08 21:27 ` [PATCH 7/8] perf scripts python: Add Python 3 support to stat-cpi.py Jeremy Cline

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0100016341a7413b-a8e15991-fe45-42e9-9209-8143734f0511-000000@email.amazonses.com \
    --to=jeremy@jcline.org \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=herton@redhat.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --subject='Re: [PATCH 8/8] perf tests: Add Python 3 support to attr.py' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).