diff options
author | Lars Wirzenius <liw@liw.fi> | 2011-09-11 18:54:03 +0100 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2011-09-11 18:54:03 +0100 |
commit | 43523c4ba81cb2836d4c70c6ab4ee374ceebaa4e (patch) | |
tree | 6cf5e16b9b47873883f4403d5cf136450aa9d12f /cmdtestlib.py | |
parent | 18a3f1062d8ce7590bbd94b32ab8bbb812000f59 (diff) | |
download | cmdtest-43523c4ba81cb2836d4c70c6ab4ee374ceebaa4e.tar.gz |
Rename cmdtest.py so it does not conflict with cmdtest script.
Diffstat (limited to 'cmdtestlib.py')
-rw-r--r-- | cmdtestlib.py | 73 |
1 files changed, 73 insertions, 0 deletions
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 <http://www.gnu.org/licenses/>. + + +__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)) + |