Debian Codegraph @

test/scons-time/run/config/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 specifying an alternate Python executable in a config file.
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 'config',
48 f"""\
49 python = r'{my_python_py}'
50 """,
51 )
52
53 test.write(
54 my_python_py,
55 fr"""#!{_python_}
56 import sys
57 profile = ''
58 for arg in sys.argv[1:]:
59 if arg.startswith('--profile='):
60 profile = arg[10:]
61 break
62 print('my_python.py: %s' % profile)
63 """,
64 )
65
66 os.chmod(my_python_py, 0o755)
67
68 test.run(arguments='run -f config foo.tar.gz')
69
70 prof0 = test.workpath('foo-000-0.prof')
71 prof1 = test.workpath('foo-000-1.prof')
72 prof2 = test.workpath('foo-000-2.prof')
73
74 test.must_match('foo-000-0.log', "my_python.py: %s\n" % prof0, mode='r')
75 test.must_match('foo-000-1.log', "my_python.py: %s\n" % prof1, mode='r')
76 test.must_match('foo-000-2.log', "my_python.py: %s\n" % prof2, mode='r')
77
78 test.pass_test()
79
80 # Local Variables:
81 # tab-width:4
82 # indent-tabs-mode:nil
83 # End:
84 # vim: set expandtab tabstop=4 shiftwidth=4: