Debian Codegraph @

test/scons-time/run/option/python.py

raw
1 #!/usr/bin/env python
2 #
3 # MIT License
4 #
5 # Copyright The SCons Foundation
6 #
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
14 #
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
17 #
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 """
27 Verify the run --python option to specify an alternatie Python executable.
28 """
29
30 import os
31
32 import TestSCons_time
33
34 from TestCmd import NEED_HELPER
35 from TestSCons_time import _python_
36
37 test = TestSCons_time.TestSCons_time()
38
39 if NEED_HELPER:
40 test.skip_test("Test host cannot directly execute scripts, skipping test\n")
41
42 test.write_sample_project('foo.tar.gz')
43
44 my_python_py = test.workpath('my_python.py')
45
46 test.write(
47 my_python_py,
48 fr"""#!{_python_}
49 import sys
50 profile = ''
51 for arg in sys.argv[1:]:
52 if arg.startswith('--profile='):
53 profile = arg[10:]
54 break
55 print('my_python.py: %s' % profile)
56 """,
57 )
58
59 os.chmod(my_python_py, 0o755)
60
61 test.run(arguments='run --python %s foo.tar.gz' % my_python_py)
62
63 prof0 = test.workpath('foo-000-0.prof')
64 prof1 = test.workpath('foo-000-1.prof')
65 prof2 = test.workpath('foo-000-2.prof')
66
67 test.must_match('foo-000-0.log', "my_python.py: %s\n" % prof0, mode='r')
68 test.must_match('foo-000-1.log', "my_python.py: %s\n" % prof1, mode='r')
69 test.must_match('foo-000-2.log', "my_python.py: %s\n" % prof2, mode='r')
70
71 test.pass_test()
72
73 # Local Variables:
74 # tab-width:4
75 # indent-tabs-mode:nil
76 # End:
77 # vim: set expandtab tabstop=4 shiftwidth=4: