From 053be941832d384db748c44b294b03ce20bea8d1 Mon Sep 17 00:00:00 2001 From: ndparker Date: Wed, 12 Feb 2014 22:57:04 +0100 Subject: [PATCH] make the tests releasable --- make.py | 89 +-------------------------- package.cfg | 6 ++ run_tests.py | 165 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 174 insertions(+), 86 deletions(-) create mode 100755 run_tests.py diff --git a/make.py b/make.py index ccf834b..9327e5b 100755 --- a/make.py +++ b/make.py @@ -95,92 +95,9 @@ class Test(Target): DEPS = ["compile-quiet"] def run(self): - run_output_tests(self.dirs['tests']) - - -def run_output_tests(basedir): - """ Run output based tests """ - import rcssmin as _rcssmin - py_cssmin = _rcssmin._make_cssmin(python_only=True) - c_cssmin = _rcssmin._make_cssmin(python_only=False) - - def run_test(example, output_file): - """ Run it """ - try: - fp = open(example, 'r') - except IOError: - return - else: - try: - input = fp.read() - finally: - fp.close() - - def load_output(filename): - try: - fp = open(filename, 'r') - except IOError: - return None - else: - try: - output = fp.read() - finally: - fp.close() - output = output.strip() - if _re.search(r'(? %s" % (dirname[strip:],)) - files.sort() - for filename in files: - run_test( - _os.path.join(dirname, filename), - _os.path.join(dirname, 'out', filename[:-4] + '.out'), - ) - term.yellow("<--- %s" % (dirname[strip:],)) + if shell.spawn(_sys.executable, 'run_tests.py', + self.dirs['tests'], self.dirs['lib'] + ): raise RuntimeError('tests failed') class Benchmark(Target): diff --git a/package.cfg b/package.cfg index 3249ee3..eb5018f 100644 --- a/package.cfg +++ b/package.cfg @@ -70,8 +70,14 @@ extra = #packages.collect = modules = rcssmin +packages.extra = + _setup.py2.term + _setup.py3.term + #scripts = dist = + tests + run_tests.py bench.py bench diff --git a/run_tests.py b/run_tests.py new file mode 100755 index 0000000..88759f9 --- /dev/null +++ b/run_tests.py @@ -0,0 +1,165 @@ +#!/usr/bin/env python +# -*- coding: ascii -*- +# +# Copyright 2014 +# Andr\xe9 Malo or his licensors, as applicable +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +""" +=========== + Run tests +=========== + +Run tests. +""" +__author__ = u"Andr\xe9 Malo" +__docformat__ = "restructuredtext en" + +import os as _os +import re as _re +import sys as _sys + +from _setup import shell +from _setup import term + + +def run_tests(basedir, libdir): + """ Run output based tests """ + import rcssmin as _rcssmin + py_cssmin = _rcssmin._make_cssmin(python_only=True) + c_cssmin = _rcssmin._make_cssmin(python_only=False) + + def run_test(example, output_file): + """ Run it """ + try: + fp = open(example, 'r') + except IOError: + return + else: + try: + input = fp.read() + finally: + fp.close() + + def load_output(filename): + try: + fp = open(filename, 'r') + except IOError: + return None + else: + try: + output = fp.read() + finally: + fp.close() + output = output.strip() + if _re.search(r'(? %s" % (dirname[strip:],)) + files.sort() + for filename in files: + if run_test( + _os.path.join(dirname, filename), + _os.path.join(dirname, 'out', filename[:-4] + '.out'), + ): erred = 1 + term.yellow("<--- %s" % (dirname[strip:],)) + return erred + + +def main(): + """ Main """ + basedir, libdir = None, None + accept_opts = True + args = [] + for arg in _sys.argv[1:]: + if accept_opts: + if arg == '--': + accept_opts = False + continue + elif arg == '-q': + term.write = term.green = term.red = term.yellow = \ + term.announce = \ + lambda fmt, **kwargs: None + continue + elif arg == '-p': + info = {} + for key in term.terminfo(): + info[key] = '' + info['ERASE'] = '\n' + term.terminfo.info = info + continue + elif arg.startswith('-'): + _sys.stderr.write("Unrecognized option %r\n" % (arg,)) + return 2 + args.append(arg) + if len(args) > 2: + _sys.stderr.write("Too many arguments\n") + return 2 + elif len(args) < 1: + _sys.stderr.write("Missing arguments\n") + return 2 + basedir = args[0] + if len(args) > 1: + libdir = args[1] + return run_tests(basedir, libdir) + + +if __name__ == '__main__': + _sys.exit(main())