From 596492baa23623411d143186d9cad33a1305cd24 Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Thu, 4 Aug 2011 12:57:25 -0400 Subject: Added some fadfile commands to (re)generate tests when they are added or updated. --- fabfile.py | 16 ++++++++++++++++ tests/__init__.py | 43 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/fabfile.py b/fabfile.py index 9680bd1..007fd7f 100644 --- a/fabfile.py +++ b/fabfile.py @@ -61,6 +61,22 @@ def build_tests(version=_pyversion[:3]): local('2to3-%s -w build/test.%s/tests' % (version, version)) local('2to3-%s -w build/test.%s/run-tests.py' % (version, version)) +def generate_test(file): + """ Generate a given test. """ + import tests + config = tests.get_config(os.path.dirname(file)) + root, ext = os.path.splitext(file) + if ext == config.get(get_section(os.path.basename(root), config), + 'input_ext'): + tests.generate(root, config) + else: + print test, 'does not have a valid file extension. Check config.' + +def generate_tests(): + """ Generate all outdated tests. """ + from tests import generate_all + generate_all() + def build_env(version=_pyversion[:3]): """ Build testing environment for given Python version. """ if version in confirmed_versions: diff --git a/tests/__init__.py b/tests/__init__.py index 99eae44..26cc0d0 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -31,6 +31,15 @@ def relpath(path, start=test_dir): return test_dir return os.path.join(*rel_list) +def get_config(dir_name): + """ Get config for given directory name. """ + config = util.CustomConfigParser({'normalize': '0', + 'skip': '0', + 'input_ext': '.txt', + 'output_ext': '.html'}) + config.read(os.path.join(dir_name, 'test.cfg')) + return config + def get_section(file, config): """ Get name of config section for given file. """ filename = os.path.basename(file) @@ -99,11 +108,7 @@ class CheckSyntax(object): def TestSyntax(): for dir_name, sub_dirs, files in os.walk(test_dir): # Get dir specific config settings. - config = util.CustomConfigParser({'normalize': '0', - 'skip': '0', - 'input_ext': '.txt', - 'output_ext': '.html'}) - config.read(os.path.join(dir_name, 'test.cfg')) + config = get_config(dir_name) # Loop through files and generate tests. for file in files: root, ext = os.path.splitext(file) @@ -112,6 +117,34 @@ def TestSyntax(): check_syntax = CheckSyntax(description=relpath(path, test_dir)) yield check_syntax, path, config +def generate(file, config): + """ Write expected output file for given input. """ + cfg_section = get_section(file, config) + if config.get(cfg_section, 'skip'): + print 'Skipping:', file + return None + input_file = file + config.get(cfg_section, 'input_ext') + output_file = file + config.get(cfg_section, 'output_ext') + if not os.path.isfile(output_file) or \ + os.path.getmtime(output_file) < os.path.getmtime(input_file): + print 'Generating:', file + markdown.markdownFromFile(input=input_file, output=output_file, + encoding='utf-8', **get_args(file, config)) + else: + print 'Already up-to-date:', file + +def generate_all(): + """ Generate expected output for all outdated tests. """ + for dir_name, sub_dirs, files in os.walk(test_dir): + # Get dir specific config settings. + config = get_config(dir_name) + # Loop through files and generate tests. + for file in files: + root, ext = os.path.splitext(file) + if ext == config.get(get_section(file, config), 'input_ext'): + generate(os.path.join(dir_name, root), config) + + def run(): nose.main(addplugins=[HtmlOutput(), Markdown()]) -- cgit v1.2.3