From 85fd52880db93c6cd01f2c459eb46e6dd35d777c Mon Sep 17 00:00:00 2001 From: hut Date: Mon, 7 Jun 2010 15:53:01 +0200 Subject: simplified all_tests.py, moved to test/ --- test/all_benchmarks.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 test/all_benchmarks.py (limited to 'test/all_benchmarks.py') diff --git a/test/all_benchmarks.py b/test/all_benchmarks.py new file mode 100755 index 00000000..73316658 --- /dev/null +++ b/test/all_benchmarks.py @@ -0,0 +1,58 @@ +#!/usr/bin/python +# Copyright (C) 2009, 2010 Roman Zimbelmann +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +"""Run all the tests inside the test/ directory as a test suite.""" +if __name__ == '__main__': + from re import compile + from test import * + from time import time + from types import FunctionType as function + from sys import argv + bms = [] + try: + n = int(argv[1]) + except IndexError: + n = 10 + if len(argv) > 2: + args = [compile(re) for re in argv[2:]] + def allow(name): + for re in args: + if re.search(name): + return True + else: + return False + else: + allow = lambda name: True + for key, val in vars().copy().items(): + if key.startswith('bm_'): + bms.extend(v for k,v in vars(val).items() if type(v) == type) + for bmclass in bms: + for attrname in vars(bmclass): + if not attrname.startswith('bm_'): + continue + bmobj = bmclass() + t1 = time() + method = getattr(bmobj, attrname) + methodname = "{0}.{1}".format(bmobj.__class__.__name__, method.__name__) + if allow(methodname): + try: + method(n) + except: + print("{0} failed!".format(methodname)) + raise + else: + t2 = time() + print("{0:60}: {1:10}s".format(methodname, t2 - t1)) -- cgit 1.4.1-2-gfad0 From 8129ccb6d1e10182d60a71483da2c3db08108adb Mon Sep 17 00:00:00 2001 From: hut Date: Wed, 9 Jun 2010 10:33:50 +0200 Subject: Changed hashbang line to "#!/usr/bin/env python" --- INSTALL | 2 +- doc/print_colors.py | 2 +- doc/print_keys.py | 2 +- ranger.py | 2 +- ranger/__main__.py | 2 +- test/all_benchmarks.py | 2 +- test/all_tests.py | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) (limited to 'test/all_benchmarks.py') diff --git a/INSTALL b/INSTALL index 5fc5ca6b..9939c11b 100644 --- a/INSTALL +++ b/INSTALL @@ -21,7 +21,7 @@ though you might want to read the Makefile first) 0. Make sure you have a recent version of python, including the curses module, which is the case if this shell command prints no errors: - python -c 'import curses' + python -c 'import curses, sys; assert sys.version >= "2.6"' 1. Copy the file "ranger.py" into any of the directories in the PATH diff --git a/doc/print_colors.py b/doc/print_colors.py index 7ffd6500..c3508fa6 100755 --- a/doc/print_colors.py +++ b/doc/print_colors.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python """ You can use this tool to display all supported colors and their color number. It will exit after a keypress. diff --git a/doc/print_keys.py b/doc/print_keys.py index 0790acab..f87a2a40 100644 --- a/doc/print_keys.py +++ b/doc/print_keys.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python """ You can use this tool to find out values of keypresses """ diff --git a/ranger.py b/ranger.py index aca1b557..a3f2095b 100755 --- a/ranger.py +++ b/ranger.py @@ -1,4 +1,4 @@ -#!/usr/bin/python -O +#!/usr/bin/env python -O # coding=utf-8 # # Ranger: Explore your forest of files from inside your terminal diff --git a/ranger/__main__.py b/ranger/__main__.py index 0c38b6e1..2164c045 100644 --- a/ranger/__main__.py +++ b/ranger/__main__.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # coding=utf-8 # # Copyright (C) 2009, 2010 Roman Zimbelmann diff --git a/test/all_benchmarks.py b/test/all_benchmarks.py index 73316658..84d6817d 100755 --- a/test/all_benchmarks.py +++ b/test/all_benchmarks.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright (C) 2009, 2010 Roman Zimbelmann # # This program is free software: you can redistribute it and/or modify diff --git a/test/all_tests.py b/test/all_tests.py index dff49b60..04321462 100755 --- a/test/all_tests.py +++ b/test/all_tests.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright (C) 2009, 2010 Roman Zimbelmann # # This program is free software: you can redistribute it and/or modify -- cgit 1.4.1-2-gfad0 From 110dd383d250c20b1bf74f059f8f996d81a6d123 Mon Sep 17 00:00:00 2001 From: hut Date: Wed, 9 Jun 2010 11:43:36 +0200 Subject: all_benchmarks.py: fix + cleanup --- test/all_benchmarks.py | 75 +++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 40 deletions(-) (limited to 'test/all_benchmarks.py') diff --git a/test/all_benchmarks.py b/test/all_benchmarks.py index 84d6817d..e1b47142 100755 --- a/test/all_benchmarks.py +++ b/test/all_benchmarks.py @@ -14,45 +14,40 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -"""Run all the tests inside the test/ directory as a test suite.""" +""" +Run all the benchmarks inside this directory. +Usage: ./all_benchmarks.py [count] [regexp-filters...] +""" + +import os +import re +import sys +import time + if __name__ == '__main__': - from re import compile - from test import * - from time import time - from types import FunctionType as function - from sys import argv - bms = [] - try: - n = int(argv[1]) - except IndexError: - n = 10 - if len(argv) > 2: - args = [compile(re) for re in argv[2:]] - def allow(name): - for re in args: - if re.search(name): - return True + count = int(sys.argv[1]) if len(sys.argv) > 1 else 10 + regexes = [re.compile(fltr) for fltr in sys.argv[2:]] + modules = (fname[:-3] for fname in os.listdir(sys.path[0]) \ + if fname[:3] == 'bm_' and fname[-3:] == '.py') + + benchmarks = [] # find all benchmark (class, methodname) pairs + for val in [__import__(module) for module in modules]: + for cls in vars(val).values(): + if type(cls) == type: + for methodname in vars(cls): + if methodname.startswith('bm_'): + benchmarks.append((cls, methodname)) + + for cls, methodname in benchmarks: + full_method_name = "{0}.{1}".format(cls.__name__, methodname) + if all(re.search(full_method_name) for re in regexes): + method = getattr(cls(), methodname) + t1 = time.time() + try: + method(count) + except: + print("{0} failed!".format(full_method_name)) + raise else: - return False - else: - allow = lambda name: True - for key, val in vars().copy().items(): - if key.startswith('bm_'): - bms.extend(v for k,v in vars(val).items() if type(v) == type) - for bmclass in bms: - for attrname in vars(bmclass): - if not attrname.startswith('bm_'): - continue - bmobj = bmclass() - t1 = time() - method = getattr(bmobj, attrname) - methodname = "{0}.{1}".format(bmobj.__class__.__name__, method.__name__) - if allow(methodname): - try: - method(n) - except: - print("{0} failed!".format(methodname)) - raise - else: - t2 = time() - print("{0:60}: {1:10}s".format(methodname, t2 - t1)) + t2 = time.time() + print("{0:60}: {1:10}s".format(full_method_name, t2 - t1)) -- cgit 1.4.1-2-gfad0 From 26962ded19264ae1885386783c861d002d8fd1dc Mon Sep 17 00:00:00 2001 From: hut Date: Fri, 18 Jun 2010 11:44:53 +0200 Subject: all_benchmarks: shortened --- test/all_benchmarks.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'test/all_benchmarks.py') diff --git a/test/all_benchmarks.py b/test/all_benchmarks.py index e1b47142..20f11ad8 100755 --- a/test/all_benchmarks.py +++ b/test/all_benchmarks.py @@ -30,15 +30,7 @@ if __name__ == '__main__': modules = (fname[:-3] for fname in os.listdir(sys.path[0]) \ if fname[:3] == 'bm_' and fname[-3:] == '.py') - benchmarks = [] # find all benchmark (class, methodname) pairs - for val in [__import__(module) for module in modules]: - for cls in vars(val).values(): - if type(cls) == type: - for methodname in vars(cls): - if methodname.startswith('bm_'): - benchmarks.append((cls, methodname)) - - for cls, methodname in benchmarks: + def run_benchmark(cls, methodname): full_method_name = "{0}.{1}".format(cls.__name__, methodname) if all(re.search(full_method_name) for re in regexes): method = getattr(cls(), methodname) @@ -51,3 +43,10 @@ if __name__ == '__main__': else: t2 = time.time() print("{0:60}: {1:10}s".format(full_method_name, t2 - t1)) + + for val in [__import__(module) for module in modules]: + for cls in vars(val).values(): + if type(cls) == type: + for methodname in vars(cls): + if methodname.startswith('bm_'): + run_benchmark(cls, methodname) -- cgit 1.4.1-2-gfad0 From ec823be00aa7175ebcb836a240a20f6389159c2e Mon Sep 17 00:00:00 2001 From: hut Date: Sun, 29 Aug 2010 19:16:57 +0200 Subject: Removed symlink in test/ --- test/all_benchmarks.py | 8 ++++++-- test/all_tests.py | 6 +++++- test/bm_human_readable.py | 6 ++++++ test/bm_loader.py | 6 ++++++ test/ranger | 1 - test/tc_bookmarks.py | 6 ++++++ test/tc_colorscheme.py | 6 ++++++ test/tc_direction.py | 6 ++++++ test/tc_directory.py | 5 +++++ test/tc_displayable.py | 6 ++++++ test/tc_ext.py | 6 ++++++ test/tc_history.py | 6 ++++++ test/tc_human_readable.py | 6 ++++++ test/tc_keyapi.py | 6 ++++++ test/tc_loader.py | 6 ++++++ test/tc_newkeys.py | 10 +++++++--- test/tc_signal.py | 6 ++++++ test/tc_ui.py | 6 ++++++ test/tc_utfwidth.py | 8 +++++++- 19 files changed, 108 insertions(+), 8 deletions(-) delete mode 120000 test/ranger (limited to 'test/all_benchmarks.py') diff --git a/test/all_benchmarks.py b/test/all_benchmarks.py index 20f11ad8..a3612701 100755 --- a/test/all_benchmarks.py +++ b/test/all_benchmarks.py @@ -19,9 +19,13 @@ Run all the benchmarks inside this directory. Usage: ./all_benchmarks.py [count] [regexp-filters...] """ -import os -import re +import os.path import sys +rangerpath = os.path.join(os.path.dirname(__file__), '..') +if sys.path[1] != rangerpath: + sys.path[1:1] = [rangerpath] + +import re import time if __name__ == '__main__': diff --git a/test/all_tests.py b/test/all_tests.py index 7cfc855f..0c184df5 100755 --- a/test/all_tests.py +++ b/test/all_tests.py @@ -19,8 +19,12 @@ Run all the tests inside this directory as a test suite. Usage: ./all_tests.py [verbosity] """ -import os +import os.path import sys +rangerpath = os.path.join(os.path.dirname(__file__), '..') +if sys.path[1] != rangerpath: + sys.path[1:1] = [rangerpath] + import unittest if __name__ == '__main__': diff --git a/test/bm_human_readable.py b/test/bm_human_readable.py index 83f2a057..ef400774 100644 --- a/test/bm_human_readable.py +++ b/test/bm_human_readable.py @@ -13,6 +13,12 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import os.path +import sys +rangerpath = os.path.join(os.path.dirname(__file__), '..') +if sys.path[1] != rangerpath: + sys.path[1:1] = [rangerpath] + from ranger.ext.human_readable import * # The version before 2010/06/24: diff --git a/test/bm_loader.py b/test/bm_loader.py index 968640a5..552954a7 100644 --- a/test/bm_loader.py +++ b/test/bm_loader.py @@ -13,6 +13,12 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import os.path +import sys +rangerpath = os.path.join(os.path.dirname(__file__), '..') +if sys.path[1] != rangerpath: + sys.path[1:1] = [rangerpath] + from ranger.core.loader import Loader from ranger.fsobject import Directory, File from ranger.ext.openstruct import OpenStruct diff --git a/test/ranger b/test/ranger deleted file mode 120000 index 5459458c..00000000 --- a/test/ranger +++ /dev/null @@ -1 +0,0 @@ -../ranger \ No newline at end of file diff --git a/test/tc_bookmarks.py b/test/tc_bookmarks.py index 9b41f1c6..59435f06 100644 --- a/test/tc_bookmarks.py +++ b/test/tc_bookmarks.py @@ -13,6 +13,12 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import os.path +import sys +rangerpath = os.path.join(os.path.dirname(__file__), '..') +if sys.path[1] != rangerpath: + sys.path[1:1] = [rangerpath] + from os.path import realpath, join, dirname import unittest import os diff --git a/test/tc_colorscheme.py b/test/tc_colorscheme.py index 8d6adee6..eefb1e4f 100644 --- a/test/tc_colorscheme.py +++ b/test/tc_colorscheme.py @@ -13,6 +13,12 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import os.path +import sys +rangerpath = os.path.join(os.path.dirname(__file__), '..') +if sys.path[1] != rangerpath: + sys.path[1:1] = [rangerpath] + from unittest import TestCase, main import random import ranger.colorschemes diff --git a/test/tc_direction.py b/test/tc_direction.py index 5c1776cf..16c26dab 100644 --- a/test/tc_direction.py +++ b/test/tc_direction.py @@ -13,6 +13,12 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import os.path +import sys +rangerpath = os.path.join(os.path.dirname(__file__), '..') +if sys.path[1] != rangerpath: + sys.path[1:1] = [rangerpath] + import unittest from ranger.ext.direction import Direction from ranger.ext.openstruct import OpenStruct diff --git a/test/tc_directory.py b/test/tc_directory.py index a702c4db..754253b3 100644 --- a/test/tc_directory.py +++ b/test/tc_directory.py @@ -13,7 +13,12 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import os.path import sys +rangerpath = os.path.join(os.path.dirname(__file__), '..') +if sys.path[1] != rangerpath: + sys.path[1:1] = [rangerpath] + from os.path import realpath, join, dirname from ranger import fsobject diff --git a/test/tc_displayable.py b/test/tc_displayable.py index 1c66a40e..72e0507d 100644 --- a/test/tc_displayable.py +++ b/test/tc_displayable.py @@ -13,6 +13,12 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import os.path +import sys +rangerpath = os.path.join(os.path.dirname(__file__), '..') +if sys.path[1] != rangerpath: + sys.path[1:1] = [rangerpath] + import unittest import curses from random import randint diff --git a/test/tc_ext.py b/test/tc_ext.py index 919f35a2..495591a1 100644 --- a/test/tc_ext.py +++ b/test/tc_ext.py @@ -13,6 +13,12 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import os.path +import sys +rangerpath = os.path.join(os.path.dirname(__file__), '..') +if sys.path[1] != rangerpath: + sys.path[1:1] = [rangerpath] + import unittest from collections import deque diff --git a/test/tc_history.py b/test/tc_history.py index 301ebedd..02a8bb9f 100644 --- a/test/tc_history.py +++ b/test/tc_history.py @@ -13,6 +13,12 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import os.path +import sys +rangerpath = os.path.join(os.path.dirname(__file__), '..') +if sys.path[1] != rangerpath: + sys.path[1:1] = [rangerpath] + from ranger.container import History from unittest import TestCase, main import unittest diff --git a/test/tc_human_readable.py b/test/tc_human_readable.py index b931ba21..493e6d3a 100644 --- a/test/tc_human_readable.py +++ b/test/tc_human_readable.py @@ -13,6 +13,12 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import os.path +import sys +rangerpath = os.path.join(os.path.dirname(__file__), '..') +if sys.path[1] != rangerpath: + sys.path[1:1] = [rangerpath] + import unittest from ranger.ext.human_readable import human_readable as hr diff --git a/test/tc_keyapi.py b/test/tc_keyapi.py index 48282a7d..79d89fa5 100644 --- a/test/tc_keyapi.py +++ b/test/tc_keyapi.py @@ -13,6 +13,12 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import os.path +import sys +rangerpath = os.path.join(os.path.dirname(__file__), '..') +if sys.path[1] != rangerpath: + sys.path[1:1] = [rangerpath] + from unittest import TestCase, main class Test(TestCase): diff --git a/test/tc_loader.py b/test/tc_loader.py index 9f7f7322..5a2e5a68 100644 --- a/test/tc_loader.py +++ b/test/tc_loader.py @@ -13,6 +13,12 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import os.path +import sys +rangerpath = os.path.join(os.path.dirname(__file__), '..') +if sys.path[1] != rangerpath: + sys.path[1:1] = [rangerpath] + import unittest import os from os.path import realpath, join, dirname diff --git a/test/tc_newkeys.py b/test/tc_newkeys.py index fd856f17..c9597201 100644 --- a/test/tc_newkeys.py +++ b/test/tc_newkeys.py @@ -12,7 +12,13 @@ # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with this program. If not, see . + +import os.path +import sys +rangerpath = os.path.join(os.path.dirname(__file__), '..') +if sys.path[1] != rangerpath: + sys.path[1:1] = [rangerpath] +sys.path[1:1] = ['..'] from unittest import TestCase, main @@ -22,8 +28,6 @@ from ranger.container.keymap import * from ranger.container.keybuffer import KeyBuffer from ranger.ext.keybinding_parser import parse_keybinding -import sys - def simulate_press(self, string): for char in parse_keybinding(string): self.add(char) diff --git a/test/tc_signal.py b/test/tc_signal.py index f31681f4..3b1bac40 100644 --- a/test/tc_signal.py +++ b/test/tc_signal.py @@ -13,6 +13,12 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import os.path +import sys +rangerpath = os.path.join(os.path.dirname(__file__), '..') +if sys.path[1] != rangerpath: + sys.path[1:1] = [rangerpath] + import unittest import gc from ranger.ext.signal_dispatcher import * diff --git a/test/tc_ui.py b/test/tc_ui.py index dc8d669d..fa2bdcac 100644 --- a/test/tc_ui.py +++ b/test/tc_ui.py @@ -13,6 +13,12 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import os.path +import sys +rangerpath = os.path.join(os.path.dirname(__file__), '..') +if sys.path[1] != rangerpath: + sys.path[1:1] = [rangerpath] + import unittest import curses diff --git a/test/tc_utfwidth.py b/test/tc_utfwidth.py index 2aa5fa6d..0288c17b 100644 --- a/test/tc_utfwidth.py +++ b/test/tc_utfwidth.py @@ -12,7 +12,13 @@ # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with this program. If not, see . + +import os.path +import sys +rangerpath = os.path.join(os.path.dirname(__file__), '..') +if sys.path[1] != rangerpath: + sys.path[1:1] = [rangerpath] +sys.path[1:1] = ['..'] from unittest import TestCase, main from ranger.ext.utfwidth import * -- cgit 1.4.1-2-gfad0