From 43523c4ba81cb2836d4c70c6ab4ee374ceebaa4e Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 11 Sep 2011 18:54:03 +0100 Subject: Rename cmdtest.py so it does not conflict with cmdtest script. --- cmdtestlib.py | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 cmdtestlib.py (limited to 'cmdtestlib.py') diff --git a/cmdtestlib.py b/cmdtestlib.py new file mode 100644 index 0000000..29f7132 --- /dev/null +++ b/cmdtestlib.py @@ -0,0 +1,73 @@ +# Copyright 2011 Lars Wirzenius +# +# 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 . + + +__version__ = '0.0' + + +import os + + +class TestCase(object): + + def __init__(self, name, path_prefix): + self.name = name + self.path_prefix = path_prefix + + +class TestDir(object): + + '''Contain information about a directory of test cases.''' + + per_test_suffixes = ('args', 'script', 'stdin', 'stdout', 'stderr', + 'exit', 'setup', 'teardown') + + def __init__(self): + self.setup = None + self.setup_once = None + self.tests = [] + self.teardown = None + self.teardown_once = None + + def scan(self, dirname, filenames=None): + filenames = os.listdir(dirname) if filenames is None else filenames + + script_names = ['setup_once', 'setup', 'teardown', 'teardown_once'] + for name in script_names: + if name in filenames: + setattr(self, name, os.path.join(dirname, name)) + + prefixes = self.find_prefixes(filenames) + for prefix in prefixes: + test = TestCase(prefix, os.path.join(dirname, prefix)) + for suffix in self.per_test_suffixes: + name = '%s.%s' % (prefix, suffix) + if name in filenames: + value = os.path.join(dirname, name) + else: + value = None + setattr(test, suffix, value) + self.tests.append(test) + + def find_prefixes(self, filenames): + prefixes = set() + for filename in filenames: + for suffix in self.per_test_suffixes: + suffix = '.' + suffix + if filename.endswith(suffix): + prefix = filename[:-len(suffix)] + prefixes.add(prefix) + return sorted(list(prefixes)) + -- cgit v1.2.1