diff --git a/doc/contributing/pickle-to-xml.py b/doc/contributing/pickle-to-xml.py index b2db082ad..6a4fcebb3 100755 --- a/doc/contributing/pickle-to-xml.py +++ b/doc/contributing/pickle-to-xml.py @@ -33,7 +33,6 @@ def dump_pickles(out, dirname, filename, path): next_path = os.path.normpath(os.path.join(path, data['next']['link'])) next_filename = os.path.basename(next_path) + '.fpickle' dump_pickles(out, dirname, next_filename, next_path) - return import sys diff --git a/doc/tutorial/pickle-to-xml.py b/doc/tutorial/pickle-to-xml.py index b2db082ad..6a4fcebb3 100755 --- a/doc/tutorial/pickle-to-xml.py +++ b/doc/tutorial/pickle-to-xml.py @@ -33,7 +33,6 @@ def dump_pickles(out, dirname, filename, path): next_path = os.path.normpath(os.path.join(path, data['next']['link'])) next_filename = os.path.basename(next_path) + '.fpickle' dump_pickles(out, dirname, next_filename, next_path) - return import sys diff --git a/test.py b/test.py index 336fd8ab5..87e5c6b67 100755 --- a/test.py +++ b/test.py @@ -22,7 +22,6 @@ import argparse import subprocess import threading import signal -import xml.dom.minidom import shutil import fnmatch @@ -32,14 +31,14 @@ from utils import get_list_from_file colors_lst={'USE':True,'BOLD':'\x1b[01;1m','RED':'\x1b[01;31m','GREEN':'\x1b[32m','YELLOW':'\x1b[33m','PINK':'\x1b[35m','BLUE':'\x1b[01;34m','CYAN':'\x1b[36m','GREY':'\x1b[37m','NORMAL':'\x1b[0m','cursor_on':'\x1b[?25h','cursor_off':'\x1b[?25l',} def get_color(cl): if colors_lst['USE']: - return colors_lst.get(cl,'') - return'' + return colors_lst.get(cl, '') + return '' class color_dict(object): - def __getattr__(self,a): + def __getattr__(self, a): return get_color(a) - def __call__(self,a): + def __call__(self, a): return get_color(a) -colors=color_dict() +colors = color_dict() try: import queue @@ -1246,13 +1245,13 @@ def run_tests(): examples_sorted.sort() if ENABLE_PYTHON_BINDINGS: python_examples_sorted = [] - for (x,y) in python_tests: + for (x, y) in python_tests: if y == 'True': python_examples_sorted.append(x) python_examples_sorted.sort() examples_sorted.extend(python_examples_sorted) for item in examples_sorted: - print("example ", item) + print("example ", item) print() if args.kinds or args.list: @@ -1284,7 +1283,7 @@ def run_tests(): if not os.path.exists(TMP_OUTPUT_DIR): os.makedirs(TMP_OUTPUT_DIR) - testpy_output_dir = os.path.join(TMP_OUTPUT_DIR, date_and_time); + testpy_output_dir = os.path.join(TMP_OUTPUT_DIR, date_and_time) if not os.path.exists(testpy_output_dir): os.makedirs(testpy_output_dir) @@ -1390,7 +1389,7 @@ def run_tests(): output_queue = queue.Queue(0) jobs = 0 - threads=[] + threads = [] # # In Python 2.6 you can just use multiprocessing module, but we don't want @@ -1399,7 +1398,7 @@ def run_tests(): processors = 1 if sys.platform != "win32": - if 'SC_NPROCESSORS_ONLN'in os.sysconf_names: + if 'SC_NPROCESSORS_ONLN' in os.sysconf_names: processors = os.sysconf('SC_NPROCESSORS_ONLN') else: proc = subprocess.Popen("sysctl -n hw.ncpu", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -1553,7 +1552,7 @@ def run_tests(): key_list = [] for key in ns3_runnable_programs_dictionary: - key_list.append (key) + key_list.append(key) example_name_key_list = fnmatch.filter(key_list, example_name) if len(example_name_key_list) == 0: @@ -2013,7 +2012,7 @@ def main(argv): signal.signal(signal.SIGINT, sigint_hook) # From waf/waflib/Options.py - envcolor=os.environ.get('NOCOLOR','') and 'no' or 'auto' or 'yes' + envcolor = os.environ.get('NOCOLOR', '') and 'no' or 'auto' or 'yes' if args.nocolor or envcolor == 'no': colors_lst['USE'] = False diff --git a/utils.py b/utils.py index 2be96c1d3..a70aaae29 100644 --- a/utils.py +++ b/utils.py @@ -5,7 +5,7 @@ # should be enabled import os -import sys + def get_list_from_file(file_path, list_name): '''Looks for a Python list called list_name in the file specified @@ -121,4 +121,3 @@ def read_config_file(): tests_enabled = get_bool_from_file(dot_ns3rc_path, 'tests_enabled', value_if_missing) return (config_file_exists, modules_enabled, examples_enabled, tests_enabled) - diff --git a/utils/grid.py b/utils/grid.py index e8293af8c..61a07b37e 100644 --- a/utils/grid.py +++ b/utils/grid.py @@ -14,7 +14,7 @@ class DataRange: # end ## @var value # value - def __init__(self, start = 0, end = 0, value = ''): + def __init__(self, start=0, end=0, value=''): """! Initializer @param self this object @param start start @@ -30,7 +30,7 @@ class EventString: # at ## @var value # value - def __init__(self, at = 0, value = ''): + def __init__(self, at=0, value=''): """! Initializer @param self this object @param at you @@ -44,7 +44,7 @@ class EventFloat: # at ## @var value # value - def __init__(self, at = 0, value = 0.0): + def __init__(self, at=0, value=0.0): """! Initializer @param self this object @param at you @@ -58,7 +58,7 @@ class EventInt: # at ## @var value # value - def __init__(self, at = 0, value = 0.0): + def __init__(self, at=0, value=0.0): """! Initializer @param self this object @param at you @@ -88,7 +88,7 @@ class TimelineDataRange: # name ## @var ranges # ranges - def __init__(self, name = ''): + def __init__(self, name=''): """! Initializer @param self this object @param name name @@ -154,13 +154,13 @@ class TimelineDataRange: s = self.__search(start) e = self.__search(end) if s == -1 and e == -1: - return(0, 0) + return (0, 0) elif s == -1: - return(0, e + 1) + return (0, e + 1) elif e == -1: - return(s, len(self.ranges)) + return (s, len(self.ranges)) else: - return(s, e + 1) + return (s, e + 1) def sort(self): """! Sort ranges @param self this object @@ -175,16 +175,16 @@ class TimelineDataRange: if len(self.ranges) > 0: lo = self.ranges[0].start hi = self.ranges[len(self.ranges)-1].end - return(lo, hi) + return (lo, hi) else: - return(0, 0) + return (0, 0) ## TimelineEvent class class TimelineEvent: ## @var name # name ## @var events # events - def __init__(self, name = ''): + def __init__(self, name=''): """! Get ranges bounds @param self this object @param name name @@ -235,7 +235,7 @@ class TimelineEvent: """ s = self.__search(start) e = self.__search(end) - return(s, e + 1) + return (s, e + 1) def sort(self): """! Sort function @param self this object @@ -250,9 +250,9 @@ class TimelineEvent: if len(self.events) > 0: lo = self.events[0].at hi = self.events[-1].at - return(lo, hi) + return (lo, hi) else: - return(0, 0) + return (0, 0) ## Timeline class class Timeline: @@ -264,7 +264,7 @@ class Timeline: # event string ## @var event_int # event int - def __init__(self, name = ''): + def __init__(self, name=''): """! Initializer @param self this object @param name name @@ -363,7 +363,7 @@ class Timeline: lo = ev_lo if ev_hi > hi: hi = ev_hi - return(lo, hi) + return (lo, hi) ## Timelines class class Timelines: @@ -412,7 +412,7 @@ class Timelines: lo = t_lo if t_hi > hi: hi = t_hi - return(lo, hi) + return (lo, hi) def get_all_range_values(self): """! Get All Ranges @param self this object @@ -433,7 +433,7 @@ class Color: # green ## @var b # blue - def __init__(self, r = 0.0, g = 0.0, b = 0.0): + def __init__(self, r=0.0, g=0.0, b=0.0): """! Initializer @param self: this object @param r: red @@ -587,8 +587,6 @@ class TopLegendRenderer: ctx.show_text(legend) i += 1 - return - ## TimelinesRenderer class class TimelinesRenderer: ## @var padding @@ -797,7 +795,7 @@ class TimelinesRenderer: for timeline in self.timelines.get_all(): (y_bearing, t_width, t_height) = ctx.text_extents(timeline.name)[1:4] ctx.move_to(left_x_start, cur_y + self.max_text_height - (t_height + y_bearing)) - ctx.show_text(timeline.name); + ctx.show_text(timeline.name) for events_int in timeline.get_events_int(): (y_bearing, t_width, t_height) = ctx.text_extents(events_int.name)[1:4] ctx.move_to(right_x_start, cur_y + self.max_text_height - (t_height + y_bearing)) @@ -830,7 +828,6 @@ class TimelinesRenderer: 0, bot_y) self.draw_line(ctx, right_x_end + self.padding / 2, 0, 0, bot_y) - return ## ScaleRenderer class class ScaleRenderer: @@ -869,7 +866,7 @@ class ScaleRenderer: @param x x @return real x """ - real_x = (x - self.__lo ) * self.__width / (self.__hi - self.__lo) + real_x = (x - self.__lo) * self.__width / (self.__hi - self.__lo) return real_x def set_top(self): """! Set Top @@ -899,7 +896,7 @@ class ScaleRenderer: closest *= 10 if (data_delta / closest) == 0: delta = closest - elif(data_delta / closest) == 1: + elif (data_delta / closest) == 1: delta = closest / 10 else: delta = closest @@ -940,7 +937,7 @@ class ScaleRenderer: ctx.set_line_width(1.0) ticks = range(int(start), int(end + delta), int(delta)) for x in ticks: - real_x = (x - self.__lo ) * self.__width / (self.__hi - self.__lo) + real_x = (x - self.__lo) * self.__width / (self.__hi - self.__lo) ctx.move_to(real_x, 0) ctx.line_to(real_x, 5*s) ctx.close_path() @@ -958,7 +955,7 @@ class ScaleRenderer: start = self.__lo - (self.__lo % delta) + delta end = self.__hi - (self.__hi % delta) for x in range(int(start), int(end + delta), int(delta)): - real_x = (x - self.__lo ) * self.__width / (self.__hi - self.__lo) + real_x = (x - self.__lo) * self.__width / (self.__hi - self.__lo) ctx.move_to(real_x, 0) ctx.line_to(real_x, 3*s) ctx.close_path() @@ -1024,7 +1021,7 @@ class GraphicRenderer: """ y_start = self.__top_legend.get_height() x_start = self.__data.get_data_x_start() - return(x_start, y_start, self.__width - x_start, self.__data.get_height()) + return (x_start, y_start, self.__width - x_start, self.__data.get_height()) def scale_data(self, x): """! Get Data Rectangle @param self this object @@ -1044,7 +1041,7 @@ class GraphicRenderer: y_height = self.__bot_scale.get_height() + 20 x_start = self.__bot_scale.get_position(self.__r_start) x_end = self.__bot_scale.get_position(self.__r_end) - return(x_start, y_start, x_end - x_start, y_height) + return (x_start, y_start, x_end - x_start, y_height) def scale_selection(self, x): """! Scale Selection @param self this object @@ -1074,7 +1071,7 @@ class GraphicRenderer: @param self this object @return range """ - return(self.__r_start, self.__r_end) + return (self.__r_start, self.__r_end) def set_data(self, data): """! Set Date @param self this object @@ -1144,14 +1141,14 @@ class GraphicRenderer: # data ctx.save() ctx.translate(0, - top_legend_height) + top_legend_height) self.__data.draw(ctx) ctx.restore() # scale below data ctx.save() ctx.translate(self.__data.get_data_x_start(), - top_legend_height + self.__data.get_height() + self.__mid_scale.get_height()) + top_legend_height + self.__data.get_height() + self.__mid_scale.get_height()) self.__mid_scale.draw(ctx) ctx.restore() @@ -1177,7 +1174,7 @@ class GraphicRenderer: select_end = self.__bot_scale.get_position(self.__r_end) # left connection between top scale and bottom scale - ctx.move_to(0, height_used); + ctx.move_to(0, height_used) ctx.line_to(self.__data.get_data_x_start(), height_used) ctx.line_to(select_start, height_used + 20) ctx.line_to(0, height_used + 20) @@ -1206,12 +1203,12 @@ class GraphicRenderer: unused_end = self.__bot_scale.get_position(self.__r_end) unused_height = self.__bot_scale.get_height() + 20 ctx.rectangle(0, height_used, - unused_start, - unused_height) + unused_start, + unused_height) ctx.rectangle(unused_end, - height_used, - self.__width - unused_end, - unused_height) + height_used, + self.__width - unused_end, + unused_height) ctx.set_source_rgb(0.9, 0.9, 0.9) ctx.fill() @@ -1584,7 +1581,6 @@ class MainWindow: dialog.set_default_response(1) dialog.connect("response", self.__dialog_response_cb) dialog.show() - return def __dialog_response_cb(self, widget, response): """! Dialog Response Callback @param self this object @@ -1596,7 +1592,6 @@ class MainWindow: filename = self.__dialog.get_filename() self.__render.output_png(filename) widget.hide() - return ## read_data function @@ -1654,7 +1649,6 @@ def read_data(filename): return (colors, timelines) - def main(): (colors, timelines) = read_data(sys.argv[1]) (lower_bound, upper_bound) = timelines.get_bounds() diff --git a/utils/tests/TestBase.py b/utils/tests/TestBase.py index b23aaddbc..0bf6ef3c2 100644 --- a/utils/tests/TestBase.py +++ b/utils/tests/TestBase.py @@ -24,9 +24,9 @@ import os def print_case_in_file(case_string, out): for i in range(100): - print("-", end = '', file = out) + print("-", end='', file=out) print(file=out) - print("running test case " + case_string, end='\n\n', file = out) + print("running test case " + case_string, end='\n\n', file=out) out.flush() def print_failed_cases(failed_cases): @@ -40,10 +40,10 @@ def print_cmds(cmds): print(cmd.replace(sys.executable, '')) def set_workdir(): - dir_files = [ f for f in os.listdir('.') if os.path.exists(f) ] + dir_files = [f for f in os.listdir('.') if os.path.exists(f)] if not 'VERSION' in dir_files and not 'ns3' in dir_files: if os.path.split(os.path.abspath('.'))[1] == 'tests' and os.path.split(os.path.abspath(os.pardir))[1] == 'utils': - os.chdir('../../') + os.chdir('../../') else: print('Error: Invalid working directory') sys.exit(1) @@ -75,7 +75,7 @@ class TestBaseClass: self.my_env['LD_LIBRARY_PATH'] = os.getcwd() + "/build" self.mode = mode self.outfile = 'test-port-'+self.mode+'.out' - self.options = self.parseargs(argv , desc) + self.options = self.parseargs(argv, desc) def parseargs(self, argv, desc): """! @@ -85,15 +85,15 @@ class TestBaseClass: @param desc description @return command line arguments """ - parser = argparse.ArgumentParser(description = desc) - parser.add_argument('-f', '--file', action='store', dest='out_file', default = self.outfile, + parser = argparse.ArgumentParser(description=desc) + parser.add_argument('-f', '--file', action='store', dest='out_file', default=self.outfile, metavar="FILE", help='File to be used for storing the command specific output (Default: '+self.outfile+')') parser.add_argument('-c', action='store_true', dest='cmds', default=False, help='List out all the commands being tested') parser.add_argument('-m', action='store_true', dest='mute', default=False, help='Sends only stderr output to FILE') - parser.add_argument('-x', '--customcmd', action='store', dest='custcmd', default = None, + parser.add_argument('-x', '--customcmd', action='store', dest='custcmd', default=None, help='Enter a comma-separated list of commands to override the existing ones. NOT APPLICABLE FOR TEST-PY SUITE.') return parser.parse_args(argv) @@ -142,5 +142,5 @@ class TestBaseClass: print_failed_cases(failed_cases) else: print("\nAll cases passed") - print ("Detailed output available in " + self.options.out_file, end='\n\n') + print("Detailed output available in " + self.options.out_file, end='\n\n') return final_return diff --git a/utils/tests/test-test.py b/utils/tests/test-test.py index 519da4f3d..96a6197a5 100644 --- a/utils/tests/test-test.py +++ b/utils/tests/test-test.py @@ -71,49 +71,49 @@ def main(argv): Prepares test cases and executes """ test_cases = [ - '', - '-h', - '--help', - '-b build/', - '--buildpath=build/', - '-c performance', - '--constrain=performance', - '-d', - '--duration', - '-e socket-options-ipv6', - '--example=socket-options-ipv6', - '-u', - '--update-data', - '-f EXTENSIVE --fullness=EXTENSIVE' - '-g', - '--grind', - '-l', - '--list', - '-m', - '--multiple', - '-n', - '--no-build', - '-p first', - '--pyexample=first', - '-r', - '--retain', - '-s ns3-tcp-interoperability', - '--suite=ns3-tcp-interoperability', - '-t t_opt.txt', - '--text=t_opt.txt && rm -rf t_opt.txt', - '-v', - '--verbose', - '-w t_opt.html && rm -rf t_opt.html', - '--web=t_opt.html && rm -rf t_opt.html', - '--html=t_opt.html && rm -rf t_opt.html', - '-x t_opt.xml && rm -rf t_opt.xml', - '--xml=t_opt.xml && rm -rf t_opt.xml', + '', + '-h', + '--help', + '-b build/', + '--buildpath=build/', + '-c performance', + '--constrain=performance', + '-d', + '--duration', + '-e socket-options-ipv6', + '--example=socket-options-ipv6', + '-u', + '--update-data', + '-f EXTENSIVE --fullness=EXTENSIVE' + '-g', + '--grind', + '-l', + '--list', + '-m', + '--multiple', + '-n', + '--no-build', + '-p first', + '--pyexample=first', + '-r', + '--retain', + '-s ns3-tcp-interoperability', + '--suite=ns3-tcp-interoperability', + '-t t_opt.txt', + '--text=t_opt.txt && rm -rf t_opt.txt', + '-v', + '--verbose', + '-w t_opt.html && rm -rf t_opt.html', + '--web=t_opt.html && rm -rf t_opt.html', + '--html=t_opt.html && rm -rf t_opt.html', + '-x t_opt.xml && rm -rf t_opt.xml', + '--xml=t_opt.xml && rm -rf t_opt.xml', ] configure_string = sys.executable + ' ns3 configure --enable-tests --enable-examples' clean_string = sys.executable + ' ns3 clean' - cmd_execute_list = [ '%s && %s test.py %s && %s' % (configure_string, sys.executable, option, clean_string) for option in test_cases] - runner = TestBaseClass(argv[1:], "Test suite for the ns-3 unit test runner" , 'test-py') + cmd_execute_list = ['%s && %s test.py %s && %s' % (configure_string, sys.executable, option, clean_string) for option in test_cases] + runner = TestBaseClass(argv[1:], "Test suite for the ns-3 unit test runner", 'test-py') return runner.runtests(cmd_execute_list) if __name__ == '__main__':