8534cf8d5c95d39990d5f6c140c832d299b5c439
[scons.git] / src / engine / SCons / DefaultsTests.py
1 #
2 # __COPYRIGHT__
3 #
4 # Permission is hereby granted, free of charge, to any person obtaining
5 # a copy of this software and associated documentation files (the
6 # "Software"), to deal in the Software without restriction, including
7 # without limitation the rights to use, copy, modify, merge, publish,
8 # distribute, sublicense, and/or sell copies of the Software, and to
9 # permit persons to whom the Software is furnished to do so, subject to
10 # the following conditions:
11 #
12 # The above copyright notice and this permission notice shall be included
13 # in all copies or substantial portions of the Software.
14 #
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
16 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
17 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 #
23
24 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
25
26 import os
27 import os.path
28 import StringIO
29 import sys
30 import types
31 import unittest
32
33 from UserDict import UserDict
34
35 import TestCmd
36
37 import SCons.Errors
38
39 from SCons.Defaults import *
40
41 class DefaultsTestCase(unittest.TestCase):
42     def test_mkdir_func0(self):
43         test = TestCmd.TestCmd(workdir = '')
44         test.subdir('sub')
45         subdir2 = test.workpath('sub', 'dir1', 'dir2')
46         # Simple smoke test
47         mkdir_func(subdir2)
48         mkdir_func(subdir2)     # 2nd time should be OK too
49
50     def test_mkdir_func1(self):
51         test = TestCmd.TestCmd(workdir = '')
52         test.subdir('sub')
53         subdir1 = test.workpath('sub', 'dir1')
54         subdir2 = test.workpath('sub', 'dir1', 'dir2')
55         # No error if asked to create existing dir
56         os.makedirs(subdir2)
57         mkdir_func(subdir2)
58         mkdir_func(subdir1)
59
60     def test_mkdir_func2(self):
61         test = TestCmd.TestCmd(workdir = '')
62         test.subdir('sub')
63         subdir1 = test.workpath('sub', 'dir1')
64         subdir2 = test.workpath('sub', 'dir1', 'dir2')
65         file = test.workpath('sub', 'dir1', 'dir2', 'file')
66
67         # make sure it does error if asked to create a dir
68         # where there's already a file
69         os.makedirs(subdir2)
70         test.write(file, "test\n")
71         try:
72             mkdir_func(file)
73         except os.error, e:
74             pass
75         else:
76             fail("expected os.error")
77         
78
79 if __name__ == "__main__":
80     suite = unittest.TestSuite()
81     tclasses = [ DefaultsTestCase,
82                ]
83     for tclass in tclasses:
84         names = unittest.getTestCaseNames(tclass, 'test_')
85         suite.addTests(list(map(tclass, names)))
86     if not unittest.TextTestRunner().run(suite).wasSuccessful():
87         sys.exit(1)
88
89 # Local Variables:
90 # tab-width:4
91 # indent-tabs-mode:nil
92 # End:
93 # vim: set expandtab tabstop=4 shiftwidth=4: