Mock Version: 3.0 Mock Version: 3.0 Mock Version: 3.0 ENTER ['do_with_status'](['bash', '--login', '-c', '/usr/bin/rpmbuild -bs --target noarch --nodeps /builddir/build/SPECS/python-gflags.spec'], chrootPath='/var/lib/mock/dist-oc8-build-34132-10713/root'env={'TERM': 'vt100', 'SHELL': '/bin/bash', 'HOME': '/builddir', 'HOSTNAME': 'mock', 'PATH': '/usr/bin:/bin:/usr/sbin:/sbin', 'PROMPT_COMMAND': 'printf "\\033]0;\\007"', 'PS1': ' \\s-\\v\\$ ', 'LANG': 'C.UTF-8'}shell=Falselogger=timeout=86400uid=991gid=135user='mockbuild'nspawn_args=[]unshare_net=TrueprintOutput=False) Executing command: ['bash', '--login', '-c', '/usr/bin/rpmbuild -bs --target noarch --nodeps /builddir/build/SPECS/python-gflags.spec'] with env {'TERM': 'vt100', 'SHELL': '/bin/bash', 'HOME': '/builddir', 'HOSTNAME': 'mock', 'PATH': '/usr/bin:/bin:/usr/sbin:/sbin', 'PROMPT_COMMAND': 'printf "\\033]0;\\007"', 'PS1': ' \\s-\\v\\$ ', 'LANG': 'C.UTF-8'} and shell False Building target platforms: noarch Building for target noarch Wrote: /builddir/build/SRPMS/python-gflags-2.0-13.oc8.src.rpm Child return code was: 0 ENTER ['do_with_status'](['bash', '--login', '-c', '/usr/bin/rpmbuild -bb --target noarch --nodeps --nocheck /builddir/build/SPECS/python-gflags.spec'], chrootPath='/var/lib/mock/dist-oc8-build-34132-10713/root'env={'TERM': 'vt100', 'SHELL': '/bin/bash', 'HOME': '/builddir', 'HOSTNAME': 'mock', 'PATH': '/usr/bin:/bin:/usr/sbin:/sbin', 'PROMPT_COMMAND': 'printf "\\033]0;\\007"', 'PS1': ' \\s-\\v\\$ ', 'LANG': 'C.UTF-8'}shell=Falselogger=timeout=86400uid=991gid=135user='mockbuild'nspawn_args=[]unshare_net=TrueprintOutput=False) Executing command: ['bash', '--login', '-c', '/usr/bin/rpmbuild -bb --target noarch --nodeps --nocheck /builddir/build/SPECS/python-gflags.spec'] with env {'TERM': 'vt100', 'SHELL': '/bin/bash', 'HOME': '/builddir', 'HOSTNAME': 'mock', 'PATH': '/usr/bin:/bin:/usr/sbin:/sbin', 'PROMPT_COMMAND': 'printf "\\033]0;\\007"', 'PS1': ' \\s-\\v\\$ ', 'LANG': 'C.UTF-8'} and shell False Building target platforms: noarch Building for target noarch Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.1CqUjt + umask 022 + cd /builddir/build/BUILD + cd /builddir/build/BUILD + rm -rf python-gflags-2.0 + /usr/bin/mkdir -p python-gflags-2.0 + cd python-gflags-2.0 + /usr/bin/gzip -dc /builddir/build/SOURCES/python-gflags-2.0.tar.gz + /usr/bin/tar -xof - + STATUS=0 + '[' 0 -ne 0 ']' + /usr/bin/chmod -Rf a+rX,u+w,g-w,o-w . + cp -a python-gflags-2.0 python3 + pathfix.py -i /usr/libexec/platform-python -pn python3/gflags.py python3/gflags2man.py python3/gflags_validators.py python3/setup.py python3/tests/gflags_googletest.py python3/tests/gflags_helpxml_test.py python3/tests/gflags_unittest.py python3/tests/gflags_validators_test.py python3/gflags.py: updating python3/gflags2man.py: updating python3/gflags_validators.py: updating python3/setup.py: updating python3/tests/gflags_googletest.py: updating python3/tests/gflags_helpxml_test.py: updating python3/tests/gflags_unittest.py: updating python3/tests/gflags_validators_test.py: updating + 2to3 --write --nobackup python3 RefactoringTool: Skipping optional fixer: buffer RefactoringTool: Skipping optional fixer: idioms RefactoringTool: Skipping optional fixer: set_literal RefactoringTool: Skipping optional fixer: ws_comma RefactoringTool: Refactored python3/gflags.py RefactoringTool: Refactored python3/gflags2man.py RefactoringTool: No changes to python3/gflags_validators.py RefactoringTool: No changes to python3/setup.py RefactoringTool: Refactored python3/tests/gflags_googletest.py RefactoringTool: Refactored python3/tests/gflags_helpxml_test.py RefactoringTool: Refactored python3/tests/gflags_unittest.py RefactoringTool: Refactored python3/tests/gflags_validators_test.py RefactoringTool: Refactored python3/tests/flags_modules_for_testing/module_bar.py RefactoringTool: No changes to python3/tests/flags_modules_for_testing/module_baz.py RefactoringTool: No changes to python3/tests/flags_modules_for_testing/module_foo.py RefactoringTool: Files that were modified: RefactoringTool: python3/gflags.py RefactoringTool: python3/gflags2man.py RefactoringTool: python3/gflags_validators.py RefactoringTool: python3/setup.py RefactoringTool: python3/tests/gflags_googletest.py RefactoringTool: python3/tests/gflags_helpxml_test.py RefactoringTool: python3/tests/gflags_unittest.py RefactoringTool: python3/tests/gflags_validators_test.py RefactoringTool: python3/tests/flags_modules_for_testing/module_bar.py RefactoringTool: python3/tests/flags_modules_for_testing/module_baz.py RefactoringTool: python3/tests/flags_modules_for_testing/module_foo.py --- python3/gflags.py (original) +++ python3/gflags.py (refactored) @@ -583,7 +583,7 @@ space_prefix_len = len(common_prefix) - len(common_prefix.lstrip()) # If we have a common space prefix, drop it from all lines if space_prefix_len: - for index in xrange(len(text_lines)): + for index in range(len(text_lines)): if text_lines[index]: text_lines[index] = text_lines[index][space_prefix_len:] return '\n'.join(text_first_line + text_lines) @@ -745,7 +745,7 @@ # a parallel thread imports a module while we iterate over # .iteritems() (not nice, but possible), we get a RuntimeError ... # Hence, we use the slightly slower but safer .items(). - for name, module in sys.modules.items(): + for name, module in list(sys.modules.items()): if getattr(module, '__dict__', None) is globals_dict: if name == '__main__': # Pick a more informative name for the main module. @@ -964,7 +964,7 @@ If no such module exists (i.e. no flag with this name exists), we return default. """ - for module, flags in self.FlagsByModuleDict().iteritems(): + for module, flags in self.FlagsByModuleDict().items(): for flag in flags: if flag.name == flagname or flag.short_name == flagname: return module @@ -983,7 +983,7 @@ If no such module exists (i.e. no flag with this name exists), we return default. """ - for module_id, flags in self.FlagsByModuleIdDict().iteritems(): + for module_id, flags in self.FlagsByModuleIdDict().items(): for flag in flags: if flag.name == flagname or flag.short_name == flagname: return module_id @@ -995,7 +995,7 @@ Args: flag_values: registry to copy from """ - for flag_name, flag in flag_values.FlagDict().iteritems(): + for flag_name, flag in flag_values.FlagDict().items(): # Each flags with shortname appears here twice (once under its # normal name, and again with its short name). To prevent # problems (DuplicateFlagError) with double flag registration, we @@ -1068,7 +1068,7 @@ def _AssertAllValidators(self): all_validators = set() - for flag in self.FlagDict().itervalues(): + for flag in self.FlagDict().values(): for validator in flag.validators: all_validators.add(validator) self._AssertValidators(all_validators) @@ -1088,7 +1088,7 @@ validators, key=lambda validator: validator.insertion_index): try: validator.Verify(self) - except gflags_validators.Error, e: + except gflags_validators.Error as e: message = validator.PrintFlagsWithValues(self) raise IllegalFlagValue('%s: %s' % (message, str(e))) @@ -1163,7 +1163,7 @@ flags. flag_obj: A flag object. """ - for unused_module, flags_in_module in flags_by_module_dict.iteritems(): + for unused_module, flags_in_module in flags_by_module_dict.items(): # while (as opposed to if) takes care of multiple occurrences of a # flag in the list for the same module. while flag_obj in flags_in_module: @@ -1222,7 +1222,7 @@ # full forms: --mybool=(true|false). original_argv = list(argv) # list() makes a copy shortest_matches = None - for name, flag in fl.items(): + for name, flag in list(fl.items()): if not flag.boolean: continue if shortest_matches is None: @@ -1246,7 +1246,7 @@ # specified as a string of letters, each letter followed by a colon # if it takes an argument. Long options are stored in an array of # strings. Each string ends with an '=' if it takes an argument. - for name, flag in fl.items(): + for name, flag in list(fl.items()): longopts.append(name + "=") if len(name) == 1: # one-letter option: allow short flag type also shortopts += name @@ -1267,7 +1267,7 @@ else: optlist, unparsed_args = getopt.getopt(args, shortopts, longopts) break - except getopt.GetoptError, e: + except getopt.GetoptError as e: if not e.opt or e.opt in fl: # Not an unrecognized option, re-raise the exception as a FlagsError raise FlagsError(e) @@ -1335,7 +1335,7 @@ def Reset(self): """Resets the values to the point before FLAGS(argv) was called.""" - for f in self.FlagDict().values(): + for f in list(self.FlagDict().values()): f.Unparse() def RegisteredFlags(self): @@ -1375,13 +1375,13 @@ self.__RenderOurModuleFlags(module, helplist) self.__RenderModuleFlags('gflags', - _SPECIAL_FLAGS.FlagDict().values(), + list(_SPECIAL_FLAGS.FlagDict().values()), helplist) else: # Just print one long list of flags. self.__RenderFlagList( - self.FlagDict().values() + _SPECIAL_FLAGS.FlagDict().values(), + list(self.FlagDict().values()) + list(_SPECIAL_FLAGS.FlagDict().values()), helplist, prefix) return '\n'.join(helplist) @@ -1488,7 +1488,7 @@ """Returns: dictionary; maps flag names to their shortest unique prefix.""" # Sort the list of flag names sorted_flags = [] - for name, flag in fl.items(): + for name, flag in list(fl.items()): sorted_flags.append(name) if flag.boolean: sorted_flags.append('no%s' % name) @@ -1570,7 +1570,7 @@ flag_line_list = [] # Subset of lines w/o comments, blanks, flagfile= tags. try: file_obj = open(filename, 'r') - except IOError, e_msg: + except IOError as e_msg: raise CantOpenFlagFileError('ERROR:: Unable to open flagfile: %s' % e_msg) line_list = file_obj.readlines() @@ -1682,7 +1682,7 @@ from http://code.google.com/p/google-gflags """ s = '' - for flag in self.FlagDict().values(): + for flag in list(self.FlagDict().values()): if flag.value is not None: s += flag.Serialize() + '\n' return s @@ -1769,7 +1769,7 @@ try: return str(value) except UnicodeEncodeError: - return unicode(value) + return str(value) def _MakeXMLSafe(s): @@ -1883,7 +1883,7 @@ def Parse(self, argument): try: self.value = self.parser.Parse(argument) - except ValueError, e: # recast ValueError as IllegalFlagValue + except ValueError as e: # recast ValueError as IllegalFlagValue raise IllegalFlagValue("flag --%s=%s: %s" % (self.name, argument, e)) self.present += 1 @@ -2030,7 +2030,7 @@ return type.__call__(mcs, *args) -class ArgumentParser(object): +class ArgumentParser(object, metaclass=_ArgumentParserCache): """Base class used to parse and convert arguments. The Parse() method checks to make sure that the string argument is a @@ -2045,7 +2045,6 @@ and shared between flags. Initializer arguments are allowed, but all member variables must be derived from initializer arguments only. """ - __metaclass__ = _ArgumentParserCache syntactic_help = "" @@ -2296,7 +2295,7 @@ # a different module. So, we can't use _GetKeyFlagsForModule. # Instead, we take all flags from _SPECIAL_FLAGS (a private # FlagValues, where no other module should register flags). - [f.name for f in _SPECIAL_FLAGS.FlagDict().values()], + [f.name for f in list(_SPECIAL_FLAGS.FlagDict().values())], flag_values=_SPECIAL_FLAGS, key_flag_values=flag_values) @@ -2396,10 +2395,10 @@ if arg: doc = sys.modules["__main__"].__doc__ flags = str(FLAGS) - print doc or ("\nUSAGE: %s [flags]\n" % sys.argv[0]) + print(doc or ("\nUSAGE: %s [flags]\n" % sys.argv[0])) if flags: - print "flags:" - print flags + print("flags:") + print(flags) sys.exit(1) class HelpXMLFlag(BooleanFlag): """Similar to HelpFlag, but generates output in XML format.""" @@ -2426,10 +2425,10 @@ if arg: doc = sys.modules["__main__"].__doc__ flags = FLAGS.MainModuleHelp() - print doc or ("\nUSAGE: %s [flags]\n" % sys.argv[0]) + print(doc or ("\nUSAGE: %s [flags]\n" % sys.argv[0])) if flags: - print "flags:" - print flags + print("flags:") + print(flags) sys.exit(1) # --- python3/gflags2man.py (original) +++ python3/gflags2man.py (refactored) @@ -81,18 +81,18 @@ class Logging: """A super-simple logging class""" - def error(self, msg): print >>sys.stderr, "ERROR: ", msg - def warn(self, msg): print >>sys.stderr, "WARNING: ", msg - def info(self, msg): print msg + def error(self, msg): print("ERROR: ", msg, file=sys.stderr) + def warn(self, msg): print("WARNING: ", msg, file=sys.stderr) + def info(self, msg): print(msg) def debug(self, msg): self.vlog(1, msg) def vlog(self, level, msg): - if FLAGS.v >= level: print msg + if FLAGS.v >= level: print(msg) logging = Logging() class App: def usage(self, shorthelp=0): - print >>sys.stderr, __doc__ - print >>sys.stderr, "flags:" - print >>sys.stderr, str(FLAGS) + print(__doc__, file=sys.stderr) + print("flags:", file=sys.stderr) + print(str(FLAGS), file=sys.stderr) def run(self): main(sys.argv) app = App() --- python3/tests/gflags_googletest.py (original) +++ python3/tests/gflags_googletest.py (refactored) @@ -49,10 +49,10 @@ if actual == expected: return True - print "Error: FLAGS.MainModuleHelp() didn't return the expected result." - print "Got:" - print actual - print "[End of got]" + print("Error: FLAGS.MainModuleHelp() didn't return the expected result.") + print("Got:") + print(actual) + print("[End of got]") actual_lines = actual.split("\n") expected_lines = expected.split("\n") @@ -61,28 +61,28 @@ num_expected_lines = len(expected_lines) if num_actual_lines != num_expected_lines: - print "Number of actual lines = %d, expected %d" % ( - num_actual_lines, num_expected_lines) + print("Number of actual lines = %d, expected %d" % ( + num_actual_lines, num_expected_lines)) num_to_match = min(num_actual_lines, num_expected_lines) for i in range(num_to_match): if actual_lines[i] != expected_lines[i]: - print "One discrepancy: Got:" - print actual_lines[i] - print "Expected:" - print expected_lines[i] + print("One discrepancy: Got:") + print(actual_lines[i]) + print("Expected:") + print(expected_lines[i]) break else: # If we got here, found no discrepancy, print first new line. if num_actual_lines > num_expected_lines: - print "New help line:" - print actual_lines[num_expected_lines] + print("New help line:") + print(actual_lines[num_expected_lines]) elif num_expected_lines > num_actual_lines: - print "Missing expected help line:" - print expected_lines[num_actual_lines] + print("Missing expected help line:") + print(expected_lines[num_actual_lines]) else: - print "Bug in this test -- discrepancy detected but not found." + print("Bug in this test -- discrepancy detected but not found.") return False @@ -108,7 +108,7 @@ def assertRaisesWithRegexpMatch(self, exception, regexp, fn, *args, **kwargs): try: fn(*args, **kwargs) - except exception, why: + except exception as why: self.assertTrue(re.search(regexp, str(why)), "'%s' does not match '%s'" % (regexp, why)) return --- python3/tests/gflags_helpxml_test.py (original) +++ python3/tests/gflags_helpxml_test.py (refactored) @@ -35,7 +35,7 @@ import string -import StringIO +import io import sys import xml.dom.minidom import xml.sax.saxutils @@ -96,7 +96,7 @@ def _CheckFlagHelpInXML(self, flag_name, module_name, expected_output, is_key=False): # StringIO.StringIO is a file object that writes into a memory string. - sio = StringIO.StringIO() + sio = io.StringIO() flag_obj = self.fv[flag_name] flag_obj.WriteInfoInXMLFormat(sio, module_name, is_key=is_key, indent=' ') self.assertMultiLineEqual(sio.getvalue(), expected_output) @@ -496,7 +496,7 @@ gflags.DECLARE_key_flag('tmod_bar_u', flag_values=fv) # Generate flag help in XML format in the StringIO sio. - sio = StringIO.StringIO() + sio = io.StringIO() fv.WriteHelpInXMLFormat(sio) # Check that we got the expected result. --- python3/tests/gflags_unittest.py (original) +++ python3/tests/gflags_unittest.py (refactored) @@ -34,7 +34,7 @@ __pychecker__ = "no-local" # for unittest -import cStringIO +import io import sys import os import shutil @@ -169,8 +169,8 @@ assert 'numbers' in FLAGS.RegisteredFlags() # has_key - assert FLAGS.has_key('name') - assert not FLAGS.has_key('name2') + assert 'name' in FLAGS + assert 'name2' not in FLAGS assert 'name' in FLAGS assert 'name2' not in FLAGS @@ -216,24 +216,24 @@ # Test integer argument passing argv = ('./program', '--x', '0x12345') argv = FLAGS(argv) - self.assertEquals(FLAGS.x, 0x12345) - self.assertEquals(type(FLAGS.x), int) + self.assertEqual(FLAGS.x, 0x12345) + self.assertEqual(type(FLAGS.x), int) argv = ('./program', '--x', '0x1234567890ABCDEF1234567890ABCDEF') argv = FLAGS(argv) - self.assertEquals(FLAGS.x, 0x1234567890ABCDEF1234567890ABCDEF) - self.assertEquals(type(FLAGS.x), long) + self.assertEqual(FLAGS.x, 0x1234567890ABCDEF1234567890ABCDEF) + self.assertEqual(type(FLAGS.x), int) # Treat 0-prefixed parameters as base-10, not base-8 argv = ('./program', '--x', '012345') argv = FLAGS(argv) - self.assertEquals(FLAGS.x, 12345) - self.assertEquals(type(FLAGS.x), int) + self.assertEqual(FLAGS.x, 12345) + self.assertEqual(type(FLAGS.x), int) argv = ('./program', '--x', '0123459') argv = FLAGS(argv) - self.assertEquals(FLAGS.x, 123459) - self.assertEquals(type(FLAGS.x), int) + self.assertEqual(FLAGS.x, 123459) + self.assertEqual(type(FLAGS.x), int) argv = ('./program', '--x', '0x123efg') try: @@ -314,7 +314,7 @@ for lst in lists: argv = ('./program', '--%s=%s' % (name, sep.join(lst))) argv = FLAGS(argv) - self.assertEquals(getattr(FLAGS, name), lst) + self.assertEqual(getattr(FLAGS, name), lst) # Test help text flagsHelp = str(FLAGS) @@ -497,7 +497,7 @@ gflags.DEFINE_boolean("zoom1", 0, "runhelp z1", short_name='z') gflags.DEFINE_boolean("zoom2", 0, "runhelp z2", short_name='z') raise AssertionError("duplicate short flag detection failed") - except gflags.DuplicateFlag, e: + except gflags.DuplicateFlag as e: self.assertTrue("The flag 'z' is defined twice. " in e.args[0]) self.assertTrue("First from" in e.args[0]) self.assertTrue(", Second from" in e.args[0]) @@ -507,7 +507,7 @@ gflags.DEFINE_boolean("short1", 0, "runhelp s1", short_name='s') gflags.DEFINE_boolean("s", 0, "runhelp s2") raise AssertionError("duplicate mixed flag detection failed") - except gflags.DuplicateFlag, e: + except gflags.DuplicateFlag as e: self.assertTrue("The flag 's' is defined twice. " in e.args[0]) self.assertTrue("First from" in e.args[0]) self.assertTrue(", Second from" in e.args[0]) @@ -521,7 +521,7 @@ duplicate_flags = module_foo.DuplicateFlags(flagnames) try: original_flags.AppendFlagValues(duplicate_flags) - except gflags.DuplicateFlagError, e: + except gflags.DuplicateFlagError as e: self.assertTrue("flags_unittest" in str(e)) self.assertTrue("module_foo" in str(e)) @@ -580,8 +580,8 @@ allow_override=1) gflags.DEFINE_boolean("dup3", 1, "runhelp d32", short_name='u', allow_override=1) - self.assert_(str(FLAGS).find('runhelp d31') == -1) - self.assert_(str(FLAGS).find('runhelp d32') != -1) + self.assertTrue(str(FLAGS).find('runhelp d31') == -1) + self.assertTrue(str(FLAGS).find('runhelp d32') != -1) # Make sure AppendFlagValues works new_flags = gflags.FlagValues() @@ -782,12 +782,12 @@ 'float option that can occur multiple times', short_name='mf') for (expected, actual) in zip(float_defaults, FLAGS.get('m_float', None)): - self.assertAlmostEquals(expected, actual) + self.assertAlmostEqual(expected, actual) argv = ('./program', '--m_float=-17', '--mf=2.78e9') FLAGS(argv) expected_floats = [-17.0, 2.78e9] for (expected, actual) in zip(expected_floats, FLAGS.get('m_float', None)): - self.assertAlmostEquals(expected, actual) + self.assertAlmostEqual(expected, actual) def testSingleValueDefault(self): """Test multi_int and multi_float flags with a single default value.""" @@ -800,8 +800,8 @@ gflags.DEFINE_multi_float('m_float1', float_default, 'float option that can occur multiple times') actual = FLAGS.get('m_float1', None) - self.assertEquals(1, len(actual)) - self.assertAlmostEquals(actual[0], float_default) + self.assertEqual(1, len(actual)) + self.assertAlmostEqual(actual[0], float_default) def testBadMultiNumericalFlags(self): """Test multi_int and multi_float flags with non-parseable values.""" @@ -866,7 +866,7 @@ gflags.DEFINE_list("non_unicode", ["abc", "def", "ghi"], "help:\xC3\xAD".decode("utf-8")) - outfile = cStringIO.StringIO() + outfile = io.StringIO() FLAGS.WriteHelpInXMLFormat(outfile) actual_output = outfile.getvalue() @@ -924,9 +924,9 @@ tmp_flag_file_2 = open(tmp_path + '/UnitTestFile2.tst', 'w') tmp_flag_file_3 = open(tmp_path + '/UnitTestFile3.tst', 'w') tmp_flag_file_4 = open(tmp_path + '/UnitTestFile4.tst', 'w') - except IOError, e_msg: - print e_msg - print 'FAIL\n File Creation problem in Unit Test' + except IOError as e_msg: + print(e_msg) + print('FAIL\n File Creation problem in Unit Test') sys.exit(1) # put some dummy flags in our test files @@ -971,8 +971,8 @@ for file_name in self.files_to_delete: try: os.remove(file_name) - except OSError, e_msg: - print '%s\n, Problem deleting test file' % e_msg + except OSError as e_msg: + print('%s\n, Problem deleting test file' % e_msg) #end RemoveTestFiles def def _ReadFlagsFromFiles(self, argv, force_gnu): @@ -1261,8 +1261,8 @@ 'nocommon': 'nocommon', 'common': 'common'} - for name, shorter in expected_results.iteritems(): - self.assertEquals(shorter_flags[name], shorter) + for name, shorter in expected_results.items(): + self.assertEqual(shorter_flags[name], shorter) self.flag_values.__delattr__('a') self.flag_values.__delattr__('abc') @@ -1322,7 +1322,7 @@ argv = ('./program', '--nosuchflag', '--name=Bob', 'extra') self.flag_values(argv) raise AssertionError("Unknown flag exception not raised") - except gflags.UnrecognizedFlag, e: + except gflags.UnrecognizedFlag as e: assert e.flagname == 'nosuchflag' assert e.flagvalue == '--nosuchflag' @@ -1331,7 +1331,7 @@ argv = ('./program', '-w', '--name=Bob', 'extra') self.flag_values(argv) raise AssertionError("Unknown flag exception not raised") - except gflags.UnrecognizedFlag, e: + except gflags.UnrecognizedFlag as e: assert e.flagname == 'w' assert e.flagvalue == '-w' @@ -1340,7 +1340,7 @@ argv = ('./program', '--nosuchflagwithparam=foo', '--name=Bob', 'extra') self.flag_values(argv) raise AssertionError("Unknown flag exception not raised") - except gflags.UnrecognizedFlag, e: + except gflags.UnrecognizedFlag as e: assert e.flagname == 'nosuchflagwithparam' assert e.flagvalue == '--nosuchflagwithparam=foo' @@ -1366,7 +1366,7 @@ '--undefok=nosuchfla', 'extra') self.flag_values(argv) raise AssertionError("Unknown flag exception not raised") - except gflags.UnrecognizedFlag, e: + except gflags.UnrecognizedFlag as e: assert e.flagname == 'nosuchflag' try: @@ -1374,7 +1374,7 @@ '--undefok=nosuchflagg', 'extra') self.flag_values(argv) raise AssertionError("Unknown flag exception not raised") - except gflags.UnrecognizedFlag, e: + except gflags.UnrecognizedFlag as e: assert e.flagname == 'nosuchflag' # Allow unknown short flag -w if specified with undefok @@ -1409,7 +1409,7 @@ '--undefok=another_such', 'extra') self.flag_values(argv) raise AssertionError("Unknown flag exception not raised") - except gflags.UnrecognizedFlag, e: + except gflags.UnrecognizedFlag as e: assert e.flagname == 'nosuchflag' # Make sure --undefok doesn't mask other option errors. @@ -1458,7 +1458,7 @@ try: argv = nonglobal_flags(argv) raise AssertionError("Unknown flag exception not raised") - except gflags.UnrecognizedFlag, e: + except gflags.UnrecognizedFlag as e: assert e.flagname == 'nosuchflag' pass @@ -1491,7 +1491,7 @@ flag_values = gflags.FlagValues() gflags.DEFINE_string('delattr_foo', default_value, 'A simple flag.', flag_values=flag_values) - self.assertEquals(flag_values.delattr_foo, default_value) + self.assertEqual(flag_values.delattr_foo, default_value) flag_obj = flag_values['delattr_foo'] # We also check that _FlagIsRegistered works as expected :) self.assertTrue(flag_values._FlagIsRegistered(flag_obj)) @@ -1934,11 +1934,11 @@ try: self.flag_values.__setattr__(flag_name, flag_value) raise AssertionError('Bounds exception not raised!') - except gflags.IllegalFlagValue, e: + except gflags.IllegalFlagValue as e: expected = ('flag --%(name)s=%(value)s: %(value)s is not %(suffix)s' % {'name': flag_name, 'value': flag_value, 'suffix': expected_message_suffix}) - self.assertEquals(str(e), expected) + self.assertEqual(str(e), expected) def main(): --- python3/tests/gflags_validators_test.py (original) +++ python3/tests/gflags_validators_test.py (refactored) @@ -63,10 +63,10 @@ argv = ('./program') self.flag_values(argv) - self.assertEquals(None, self.flag_values.test_flag) + self.assertEqual(None, self.flag_values.test_flag) self.flag_values.test_flag = 2 - self.assertEquals(2, self.flag_values.test_flag) - self.assertEquals([None, 2], self.call_args) + self.assertEqual(2, self.flag_values.test_flag) + self.assertEqual([None, 2], self.call_args) def testDefaultValueNotUsedSuccess(self): def Checker(x): @@ -81,8 +81,8 @@ argv = ('./program', '--test_flag=1') self.flag_values(argv) - self.assertEquals(1, self.flag_values.test_flag) - self.assertEquals([1], self.call_args) + self.assertEqual(1, self.flag_values.test_flag) + self.assertEqual([1], self.call_args) def testValidatorNotCalledWhenOtherFlagIsChanged(self): def Checker(x): @@ -99,9 +99,9 @@ argv = ('./program') self.flag_values(argv) - self.assertEquals(1, self.flag_values.test_flag) + self.assertEqual(1, self.flag_values.test_flag) self.flag_values.other_flag = 3 - self.assertEquals([1], self.call_args) + self.assertEqual([1], self.call_args) def testExceptionRaisedIfCheckerFails(self): def Checker(x): @@ -119,9 +119,9 @@ try: self.flag_values.test_flag = 2 raise AssertionError('gflags.IllegalFlagValue expected') - except gflags.IllegalFlagValue, e: - self.assertEquals('flag --test_flag=2: Errors happen', str(e)) - self.assertEquals([1, 2], self.call_args) + except gflags.IllegalFlagValue as e: + self.assertEqual('flag --test_flag=2: Errors happen', str(e)) + self.assertEqual([1, 2], self.call_args) def testExceptionRaisedIfCheckerRaisesException(self): def Checker(x): @@ -141,9 +141,9 @@ try: self.flag_values.test_flag = 2 raise AssertionError('gflags.IllegalFlagValue expected') - except gflags.IllegalFlagValue, e: - self.assertEquals('flag --test_flag=2: Specific message', str(e)) - self.assertEquals([1, 2], self.call_args) + except gflags.IllegalFlagValue as e: + self.assertEqual('flag --test_flag=2: Specific message', str(e)) + self.assertEqual([1, 2], self.call_args) def testErrorMessageWhenCheckerReturnsFalseOnStart(self): def Checker(x): @@ -160,9 +160,9 @@ try: self.flag_values(argv) raise AssertionError('gflags.IllegalFlagValue expected') - except gflags.IllegalFlagValue, e: - self.assertEquals('flag --test_flag=1: Errors happen', str(e)) - self.assertEquals([1], self.call_args) + except gflags.IllegalFlagValue as e: + self.assertEqual('flag --test_flag=1: Errors happen', str(e)) + self.assertEqual([1], self.call_args) def testErrorMessageWhenCheckerRaisesExceptionOnStart(self): def Checker(x): @@ -179,9 +179,9 @@ try: self.flag_values(argv) raise AssertionError('IllegalFlagValue expected') - except gflags.IllegalFlagValue, e: - self.assertEquals('flag --test_flag=1: Specific message', str(e)) - self.assertEquals([1], self.call_args) + except gflags.IllegalFlagValue as e: + self.assertEqual('flag --test_flag=1: Specific message', str(e)) + self.assertEqual([1], self.call_args) def testValidatorsCheckedInOrder(self): @@ -195,11 +195,11 @@ self.calls = [] self._DefineFlagAndValidators(Required, Even) - self.assertEquals(['Required', 'Even'], self.calls) + self.assertEqual(['Required', 'Even'], self.calls) self.calls = [] self._DefineFlagAndValidators(Even, Required) - self.assertEquals(['Even', 'Required'], self.calls) + self.assertEqual(['Even', 'Required'], self.calls) def _DefineFlagAndValidators(self, first_validator, second_validator): local_flags = gflags.FlagValues() --- python3/tests/flags_modules_for_testing/module_bar.py (original) +++ python3/tests/flags_modules_for_testing/module_bar.py (refactored) @@ -132,4 +132,4 @@ """ # Indeed, using exec generates a lint warning. But some user code # actually uses exec, and we have to test for it ... - exec code in global_dict + exec(code, global_dict) + exit 0 Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.Nu8ncG + umask 022 + cd /builddir/build/BUILD + cd python-gflags-2.0 + pushd python3 ~/build/BUILD/python-gflags-2.0/python3 ~/build/BUILD/python-gflags-2.0 + CFLAGS='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fasynchronous-unwind-tables -fstack-clash-protection' + LDFLAGS='-Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld' + /usr/libexec/platform-python setup.py build '--executable=/usr/libexec/platform-python -s' running build running build_py creating build creating build/lib copying gflags.py -> build/lib copying gflags_validators.py -> build/lib running egg_info writing python_gflags.egg-info/PKG-INFO writing dependency_links to python_gflags.egg-info/dependency_links.txt writing top-level names to python_gflags.egg-info/top_level.txt reading manifest file 'python_gflags.egg-info/SOURCES.txt' reading manifest template 'MANIFEST.in' writing manifest file 'python_gflags.egg-info/SOURCES.txt' + sleep 1 + popd ~/build/BUILD/python-gflags-2.0 + exit 0 Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.GcGUW1 + umask 022 + cd /builddir/build/BUILD + '[' /builddir/build/BUILDROOT/python-gflags-2.0-13.oc8.noarch '!=' / ']' + rm -rf /builddir/build/BUILDROOT/python-gflags-2.0-13.oc8.noarch ++ dirname /builddir/build/BUILDROOT/python-gflags-2.0-13.oc8.noarch + mkdir -p /builddir/build/BUILDROOT + mkdir /builddir/build/BUILDROOT/python-gflags-2.0-13.oc8.noarch + cd python-gflags-2.0 ~/build/BUILD/python-gflags-2.0/python3 ~/build/BUILD/python-gflags-2.0 + pushd python3 + CFLAGS='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fasynchronous-unwind-tables -fstack-clash-protection' + LDFLAGS='-Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld' + /usr/libexec/platform-python setup.py install -O1 --skip-build --root /builddir/build/BUILDROOT/python-gflags-2.0-13.oc8.noarch running install running install_lib creating /builddir/build/BUILDROOT/python-gflags-2.0-13.oc8.noarch/usr creating /builddir/build/BUILDROOT/python-gflags-2.0-13.oc8.noarch/usr/lib creating /builddir/build/BUILDROOT/python-gflags-2.0-13.oc8.noarch/usr/lib/python3.6 creating /builddir/build/BUILDROOT/python-gflags-2.0-13.oc8.noarch/usr/lib/python3.6/site-packages copying build/lib/gflags_validators.py -> /builddir/build/BUILDROOT/python-gflags-2.0-13.oc8.noarch/usr/lib/python3.6/site-packages copying build/lib/gflags.py -> /builddir/build/BUILDROOT/python-gflags-2.0-13.oc8.noarch/usr/lib/python3.6/site-packages byte-compiling /builddir/build/BUILDROOT/python-gflags-2.0-13.oc8.noarch/usr/lib/python3.6/site-packages/gflags_validators.py to gflags_validators.cpython-36.pyc byte-compiling /builddir/build/BUILDROOT/python-gflags-2.0-13.oc8.noarch/usr/lib/python3.6/site-packages/gflags.py to gflags.cpython-36.pyc writing byte-compilation script '/tmp/tmpob78oyfi.py' /usr/libexec/platform-python /tmp/tmpob78oyfi.py removing /tmp/tmpob78oyfi.py running install_data creating /builddir/build/BUILDROOT/python-gflags-2.0-13.oc8.noarch/usr/bin copying gflags2man.py -> /builddir/build/BUILDROOT/python-gflags-2.0-13.oc8.noarch/usr/bin running install_egg_info running egg_info writing python_gflags.egg-info/PKG-INFO writing dependency_links to python_gflags.egg-info/dependency_links.txt writing top-level names to python_gflags.egg-info/top_level.txt reading manifest file 'python_gflags.egg-info/SOURCES.txt' reading manifest template 'MANIFEST.in' writing manifest file 'python_gflags.egg-info/SOURCES.txt' Copying python_gflags.egg-info to /builddir/build/BUILDROOT/python-gflags-2.0-13.oc8.noarch/usr/lib/python3.6/site-packages/python_gflags-2.0-py3.6.egg-info running install_scripts + mv /builddir/build/BUILDROOT/python-gflags-2.0-13.oc8.noarch/usr/bin/gflags2man.py /builddir/build/BUILDROOT/python-gflags-2.0-13.oc8.noarch/usr/bin/gflags2man + chmod +x /builddir/build/BUILDROOT/python-gflags-2.0-13.oc8.noarch/usr/bin/gflags2man + popd ~/build/BUILD/python-gflags-2.0 + /usr/lib/rpm/find-debuginfo.sh -j32 --strict-build-id -m -i --build-id-seed 2.0-13.oc8 --unique-debug-suffix -2.0-13.oc8.noarch --unique-debug-src-base python-gflags-2.0-13.oc8.noarch --run-dwz --dwz-low-mem-die-limit 10000000 --dwz-max-die-limit 50000000 -S debugsourcefiles.list /builddir/build/BUILD/python-gflags-2.0 find: 'debug': No such file or directory + /usr/lib/rpm/check-buildroot + /usr/lib/rpm/redhat/brp-ldconfig /sbin/ldconfig: Warning: ignoring configuration file that cannot be opened: /etc/ld.so.conf: No such file or directory + /usr/lib/rpm/brp-compress + /usr/lib/rpm/brp-strip-static-archive /usr/bin/strip + /usr/lib/rpm/brp-python-bytecompile '' 1 Bytecompiling .py files below /builddir/build/BUILDROOT/python-gflags-2.0-13.oc8.noarch/usr/lib/python3.6 using /usr/libexec/platform-python + /usr/lib/rpm/brp-python-hardlink + PYTHON3=/usr/libexec/platform-python + /usr/lib/rpm/redhat/brp-mangle-shebangs Processing files: python3-gflags-2.0-13.oc8.noarch Executing(%doc): /bin/sh -e /var/tmp/rpm-tmp.hmxLYg + umask 022 + cd /builddir/build/BUILD + cd python-gflags-2.0 + DOCDIR=/builddir/build/BUILDROOT/python-gflags-2.0-13.oc8.noarch/usr/share/doc/python3-gflags + export LC_ALL=C + LC_ALL=C + export DOCDIR + /usr/bin/mkdir -p /builddir/build/BUILDROOT/python-gflags-2.0-13.oc8.noarch/usr/share/doc/python3-gflags + cp -pr python3/AUTHORS /builddir/build/BUILDROOT/python-gflags-2.0-13.oc8.noarch/usr/share/doc/python3-gflags + cp -pr python3/ChangeLog /builddir/build/BUILDROOT/python-gflags-2.0-13.oc8.noarch/usr/share/doc/python3-gflags + cp -pr python3/COPYING /builddir/build/BUILDROOT/python-gflags-2.0-13.oc8.noarch/usr/share/doc/python3-gflags + cp -pr python3/README /builddir/build/BUILDROOT/python-gflags-2.0-13.oc8.noarch/usr/share/doc/python3-gflags + exit 0 Executing(%license): /bin/sh -e /var/tmp/rpm-tmp.MLZ6o8 + umask 022 + cd /builddir/build/BUILD + cd python-gflags-2.0 + LICENSEDIR=/builddir/build/BUILDROOT/python-gflags-2.0-13.oc8.noarch/usr/share/licenses/python3-gflags + export LC_ALL=C + LC_ALL=C + export LICENSEDIR + /usr/bin/mkdir -p /builddir/build/BUILDROOT/python-gflags-2.0-13.oc8.noarch/usr/share/licenses/python3-gflags + cp -pr python3/COPYING /builddir/build/BUILDROOT/python-gflags-2.0-13.oc8.noarch/usr/share/licenses/python3-gflags + exit 0 Provides: python3-gflags = 2.0-13.oc8 python3.6dist(python-gflags) = 2.0 python3dist(python-gflags) = 2.0 Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PartialHardlinkSets) <= 4.0.4-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1 Requires: /usr/libexec/platform-python python(abi) = 3.6 Checking for unpackaged file(s): /usr/lib/rpm/check-files /builddir/build/BUILDROOT/python-gflags-2.0-13.oc8.noarch Wrote: /builddir/build/RPMS/python3-gflags-2.0-13.oc8.noarch.rpm Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.u6x1pV + umask 022 + cd /builddir/build/BUILD + cd python-gflags-2.0 + /usr/bin/rm -rf /builddir/build/BUILDROOT/python-gflags-2.0-13.oc8.noarch + exit 0 Child return code was: 0