diff --git a/test/box/xlog.test.py b/test/box/xlog.test.py index 09e0857698e178217f864b26d13991055e0b6fa4..3e3e2b4e9b11fabd636430dfe3b260261c91aa4b 100644 --- a/test/box/xlog.test.py +++ b/test/box/xlog.test.py @@ -126,5 +126,3 @@ admin("#box.space[0]") # cleanup server.stop() server.deploy() - -# vim: syntax=python diff --git a/test/lib/colorer.py b/test/lib/colorer.py index 642199eb43f0c1abfaa60577fa25b34223f6f6c5..2edfeb2cf2366defde29b22beae3ebe39706e81c 100644 --- a/test/lib/colorer.py +++ b/test/lib/colorer.py @@ -8,6 +8,69 @@ class Singleton(type): cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs) return cls._instances[cls] +class CSchema(object): + objects = {} + + def __init__(self): + self.main_objects = { + 'diff_mark': {}, + 'diff_in': {}, + 'diff_out': {}, + 'test_pass': {}, + 'test_fail': {}, + 'test_new': {}, + 'test_skip': {}, + 'test_disa': {}, + 'error': {}, + 'lerror': {}, + 'tail': {}, + 'ts_text': {}, + 'path': {}, + 'info': {}, + 'separator': {}, + 't_name': {}, + 'serv_text': {}, + 'version': {}, + 'tr_text': {}, + } + self.main_objects.update(self.objects) + +class SchemaAscetic(CSchema): + objects = { + 'diff_mark': {'fgcolor': 'magenta'}, + 'diff_in': {'fgcolor': 'green'}, + 'diff_out': {'fgcolor': 'red'}, + 'test_pass': {'fgcolor': 'green'}, + 'test_fail': {'fgcolor': 'red'}, + 'test_new': {'fgcolor': 'lblue'}, + 'test_skip': {'fgcolor': 'grey'}, + 'test_disa': {'fgcolor': 'grey'}, + 'error': {'fgcolor': 'red'}, + } + +class SchemaPretty(CSchema): + objects = { + 'diff_mark': {'fgcolor': 'magenta'}, + 'diff_in': {'fgcolor': 'blue'}, + 'diff_out': {'fgcolor': 'red'}, + 'test_pass': {'fgcolor': 'green'}, + 'test_fail': {'fgcolor': 'red'}, + 'test_new': {'fgcolor': 'lblue'}, + 'test_skip': {'fgcolor': 'grey'}, + 'test_disa': {'fgcolor': 'grey'}, + 'error': {'fgcolor': 'red'}, + 'lerror': {'fgcolor': 'lred'}, + 'tail': {'fgcolor': 'lblue'}, + 'ts_text': {'fgcolor': 'lmagenta'}, + 'path': {'fgcolor': 'green', 'bold':True}, + 'info': {'fgcolor': 'yellow', 'bold':True}, + 'separator': {'fgcolor': 'blue'}, + 't_name': {'fgcolor': 'lblue'}, + 'serv_text': {'fgcolor': 'lmagenta'}, + 'version': {'fgcolor': 'yellow', 'bold':True}, + 'tr_text': {'fgcolor': 'green'}, + } + class Colorer(object): """ Colorer/Styler based on VT220+ specifications (Not full). Based on: @@ -32,7 +95,7 @@ class Colorer(object): "lmagenta" : '1;35', "lcyan" : '1;36', "white" : '1;37', - } + } bgcolor = { "black" : '0;40', "red" : '0;41', @@ -66,6 +129,15 @@ class Colorer(object): self.stdout = sys.stdout self.is_term = self.stdout.isatty() self.colors = int(os.popen('tput colors').read()) if self.is_term else None + print os.getenv('TT_SCHEMA') + schema = os.getenv('TT_SCHEMA', 'ascetic') + if schema == 'ascetic': + self.schema = SchemaAscetic() + elif schema == 'pretty': + self.schema = SchemaPretty() + else: + self.schema = CSchema() + self.schema = self.schema.main_objects def set_stdout(self): sys.stdout = self @@ -75,6 +147,8 @@ class Colorer(object): def write(self, *args, **kwargs): flags = [] + if 'schema' in kwargs: + kwargs.update(self.schema[kwargs['schema']]) for i in self.attributes: if i in kwargs and kwargs[i] == True: flags.append(self.attributes[i]) @@ -95,11 +169,11 @@ class Colorer(object): def writeout_unidiff(self, diff): for i in diff: if i.startswith('+'): - self.write(i, fgcolor='blue') + self.write(i, schema='diff_in') elif i.startswith('-'): - self.write(i, fgcolor='red') + self.write(i, schema='diff_out') elif i.startswith('@'): - self.write(i, fgcolor='magenta') + self.write(i, schema='diff_mark') def flush(self): return self.stdout.flush() diff --git a/test/lib/tarantool_server.py b/test/lib/tarantool_server.py index b385a6894f4d1aaef24f4e5750bec19e81cac2a3..c331e62afc7c3840143ff7e4c01feb14bd3a357a 100644 --- a/test/lib/tarantool_server.py +++ b/test/lib/tarantool_server.py @@ -165,8 +165,8 @@ class TarantoolServer(Server): builddir = os.path.join(builddir, "src/box") path = builddir + os.pathsep + os.environ["PATH"] if not silent: - color_stdout("Looking for server binary in ", fgcolor='lmagenta') - color_stdout(path+" ...\n", fgcolor='green') + color_stdout("Looking for server binary in ", schema='serv_text') + color_stdout(path+" ...\n", schema='path') for _dir in path.split(os.pathsep): exe = os.path.join(_dir, self.default_bin_name) if os.access(exe, os.X_OK): @@ -186,15 +186,15 @@ class TarantoolServer(Server): self.valgrind_log = os.path.abspath(os.path.join(self.vardir, self.valgrind_log)) if not silent: - color_stdout("Installing the server ...\n", fgcolor='lmagenta') - color_stdout(" Found executable at ", fgcolor='lmagenta') - color_stdout(self.binary+'\n', fgcolor='green', bold=True) - color_stdout(" Creating and populating working directory in ", fgcolor='lmagenta') - color_stdout(self.vardir+' ...\n', fgcolor='green', bold=True) + color_stdout("Installing the server ...\n", schema='serv_text') + color_stdout(" Found executable at ", schema='serv_text') + color_stdout(self.binary+'\n', schema='path') + color_stdout(" Creating and populating working directory in ", schema='serv_text') + color_stdout(self.vardir+' ...\n', schema='path') if os.access(self.vardir, os.F_OK): if not silent: - color_stdout(" Found old vardir, deleting ...\n", fgcolor='lmagenta') + color_stdout(" Found old vardir, deleting ...\n", schema='serv_text') self.kill_old_server() self.cleanup() else: @@ -257,7 +257,7 @@ class TarantoolServer(Server): stderr = subprocess.STDOUT, stdout = subprocess.PIPE) retcode = _init.wait() if retcode: - sys.stderr.write("tarantool_box --init-storage error: \n%s\n" % _init.stdout.read()) + color_stdout("tarantool_box --init-storage error: \n%s\n" % _init.stdout.read(), schema='error') raise subprocess.CalledProcessError(retcode, cmd) def get_param(self, param): @@ -305,23 +305,23 @@ class TarantoolServer(Server): if self.is_started: if not silent: - color_stdout("The server is already started.\n", fgcolor='lred') + color_stdout("The server is already started.\n", schema='lerror') return if not silent: - color_stdout("Starting the server ...\n", fgcolor='lmagenta') + color_stdout("Starting the server ...\n", schema='serv_text') version = self.version() - color_stdout("Starting ", fgcolor='lmagenta') - color_stdout(os.path.basename(self.binary), " \n", fgcolor='green') - color_stdout(version, "\n", fgcolor='grey') + color_stdout("Starting ", schema='serv_text') + color_stdout(os.path.basename(self.binary), " \n", schema='path') + color_stdout(version, "\n", schema='version') check_port(self.port) args = self.prepare_args() if self.gdb: args = prepare_gdb(self.binary, args) - color_stdout("You started the server in gdb mode.\n", fgcolor='yellow', bold=True) - color_stdout("To attach, use `screen -r tnt-gdb`\n", fgcolor='yellow', bold=True) + color_stdout("You started the server in gdb mode.\n", schema='info') + color_stdout("To attach, use `screen -r tnt-gdb`\n", schema='info') elif self.valgrind: args = prepare_valgrind([self.binary] + args, self.valgrind_log, os.path.abspath(os.path.join(self.vardir, @@ -347,11 +347,11 @@ class TarantoolServer(Server): start up.""" if not self.is_started: if not silent: - color_stdout("The server is not started.\n", fgcolor='red') + color_stdout("The server is not started.\n", schema='lerror') return if not silent: - color_stdout("Stopping the server ...\n", fgcolor='lmagenta') + color_stdout("Stopping the server ...\n", schema='serv_text') if self.process == None: self.kill_old_server() @@ -429,7 +429,7 @@ class TarantoolServer(Server): return # Nothing to do if not silent: - color_stdout(" Found old server, pid {0}, killing ...".format(pid), fgcolor='yellow') + color_stdout(" Found old server, pid {0}, killing ...".format(pid), schema='info') try: os.kill(pid, signal.SIGTERM) @@ -452,10 +452,10 @@ class TarantoolServer(Server): return pid def print_log(self, lines): - color_stdout.write("\nLast {0} lines of Tarantool Log file:\n".format(lines), fgcolor='lred') + color_stdout("\nLast {0} lines of Tarantool Log file:\n".format(lines), schema='error') with open(os.path.join(self.vardir, 'tarantool.log'), 'r') as log: for i in log.readlines()[-lines:]: - color_stdout.write(i, fgcolor='grey') + color_stdout(i, schema='log') def wait_until_started(self): """Wait until the server is started and accepting connections""" diff --git a/test/lib/test_suite.py b/test/lib/test_suite.py index 0ac0133b6290fd985c1d38d569b62165e18aa840..c00008e89717d1dc4fc7cef41d15b69db967972e 100644 --- a/test/lib/test_suite.py +++ b/test/lib/test_suite.py @@ -35,7 +35,7 @@ def check_libs(): try: __import__(mod_name) except ImportError: - sys.stderr.write("\n\nNo %s library found\n" % mod_name) + color_stdout("\n\nNo %s library found\n" % mod_name, schema='error') sys.exit(1) @@ -89,7 +89,7 @@ def print_tail_n(filename, num_lines): with open(filename, "r+") as logfile: tail_n = collections.deque(logfile, num_lines) for line in tail_n: - color_stdout.write(line, fgcolor='lblue') + color_stdout(line, schema='tail') class Test: @@ -174,20 +174,20 @@ class Test: check_valgrind_log(server.valgrind_log) == False elif self.skip: - color_stdout("[ skip ]\n", fgcolor='grey') + color_stdout("[ skip ]\n", schema='test_skip') if os.path.exists(self.tmp_result): os.remove(self.tmp_result) elif self.is_executed_ok and self.is_equal_result and self.is_valgrind_clean: - color_stdout("[ pass ]\n", fgcolor='green') + color_stdout("[ pass ]\n", schema='test_pass') if os.path.exists(self.tmp_result): os.remove(self.tmp_result) elif (self.is_executed_ok and not self.is_equal_result and not os.path.isfile(self.result)): os.rename(self.tmp_result, self.result) - color_stdout("[ NEW ]\n", fgcolor='lblue') + color_stdout("[ new ]\n", schema='test_new') else: os.rename(self.tmp_result, self.reject) - color_stdout("[ FAIL ]\n" if not self.is_terminated else "[ TERMINATED ]\n", fgcolor='red') + color_stdout("[ fail ]\n", schema='test_fail') where = "" if not self.is_executed_ok: @@ -210,7 +210,7 @@ class Test: """Print 10 lines of client program output leading to test failure. Used to diagnose a failure of the client program""" - color_stdout(message, color='lred') + color_stdout(message, schema='error') print_tail_n(logfile, 10) def print_unidiff(self): @@ -218,7 +218,7 @@ class Test: to establish the cause of a failure when .test differs from .result.""" - color_stdout("\nTest failed! Result content mismatch:\n", fgcolor='lred') + color_stdout("\nTest failed! Result content mismatch:\n", schema='error') with open(self.result, "r") as result: with open(self.reject, "r") as reject: result_time = time.ctime(os.stat(self.result).st_mtime) @@ -282,11 +282,11 @@ class TestSuite: raise RuntimeError("Unknown server: core = {0}".format( self.ini["core"])) - color_stdout("Collecting tests in ", fgcolor='lmagenta') - color_stdout(repr(suite_path), fgcolor='green') - color_stdout(": ", self.ini["description"], ".\n", fgcolor='lmagenta') + color_stdout("Collecting tests in ", schema='ts_text') + color_stdout(repr(suite_path), schema='path') + color_stdout(": ", self.ini["description"], ".\n", schema='ts_text') self.server.find_tests(self, suite_path) - color_stdout("Found ", str(len(self.tests)), " tests.\n", fgcolor='green') + color_stdout("Found ", str(len(self.tests)), " tests.\n", schema='path') def run_all(self): """For each file in the test suite, run client program @@ -310,19 +310,19 @@ class TestSuite: shutil.copy(i, self.args.vardir) if self.args.start_and_exit: - color_stdout(" Start and exit requested, exiting...\n", fgcolor='yellow') + color_stdout(" Start and exit requested, exiting...\n", schema='info') exit(0) longsep = '='*70 shortsep = '-'*60 - color_stdout(longsep, "\n", fgcolor='blue') - color_stdout("TEST".ljust(48), fgcolor='lblue') - color_stdout("RESULT\n", fgcolor='green') - color_stdout(shortsep, "\n", fgcolor='blue') + color_stdout(longsep, "\n", schema='separator') + color_stdout("TEST".ljust(48), schema='t_name') + color_stdout("RESULT\n", schema='test_pass') + color_stdout(shortsep, "\n", schema='separator') failed_tests = [] try: for test in self.tests: - color_stdout(test.name.ljust(48), fgcolor='lblue') + color_stdout(test.name.ljust(48), schema='t_name') # for better diagnostics in case of a long-running test test_name = os.path.basename(test.name) @@ -330,7 +330,7 @@ class TestSuite: if (test_name in self.ini["disabled"] or not self.server.debug and test_name in self.ini["release_disabled"] or self.args.valgrind and test_name in self.ini["valgrind_disabled"]): - color_stdout("[ disabled ]\n", fgcolor='grey') + color_stdout("[ disabled ]\n", schema='t_name') else: test.run(self.server) if not test.passed(): @@ -339,17 +339,17 @@ class TestSuite: color_stdout('\n') raise finally: - color_stdout(shortsep, "\n", fgcolor='blue') + color_stdout(shortsep, "\n", schema='separator') self.server.stop(silent=False) self.server.cleanup() if failed_tests: color_stdout("Failed {0} tests: {1}.".format(len(failed_tests), ", ".join(failed_tests)), - fgcolor='red') + schema='error') if self.args.valgrind and check_valgrind_log(self.server.valgrind_log): - color_stdout(" Error! There were warnings/errors in valgrind log file:", fgcolor='red') + color_stdout(" Error! There were warnings/errors in valgrind log file:", schema='error') print_tail_n(self.server.valgrind_log, 20) return ['valgrind error in ' + self.suite_path] return failed_tests diff --git a/test/test-run.py b/test/test-run.py index 9e8f795680f90db480f4c47cff3b33279ab8df1c..ac780e79223ff9e20dd68baf3ec6b2f6dfd7d526 100755 --- a/test/test-run.py +++ b/test/test-run.py @@ -132,7 +132,7 @@ class Options: """Check the arguments for correctness.""" check_error = False if self.args.gdb and self.args.valgrind: - color_stdout("Error: option --gdb is not compatible with option --valgrind", fgcolor='red') + color_stdout("Error: option --gdb is not compatible with option --valgrind", schema='error') check_error = True if check_error: exit(-1) @@ -169,7 +169,7 @@ def main(): failed_tests = [] try: - color_stdout("Started {}\n".format(" ".join(sys.argv)), fgcolor='green') + color_stdout("Started {}\n".format(" ".join(sys.argv)), schema='tr_text') suite_names = [] if options.args.suites != []: suite_names = options.args.suites @@ -183,7 +183,7 @@ def main(): for suite in suites: failed_tests.extend(suite.run_all()) except RuntimeError as e: - color_stdout("\nFatal error: {0}. Execution aborted.\n".format(e), fgcolor='red') + color_stdout("\nFatal error: {0}. Execution aborted.\n".format(e), schema='error') if options.args.gdb: time.sleep(100) return (-1) @@ -191,9 +191,9 @@ def main(): os.chdir(oldcwd) if failed_tests and options.args.is_force: - color_stdout("\n===== {0} tests failed:".format(len(failed_tests))+"\n", fgcolor="red") + color_stdout("\n===== {0} tests failed:".format(len(failed_tests))+"\n", schema='error') for test in failed_tests: - color_stdout("----- "+test+"\n", fgcolor="yellow") + color_stdout("----- "+test+"\n", schema='info') return (-1 if failed_tests else 0)