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:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
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.
25 __revision__
= "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
29 _python_
= TestSCons
._python
_
31 test
= TestSCons
.TestSCons()
35 test
.write('mytex.py', r
"""
39 cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:r:', [])
40 base_name = os.path.splitext(arg[0])[0]
41 infile = open(arg[0], 'r')
42 out_file = open(base_name+'.dvi', 'w')
43 for l in infile.readlines():
49 test
.write('mylatex.py', r
"""
53 cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:r:', [])
54 base_name = os.path.splitext(arg[0])[0]
55 infile = open(arg[0], 'r')
56 out_file = open(base_name+'.dvi', 'w')
57 for l in infile.readlines():
63 test
.write('mydvips.py', r
"""
67 cmd_opts, args = getopt.getopt(sys.argv[1:], 'o:x', [])
69 for opt, arg in cmd_opts:
70 if opt == '-o': outfile = arg
71 else: opt_string = opt_string + ' ' + opt
72 infile = open(args[0], 'r')
73 out_file = open(outfile, 'w')
74 out_file.write(opt_string + "\n")
75 for l in infile.readlines():
81 test
.write('SConstruct', """
82 env = Environment(TEX = r'%(_python_)s mytex.py',
83 LATEX = r'%(_python_)s mylatex.py',
84 DVIPS = r'%(_python_)s mydvips.py', DVIPSFLAGS = '-x',
85 tools=['tex', 'latex', 'dvips'])
86 dvi = env.DVI(target = 'test1.dvi', source = 'test1.tex')
87 env.PostScript(target = 'test1.ps', source = dvi)
88 env.PostScript(target = 'test2.ps', source = 'test2.tex')
89 env.PostScript(target = 'test3.ps', source = 'test3.ltx')
90 env.PostScript(target = 'test4.ps', source = 'test4.latex')
93 test
.write('test1.tex', r
"""This is a .dvi test.
98 test
.write('test2.tex', r
"""This is a .tex test.
103 test
.write('test3.ltx', r
"""This is a .ltx test.
108 test
.write('test4.latex', r
"""This is a .latex test.
113 test
.run(arguments
= '.', stderr
= None)
115 test
.must_match('test1.ps', " -x\nThis is a .dvi test.\n", mode
='r')
117 test
.must_match('test2.ps', " -x\nThis is a .tex test.\n", mode
='r')
119 test
.must_match('test3.ps', " -x\nThis is a .ltx test.\n", mode
='r')
121 test
.must_match('test4.ps', " -x\nThis is a .latex test.\n", mode
='r')
124 dvips
= test
.where_is('dvips')
128 test
.write("wrapper.py", """
131 cmd = " ".join(sys.argv[1:])
132 with open('%s', 'a') as f:
133 f.write("%%s\\n" %% cmd)
134 subprocess.run(cmd, shell=True)
135 """ % test
.workpath('wrapper.out').replace('\\', '\\\\'))
137 test
.write('SConstruct', """
139 ENV = {'PATH' : os.environ['PATH']}
140 foo = Environment(ENV = ENV, DVIPSFLAGS = '-N')
141 dvips = foo.Dictionary('DVIPS')
142 bar = Environment(ENV = ENV,DVIPS = r'%(_python_)s wrapper.py ' + dvips)
143 foo.PostScript(target = 'foo.ps', source = 'foo.tex')
144 bar.PostScript(target = 'bar1', source = 'bar1.tex')
145 bar.PostScript(target = 'bar2', source = 'bar2.ltx')
146 bar.PostScript(target = 'bar3', source = 'bar3.latex')
150 This is the %s TeX file.
155 \documentclass{letter}
157 This is the %s LaTeX file.
161 test
.write('foo.tex', tex
% 'foo.tex')
162 test
.write('bar1.tex', tex
% 'bar1.tex')
163 test
.write('bar2.ltx', latex
% 'bar2.ltx')
164 test
.write('bar3.latex', latex
% 'bar3.latex')
166 test
.run(arguments
='foo.dvi', stderr
=None)
168 test
.must_not_exist(test
.workpath('wrapper.out'))
170 test
.must_exist(test
.workpath('foo.dvi'))
172 test
.run(arguments
='bar1.ps bar2.ps bar3.ps', stderr
=None)
174 expect
= """dvips -o bar1.ps bar1.dvi
175 dvips -o bar2.ps bar2.dvi
176 dvips -o bar3.ps bar3.dvi
179 test
.must_match('wrapper.out', expect
, mode
='r')
181 test
.must_exist(test
.workpath('bar1.ps'))
182 test
.must_exist(test
.workpath('bar2.ps'))
183 test
.must_exist(test
.workpath('bar3.ps'))
189 # indent-tabs-mode:nil
191 # vim: set expandtab tabstop=4 shiftwidth=4: