diff options
author | Ian Bicking <ian@ianbicking.org> | 2005-09-07 20:55:50 +0000 |
---|---|---|
committer | Ian Bicking <ian@ianbicking.org> | 2005-09-07 20:55:50 +0000 |
commit | defc6e51bbbbb65782b5156a15133bad352ed7e9 (patch) | |
tree | 99ef8a93e73aa40a680a8756b355108f452c8d14 | |
parent | 6842b431ce8752d2e01e1aa88dc0dabd81e69a9b (diff) | |
download | paste-git-defc6e51bbbbb65782b5156a15133bad352ed7e9.tar.gz |
Added function to write files from a template
-rw-r--r-- | paste/fixture.py | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/paste/fixture.py b/paste/fixture.py index 8a1f27d..d1558fd 100644 --- a/paste/fixture.py +++ b/paste/fixture.py @@ -502,10 +502,12 @@ class TestFileEnvironment(object): # for py.test disabled = True - def __init__(self, base_path, script_path=None, + def __init__(self, base_path, template_path=None, + script_path=None, environ=None, cwd=None, start_clear=True, ignore_paths=None, ignore_hidden=True): self.base_path = base_path + self.template_path = template_path if environ is None: environ = os.environ.copy() self.environ = environ @@ -525,7 +527,7 @@ class TestFileEnvironment(object): def run(self, script, *args, **kw): __tracebackhide__ = True expect_error = _popget(kw, 'expect_error', False) - expect_stderr = _popget(kw, 'expect_stderr', False) + expect_stderr = _popget(kw, 'expect_stderr', expect_error) stdin = _popget(kw, 'stdin', None) printresult = _popget(kw, 'printresult', True) args = map(str, args) @@ -602,6 +604,21 @@ class TestFileEnvironment(object): shutil.rmtree(self.base_path) os.mkdir(self.base_path) + def writefile(self, path, content=None, + frompath=None): + full = os.path.join(self.base_path, path) + f = open(full, 'wb') + if content is not None: + f.write(content) + if frompath is not None: + if self.template_path: + frompath = os.path.join(self.template_path, frompath) + f2 = open(frompath, 'rb') + f.write(f2.read()) + f2.close() + f.close() + return FoundFile(self.base_path, path) + class ProcResult(object): def __init__(self, test_env, args, stdin, stdout, stderr, |