summaryrefslogtreecommitdiffstats
path: root/src/engine/SCons/Options/PathOptionTests.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/SCons/Options/PathOptionTests.py')
-rw-r--r--src/engine/SCons/Options/PathOptionTests.py155
1 files changed, 147 insertions, 8 deletions
diff --git a/src/engine/SCons/Options/PathOptionTests.py b/src/engine/SCons/Options/PathOptionTests.py
index 358f8e7..9749ee7 100644
--- a/src/engine/SCons/Options/PathOptionTests.py
+++ b/src/engine/SCons/Options/PathOptionTests.py
@@ -23,6 +23,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+import os.path
import sys
import unittest
@@ -35,7 +36,9 @@ class PathOptionTestCase(unittest.TestCase):
def test_PathOption(self):
"""Test PathOption creation"""
opts = SCons.Options.Options()
- opts.Add(SCons.Options.PathOption('test', 'test option help', '/default/path'))
+ opts.Add(SCons.Options.PathOption('test',
+ 'test option help',
+ '/default/path'))
o = opts.options[0]
assert o.key == 'test', o.key
@@ -44,10 +47,124 @@ class PathOptionTestCase(unittest.TestCase):
assert not o.validator is None, o.validator
assert o.converter is None, o.converter
+ def test_PathExists(self):
+ """Test the PathExists validator"""
+ opts = SCons.Options.Options()
+ opts.Add(SCons.Options.PathOption('test',
+ 'test option help',
+ '/default/path',
+ SCons.Options.PathOption.PathExists))
+
+ test = TestCmd.TestCmd(workdir='')
+ test.write('exists', 'exists\n')
+
+ o = opts.options[0]
+
+ o.validator('X', test.workpath('exists'), {})
+
+ dne = test.workpath('does_not_exist')
+ try:
+ o.validator('X', dne, {})
+ except SCons.Errors.UserError, e:
+ assert str(e) == 'Path for option X does not exist: %s' % dne, e
+ except:
+ raise "did not catch expected UserError"
+
+ def test_PathIsDir(self):
+ """Test the PathIsDir validator"""
+ opts = SCons.Options.Options()
+ opts.Add(SCons.Options.PathOption('test',
+ 'test option help',
+ '/default/path',
+ SCons.Options.PathOption.PathIsDir))
+
+ test = TestCmd.TestCmd(workdir='')
+ test.subdir('dir')
+ test.write('file', "file\n")
+
+ o = opts.options[0]
+
+ o.validator('X', test.workpath('dir'), {})
+
+ f = test.workpath('file')
+ try:
+ o.validator('X', f, {})
+ except SCons.Errors.UserError, e:
+ assert str(e) == 'Directory path for option X is a file: %s' % f, e
+ except:
+ raise "did not catch expected UserError"
+
+ dne = test.workpath('does_not_exist')
+ try:
+ o.validator('X', dne, {})
+ except SCons.Errors.UserError, e:
+ assert str(e) == 'Directory path for option X does not exist: %s' % dne, e
+ except:
+ raise "did not catch expected UserError"
+
+ def test_PathIsDirCreate(self):
+ """Test the PathIsDirCreate validator"""
+ opts = SCons.Options.Options()
+ opts.Add(SCons.Options.PathOption('test',
+ 'test option help',
+ '/default/path',
+ SCons.Options.PathOption.PathIsDirCreate))
+
+ test = TestCmd.TestCmd(workdir='')
+ test.write('file', "file\n")
+
+ o = opts.options[0]
+
+ d = test.workpath('dir')
+ o.validator('X', d, {})
+ assert os.path.isdir(d)
+
+ f = test.workpath('file')
+ try:
+ o.validator('X', f, {})
+ except SCons.Errors.UserError, e:
+ assert str(e) == 'Path for option X is a file, not a directory: %s' % f, e
+ except:
+ raise "did not catch expected UserError"
+
+ def test_PathIsFile(self):
+ """Test the PathIsFile validator"""
+ opts = SCons.Options.Options()
+ opts.Add(SCons.Options.PathOption('test',
+ 'test option help',
+ '/default/path',
+ SCons.Options.PathOption.PathIsFile))
+
+ test = TestCmd.TestCmd(workdir='')
+ test.subdir('dir')
+ test.write('file', "file\n")
+
+ o = opts.options[0]
+
+ o.validator('X', test.workpath('file'), {})
+
+ d = test.workpath('d')
+ try:
+ o.validator('X', d, {})
+ except SCons.Errors.UserError, e:
+ assert str(e) == 'File path for option X does not exist: %s' % d, e
+ except:
+ raise "did not catch expected UserError"
+
+ dne = test.workpath('does_not_exist')
+ try:
+ o.validator('X', dne, {})
+ except SCons.Errors.UserError, e:
+ assert str(e) == 'File path for option X does not exist: %s' % dne, e
+ except:
+ raise "did not catch expected UserError"
+
def test_validator(self):
- """Test the PathOption validator"""
+ """Test the PathOption validator argument"""
opts = SCons.Options.Options()
- opts.Add(SCons.Options.PathOption('test', 'test option help', '/default/path'))
+ opts.Add(SCons.Options.PathOption('test',
+ 'test option help',
+ '/default/path'))
test = TestCmd.TestCmd(workdir='')
test.write('exists', 'exists\n')
@@ -56,12 +173,34 @@ class PathOptionTestCase(unittest.TestCase):
o.validator('X', test.workpath('exists'), {})
- caught = None
+ dne = test.workpath('does_not_exist')
+ try:
+ o.validator('X', dne, {})
+ except SCons.Errors.UserError, e:
+ expect = 'Path for option X does not exist: %s' % dne
+ assert str(e) == expect, e
+ else:
+ raise "did not catch expected UserError"
+
+ def my_validator(key, val, env):
+ raise Exception, "my_validator() got called for %s, %s!" % (key, val)
+
+ opts = SCons.Options.Options()
+ opts.Add(SCons.Options.PathOption('test2',
+ 'more help',
+ '/default/path/again',
+ my_validator))
+
+ o = opts.options[0]
+
try:
- o.validator('X', test.workpath('does_not_exist'), {})
- except SCons.Errors.UserError:
- caught = 1
- assert caught, "did not catch expected UserError"
+ o.validator('Y', 'value', {})
+ except Exception, e:
+ assert str(e) == 'my_validator() got called for Y, value!', e
+ else:
+ raise "did not catch expected exception from my_validator()"
+
+
if __name__ == "__main__":