summaryrefslogtreecommitdiffstats
path: root/etc
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2004-11-20 20:45:07 (GMT)
committerSteven Knight <knight@baldmt.com>2004-11-20 20:45:07 (GMT)
commit01bb3b17a76039f95bc7171f5e6a1a02709bfab3 (patch)
tree5eab4d2afb17727557b623e8ec7a25b614322912 /etc
parentf0593746a4dde6bd7cfa17043e7392c0690a38ae (diff)
downloadSCons-01bb3b17a76039f95bc7171f5e6a1a02709bfab3.zip
SCons-01bb3b17a76039f95bc7171f5e6a1a02709bfab3.tar.gz
SCons-01bb3b17a76039f95bc7171f5e6a1a02709bfab3.tar.bz2
Add more customizability: , , , .
Diffstat (limited to 'etc')
-rw-r--r--etc/TestCmd.py6
-rw-r--r--etc/TestCommon.py56
2 files changed, 57 insertions, 5 deletions
diff --git a/etc/TestCmd.py b/etc/TestCmd.py
index b90e653..e12aa4c 100644
--- a/etc/TestCmd.py
+++ b/etc/TestCmd.py
@@ -158,7 +158,7 @@ version.
TestCmd.where_is('foo', 'PATH1;PATH2', '.suffix3;.suffix4')
"""
-# Copyright 2000, 2001, 2002, 2003 Steven Knight
+# Copyright 2000, 2001, 2002, 2003, 2004 Steven Knight
# This module is free software, and you may redistribute it and/or modify
# it under the same terms as Python itself, so long as this copyright message
# and disclaimer are retained in their original form.
@@ -175,8 +175,8 @@ version.
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
__author__ = "Steven Knight <knight at baldmt dot com>"
-__revision__ = "TestCmd.py 0.12.D001 2004/10/21 14:00:53 knight"
-__version__ = "0.12"
+__revision__ = "TestCmd.py 0.13.D002 2004/11/20 08:34:16 knight"
+__version__ = "0.13"
import os
import os.path
diff --git a/etc/TestCommon.py b/etc/TestCommon.py
index 8ef9b3d..ae57f0c 100644
--- a/etc/TestCommon.py
+++ b/etc/TestCommon.py
@@ -32,12 +32,16 @@ TestCommon object; see the TestCmd documentation for details.
Here is an overview of the methods and keyword arguments that are
provided by the TestCommon class:
+ test.must_be_writable('file1', ['file2', ...])
+
test.must_contain('file', 'required text\n')
test.must_exist('file1', ['file2', ...])
test.must_match('file', "expected contents\n")
+ test.must_not_be_writable('file1', ['file2', ...])
+
test.must_not_exist('file1', ['file2', ...])
test.run(options = "options to be prepended to arguments",
@@ -76,11 +80,12 @@ The TestCommon module also provides the following variables
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
__author__ = "Steven Knight <knight at baldmt dot com>"
-__revision__ = "TestCommon.py 0.12.D001 2004/10/21 14:00:53 knight"
-__version__ = "0.12"
+__revision__ = "TestCommon.py 0.13.D001 2004/11/20 08:30:40 knight"
+__version__ = "0.13"
import os
import os.path
+import stat
import string
import sys
import types
@@ -145,6 +150,20 @@ def is_List(e):
return type(e) is types.ListType \
or isinstance(e, UserList.UserList)
+def is_writable(f):
+ mode = os.stat(f)[stat.ST_MODE]
+ return mode & stat.S_IWUSR
+
+def separate_files(flist):
+ existing = []
+ missing = []
+ for f in flist:
+ if os.path.exists(f):
+ existing.append(f)
+ else:
+ missing.append(f)
+ return existing, missing
+
class TestFailed(Exception):
def __init__(self, args=None):
self.args = args
@@ -193,6 +212,22 @@ class TestCommon(TestCmd):
apply(TestCmd.__init__, [self], kw)
os.chdir(self.workdir)
+ def must_be_writable(self, *files):
+ """Ensures that the specified file(s) exist and are writable.
+ An individual file can be specified as a list of directory names,
+ in which case the pathname will be constructed by concatenating
+ them. Exits FAILED if any of the files does not exist or is
+ not writable.
+ """
+ files = map(lambda x: is_List(x) and apply(os.path.join, x) or x, files)
+ existing, missing = separate_files(files)
+ unwritable = filter(lambda x, iw=is_writable: not iw(x), existing)
+ if missing:
+ print "Missing files: `%s'" % string.join(missing, "', `")
+ if unwritable:
+ print "Unwritable files: `%s'" % string.join(unwritable, "', `")
+ self.fail_test(missing + unwritable)
+
def must_contain(self, file, required, mode = 'rb'):
"""Ensures that the specified file contains the required text.
"""
@@ -247,6 +282,23 @@ class TestCommon(TestCmd):
print "Unexpected files exist: `%s'" % string.join(existing, "', `")
self.fail_test(existing)
+
+ def must_not_be_writable(self, *files):
+ """Ensures that the specified file(s) exist and are not writable.
+ An individual file can be specified as a list of directory names,
+ in which case the pathname will be constructed by concatenating
+ them. Exits FAILED if any of the files does not exist or is
+ writable.
+ """
+ files = map(lambda x: is_List(x) and apply(os.path.join, x) or x, files)
+ existing, missing = separate_files(files)
+ writable = filter(is_writable, existing)
+ if missing:
+ print "Missing files: `%s'" % string.join(missing, "', `")
+ if writable:
+ print "Writable files: `%s'" % string.join(writable, "', `")
+ self.fail_test(missing + writable)
+
def run(self, options = None, arguments = None,
stdout = None, stderr = '', status = 0, **kw):
"""Runs the program under test, checking that the test succeeded.