Remove more unnecessary imports from test scripts.
[scons.git] / test / Repository / Local.py
1 #!/usr/bin/env python
2 #
3 # __COPYRIGHT__
4 #
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 #
24
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
26
27 import os.path
28
29 import TestSCons
30
31 test = TestSCons.TestSCons()
32
33 test.subdir('repository', ['repository', 'src'],
34             'work', ['work', 'src'])
35
36 repository_aaa_out = test.workpath('repository', 'aaa.out')
37 repository_build_bbb_1 = test.workpath('repository', 'build', 'bbb.1')
38 repository_build_bbb_2 = test.workpath('repository', 'build', 'bbb.2')
39 work_aaa_mid = test.workpath('work', 'aaa.mid')
40 work_aaa_out = test.workpath('work', 'aaa.out')
41 work_build_bbb_1 = test.workpath('work', 'build', 'bbb.1')
42 work_build_bbb_2 = test.workpath('work', 'build', 'bbb.2')
43
44 opts = "-Y " + test.workpath('repository')
45
46 #
47 test.write(['repository', 'SConstruct'], r"""
48 def copy(env, source, target):
49     source = str(source[0])
50     target = str(target[0])
51     print 'copy() < %s > %s' % (source, target)
52     open(target, "wb").write(open(source, "rb").read())
53
54 Build = Builder(action=copy)
55 env = Environment(BUILDERS={'Build':Build}, BBB='bbb')
56 env.Build('aaa.mid', 'aaa.in')
57 env.Build('aaa.out', 'aaa.mid')
58 Local('aaa.out')
59
60 Export("env")
61 VariantDir('build', 'src')
62 SConscript('build/SConscript')
63 """)
64
65 test.write(['repository', 'src', 'SConscript'], r"""
66 def bbb_copy(env, source, target):
67     target = str(target[0])
68     print 'bbb_copy()'
69     open(target, "wb").write(open('build/bbb.1', "rb").read())
70
71 Import("env")
72 env.Build('bbb.1', 'bbb.0')
73 env.Local('${BBB}.1')
74 env.Command('bbb.2', 'bbb.x', bbb_copy)
75 env.Depends('bbb.2', 'bbb.1')
76 """)
77
78 test.write(['repository', 'aaa.in'], "repository/aaa.in\n")
79 test.write(['repository', 'src', 'bbb.0'], "repository/src/bbb.0\n")
80 test.write(['repository', 'src', 'bbb.x'], "repository/src/bbb.x\n")
81
82 #
83 test.run(chdir = 'repository', options = opts, arguments = '.')
84
85 test.fail_test(test.read(repository_aaa_out) != "repository/aaa.in\n")
86 test.fail_test(test.read(repository_build_bbb_2) != "repository/src/bbb.0\n")
87
88 test.up_to_date(chdir = 'repository', options = opts, arguments = '.')
89
90 # Make the entire repository non-writable, so we'll detect
91 # if we try to write into it accidentally.
92 test.writable('repository', 0)
93
94 #
95 test.run(chdir = 'work', options = opts, arguments = 'aaa.out build/bbb.2')
96
97 test.fail_test(os.path.exists(work_aaa_mid))
98 test.fail_test(test.read(work_aaa_out) != "repository/aaa.in\n")
99 test.fail_test(test.read(work_build_bbb_1) != "repository/src/bbb.0\n")
100 test.fail_test(os.path.exists(work_build_bbb_2))
101
102 #
103 test.write(['work', 'aaa.in'], "work/aaa.in\n")
104
105 #
106 test.run(chdir = 'work', options = opts, arguments = '.')
107
108 test.fail_test(test.read(work_aaa_mid) != "work/aaa.in\n")
109 test.fail_test(test.read(work_aaa_out) != "work/aaa.in\n")
110
111 test.up_to_date(chdir = 'work', options = opts, arguments = '.')
112
113 #
114 test.pass_test()
115
116 # Local Variables:
117 # tab-width:4
118 # indent-tabs-mode:nil
119 # End:
120 # vim: set expandtab tabstop=4 shiftwidth=4: