tests: py: conversion to python3
PATCH v6 1/2 tests: py: conversion to python3
This patch converts the 'nft-test.py' file to run on both python 2 and python3.
---
The version hystory of this patch is:
v1:conversion to py3 by changing the print statements. v2:add the '__future__' package for compatibility with py2 and py3. v3:solves the 'version' problem in argparse by adding a new argument. v4:uses .format() method to make print statements clearer. v5:updated the shebang and corrected the sequence of import statements. v6:resent the same with small changes
tests/py/nft-test.py | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-)
tests/py/nft-test.py +22 -20
@@ -1,4 +1,4 @@ -#!/usr/bin/python2 +#!/usr/bin/python # # (C) 2014 by Ana Rey Botello <[email protected]> #
@@ -13,6 +13,7 @@ # Thanks to the Outreach Program for Women (OPW) for sponsoring this test # infrastructure. +from __future__ import print_function import sys import os import argparse
@@ -1016,9 +1017,9 @@ def execute_cmd(cmd, filename, lineno, stdout_log=False, debug=False): :param debug: temporarily set these debug flags ''' global log_file - print >> log_file, "command: %s" % cmd + print("command: {}".format(cmd),file=log_file) if debug_option: - print cmd + print(cmd) if debug: debug_old = nftables.get_debug()
@@ -1212,7 +1213,7 @@ def run_test_file(filename, force_all_family_option, specific_file): sys.stdout.flush() if signal_received == 1: - print "\nSignal received. Cleaning up and Exitting..." + print("\nSignal received. Cleaning up and Exitting...") cleanup_on_exit() sys.exit(0)
@@ -1319,13 +1320,13 @@ def run_test_file(filename, force_all_family_option, specific_file): if specific_file: if force_all_family_option: - print print_result_all(filename, tests, total_warning, total_error, - total_unit_run) + print(print_result_all(filename, tests, total_warning, total_error, + total_unit_run)) else: - print print_result(filename, tests, total_warning, total_error) + print(print_result(filename, tests, total_warning, total_error)) else: if tests == passed and tests > 0: - print filename + ": " + Colors.GREEN + "OK" + Colors.ENDC + print(filename + ": " + Colors.GREEN + "OK" + Colors.ENDC) f.close() del table_list[:]
@@ -1336,7 +1337,7 @@ def run_test_file(filename, force_all_family_option, specific_file): def main(): - parser = argparse.ArgumentParser(description='Run nft tests', version='1.0') + parser = argparse.ArgumentParser(description='Run nft tests') parser.add_argument('filenames', nargs='*', metavar='path/to/file.t', help='Run only these tests')
@@ -1358,6 +1359,10 @@ def main(): parser.add_argument('-s', '--schema', action='store_true', dest='enable_schema', help='verify json input/output against schema') + + parser.add_argument('-v', '--version', action='version', + version='1.0', + help='print the version information') args = parser.parse_args() global debug_option, need_fix_option, enable_json_option, enable_json_schema
@@ -1372,15 +1377,15 @@ def main(): signal.signal(signal.SIGTERM, signal_handler) if os.getuid() != 0: - print "You need to be root to run this, sorry" + print("You need to be root to run this, sorry") return # Change working directory to repository root os.chdir(TESTS_PATH + "/../..") if not os.path.exists('src/.libs/libnftables.so'): - print "The nftables library does not exist. " \ - "You need to build the project." + print("The nftables library does not exist. " + "You need to build the project.") return if args.enable_schema and not args.enable_json:
@@ -1434,18 +1439,15 @@ def main(): run_total += file_unit_run if test_files == 0: - print "No test files to run" + print("No test files to run") else: if not specific_file: if force_all_family_option: - print "%d test files, %d files passed, %d unit tests, " \ - "%d total executed, %d error, %d warning" \ - % (test_files, files_ok, tests, run_total, errors, - warnings) + print("{} test files, {} files passed, {} unit tests, ".format(test_files,files_ok,tests)) + print("{} total executed, {} error, {} warning".format(run_total, errors, warnings)) else: - print "%d test files, %d files passed, %d unit tests, " \ - "%d error, %d warning" \ - % (test_files, files_ok, tests, errors, warnings) + print("{} test files, {} files passed, {} unit tests, ".format(test_files,files_ok,tests)) + print("{} error, {} warning".format(errors, warnings)) if __name__ == '__main__':
Signature · 1 line
2.17.1
Quoted 4 lines · Shekhar Sharma
This patch converts the '
nft-test.py' file to run on both python 2 and python3.Signed-off-by Shekhar Sharma <[email protected]>---
A couple nits below, but otherwise
Quoted 16 lines
The version hystory of this patch is:
v1:conversion to py3 by changing the print statements. v2:add the '__future__' package for compatibility with py2 and py3. v3:solves the 'version' problem in argparse by adding a new argument. v4:uses .format() method to make print statements clearer. v5:updated the shebang and corrected the sequence of import statements. v6:resent the same with small changestests/py/nft-test.py | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-)tests/py/nft-test.py +0
-0
tests/py/nft-test.py line 1
Quoted 2 lines
tests/py/nft-test.py +1
-1@@ -1,4 +1,4 @@ -#!/usr/bin/python2 +#!/usr/bin/python
nit: I think this shebang is more correct as it allows virtualenvs
#!/usr/bin/env python
But we can always call the tests with an explicit interpreter
# .../my/bin/python ./nft-test.py
Quoted 3 lines
tests/py/nft-test.py +0
-0# # (C) 2014 by Ana Rey Botello <[email protected]> #
[..]
tests/py/nft-test.py def main(): · line 1362
Quoted 5 lines
tests/py/nft-test.py +1
-0@@ -1358,6 +1359,10 @@ def main(): parser.add_argument('-s', '--schema', action='store_true', dest='enable_schema', help='verify json input/output against schema') +
nit: This adds a line with a tab, which both git-am and flake8 complain about.
Quoted 7 lines
tests/py/nft-test.py +3
-0+ parser.add_argument('-v', '--version', action='version', + version='1.0', + help='print the version information') args = parser.parse_args() global debug_option, need_fix_option, enable_json_option, enable_json_schema@@ -1372,15 +1377,15 @@ def main():
[..]
Quoted 32 lines · Eric Garver
Quoted 4 lines · Shekhar Sharma
This patch converts the '
nft-test.py' file to run on both python 2 and python3.Signed-off-by Shekhar Sharma <[email protected]>---
A couple nits below, but otherwise
Acked-by Eric Garver <[email protected]>Quoted 16 lines
The version hystory of this patch is:
v1:conversion to py3 by changing the print statements. v2:add the '__future__' package for compatibility with py2 and py3. v3:solves the 'version' problem in argparse by adding a new argument. v4:uses .format() method to make print statements clearer. v5:updated the shebang and corrected the sequence of import statements. v6:resent the same with small changestests/py/nft-test.py | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-)tests/py/nft-test.py +0
-0tests/py/nft-test.py line 1
Quoted 2 lines
tests/py/nft-test.py +1
-1@@ -1,4 +1,4 @@ -#!/usr/bin/python2 +#!/usr/bin/pythonnit: I think this shebang is more correct as it allows virtualenvs
Quoted 6 lines
#!/usr/bin/env python
But we can always call the tests with an explicit interpreter
# .../my/bin/python ./nft-test.py
Sure, I will update it and post the patch.
Quoted 4 lines
Quoted 3 lines
tests/py/nft-test.py +0
-0# # (C) 2014 by Ana Rey Botello <[email protected]> #[..]
Quoted 9 lines
tests/py/nft-test.py def main(): · line 1362
Quoted 5 lines
tests/py/nft-test.py +1
-0@@ -1358,6 +1359,10 @@ def main(): parser.add_argument('-s', '--schema', action='store_true', dest='enable_schema', help='verify json input/output against schema') +nit: This adds a line with a tab, which both git-am and flake8 complain about.
Will remove it.
Quoted 8 lines
Quoted 7 lines
tests/py/nft-test.py +3
-0+ parser.add_argument('-v', '--version', action='version', + version='1.0', + help='print the version information') args = parser.parse_args() global debug_option, need_fix_option, enable_json_option, enable_json_schema@@ -1372,15 +1377,15 @@ def main():[..]
Since i have to update and resend the netns patch, i think i will make changes for these nits in that.
Is it okay? or should i send a separate patch?
Thanks!
Shekhar
Quoted 60 lines · shekhar sharma
Quoted 32 lines · Eric Garver
Quoted 4 lines · Shekhar Sharma
This patch converts the '
nft-test.py' file to run on both python 2 and python3.Signed-off-by Shekhar Sharma <[email protected]>---
A couple nits below, but otherwise
Acked-by Eric Garver <[email protected]>Quoted 16 lines
The version hystory of this patch is:
v1:conversion to py3 by changing the print statements. v2:add the '__future__' package for compatibility with py2 and py3. v3:solves the 'version' problem in argparse by adding a new argument. v4:uses .format() method to make print statements clearer. v5:updated the shebang and corrected the sequence of import statements. v6:resent the same with small changestests/py/nft-test.py | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-)tests/py/nft-test.py +0
-0tests/py/nft-test.py line 1
Quoted 2 lines
tests/py/nft-test.py +1
-1@@ -1,4 +1,4 @@ -#!/usr/bin/python2 +#!/usr/bin/pythonnit: I think this shebang is more correct as it allows virtualenvs
Quoted 6 lines
#!/usr/bin/env python
But we can always call the tests with an explicit interpreter
# .../my/bin/python ./nft-test.pySure, I will update it and post the patch.
Quoted 4 lines
Quoted 3 lines
tests/py/nft-test.py +0
-0# # (C) 2014 by Ana Rey Botello <[email protected]> #[..]
Quoted 9 lines
tests/py/nft-test.py def main(): · line 1362
Quoted 5 lines
tests/py/nft-test.py +1
-0@@ -1358,6 +1359,10 @@ def main(): parser.add_argument('-s', '--schema', action='store_true', dest='enable_schema', help='verify json input/output against schema') +nit: This adds a line with a tab, which both git-am and flake8 complain about.
Will remove it.
Quoted 4 lines
Quoted 4 lines
tests/py/nft-test.py +3
-0+ parser.add_argument('-v', '--version', action='version', + version='1.0', + help='print the version information')
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
tests/py/nft-test.py +0
-0args = parser.parse_args() global debug_option, need_fix_option, enable_json_option, enable_json_schema@@ -1372,15 +1377,15 @@ def main():[..]
Since i have to update and resend the netns patch, i think i will make changes for these nits in that.
Is it okay? or should i send a separate patch?
Sending another revision is okay.