| .. | .. |
|---|
| 1 | | -#! /usr/bin/python |
|---|
| 2 | 1 | # SPDX-License-Identifier: GPL-2.0 |
|---|
| 2 | + |
|---|
| 3 | +from __future__ import print_function |
|---|
| 3 | 4 | |
|---|
| 4 | 5 | import os |
|---|
| 5 | 6 | import sys |
|---|
| .. | .. |
|---|
| 8 | 9 | import tempfile |
|---|
| 9 | 10 | import logging |
|---|
| 10 | 11 | import shutil |
|---|
| 11 | | -import ConfigParser |
|---|
| 12 | + |
|---|
| 13 | +try: |
|---|
| 14 | + import configparser |
|---|
| 15 | +except ImportError: |
|---|
| 16 | + import ConfigParser as configparser |
|---|
| 12 | 17 | |
|---|
| 13 | 18 | def data_equal(a, b): |
|---|
| 14 | 19 | # Allow multiple values in assignment separated by '|' |
|---|
| .. | .. |
|---|
| 100 | 105 | def equal(self, other): |
|---|
| 101 | 106 | for t in Event.terms: |
|---|
| 102 | 107 | log.debug(" [%s] %s %s" % (t, self[t], other[t])); |
|---|
| 103 | | - if not self.has_key(t) or not other.has_key(t): |
|---|
| 108 | + if t not in self or t not in other: |
|---|
| 104 | 109 | return False |
|---|
| 105 | 110 | if not data_equal(self[t], other[t]): |
|---|
| 106 | 111 | return False |
|---|
| 107 | 112 | return True |
|---|
| 108 | 113 | |
|---|
| 109 | 114 | def optional(self): |
|---|
| 110 | | - if self.has_key('optional') and self['optional'] == '1': |
|---|
| 115 | + if 'optional' in self and self['optional'] == '1': |
|---|
| 111 | 116 | return True |
|---|
| 112 | 117 | return False |
|---|
| 113 | 118 | |
|---|
| 114 | 119 | def diff(self, other): |
|---|
| 115 | 120 | for t in Event.terms: |
|---|
| 116 | | - if not self.has_key(t) or not other.has_key(t): |
|---|
| 121 | + if t not in self or t not in other: |
|---|
| 117 | 122 | continue |
|---|
| 118 | 123 | if not data_equal(self[t], other[t]): |
|---|
| 119 | 124 | log.warning("expected %s=%s, got %s" % (t, self[t], other[t])) |
|---|
| .. | .. |
|---|
| 134 | 139 | # - expected values assignments |
|---|
| 135 | 140 | class Test(object): |
|---|
| 136 | 141 | def __init__(self, path, options): |
|---|
| 137 | | - parser = ConfigParser.SafeConfigParser() |
|---|
| 142 | + parser = configparser.SafeConfigParser() |
|---|
| 138 | 143 | parser.read(path) |
|---|
| 139 | 144 | |
|---|
| 140 | 145 | log.warning("running '%s'" % path) |
|---|
| .. | .. |
|---|
| 193 | 198 | return True |
|---|
| 194 | 199 | |
|---|
| 195 | 200 | def load_events(self, path, events): |
|---|
| 196 | | - parser_event = ConfigParser.SafeConfigParser() |
|---|
| 201 | + parser_event = configparser.SafeConfigParser() |
|---|
| 197 | 202 | parser_event.read(path) |
|---|
| 198 | 203 | |
|---|
| 199 | 204 | # The event record section header contains 'event' word, |
|---|
| .. | .. |
|---|
| 207 | 212 | # Read parent event if there's any |
|---|
| 208 | 213 | if (':' in section): |
|---|
| 209 | 214 | base = section[section.index(':') + 1:] |
|---|
| 210 | | - parser_base = ConfigParser.SafeConfigParser() |
|---|
| 215 | + parser_base = configparser.SafeConfigParser() |
|---|
| 211 | 216 | parser_base.read(self.test_dir + '/' + base) |
|---|
| 212 | 217 | base_items = parser_base.items('event') |
|---|
| 213 | 218 | |
|---|
| .. | .. |
|---|
| 322 | 327 | for f in glob.glob(options.test_dir + '/' + options.test): |
|---|
| 323 | 328 | try: |
|---|
| 324 | 329 | Test(f, options).run() |
|---|
| 325 | | - except Unsup, obj: |
|---|
| 330 | + except Unsup as obj: |
|---|
| 326 | 331 | log.warning("unsupp %s" % obj.getMsg()) |
|---|
| 327 | | - except Notest, obj: |
|---|
| 332 | + except Notest as obj: |
|---|
| 328 | 333 | log.warning("skipped %s" % obj.getMsg()) |
|---|
| 329 | 334 | |
|---|
| 330 | 335 | def setup_log(verbose): |
|---|
| .. | .. |
|---|
| 363 | 368 | parser.add_option("-p", "--perf", |
|---|
| 364 | 369 | action="store", type="string", dest="perf") |
|---|
| 365 | 370 | parser.add_option("-v", "--verbose", |
|---|
| 366 | | - action="count", dest="verbose") |
|---|
| 371 | + default=0, action="count", dest="verbose") |
|---|
| 367 | 372 | |
|---|
| 368 | 373 | options, args = parser.parse_args() |
|---|
| 369 | 374 | if args: |
|---|
| .. | .. |
|---|
| 373 | 378 | setup_log(options.verbose) |
|---|
| 374 | 379 | |
|---|
| 375 | 380 | if not options.test_dir: |
|---|
| 376 | | - print 'FAILED no -d option specified' |
|---|
| 381 | + print('FAILED no -d option specified') |
|---|
| 377 | 382 | sys.exit(-1) |
|---|
| 378 | 383 | |
|---|
| 379 | 384 | if not options.test: |
|---|
| .. | .. |
|---|
| 382 | 387 | try: |
|---|
| 383 | 388 | run_tests(options) |
|---|
| 384 | 389 | |
|---|
| 385 | | - except Fail, obj: |
|---|
| 386 | | - print "FAILED %s" % obj.getMsg(); |
|---|
| 390 | + except Fail as obj: |
|---|
| 391 | + print("FAILED %s" % obj.getMsg()) |
|---|
| 387 | 392 | sys.exit(-1) |
|---|
| 388 | 393 | |
|---|
| 389 | 394 | sys.exit(0) |
|---|