5 # Copyright The SCons Foundation
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:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
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.
31 _python_
= TestSCons
._python
_
33 test
= TestSCons
.TestSCons()
37 test
.write('SConstruct', """
38 _ = DefaultEnvironment(tools=[])
39 env = Environment(tools = ['zip'])
40 env.Zip(target = 'aaa.zip', source = ['file1', 'file2'])
41 env.Zip(target = 'aaa.zip', source = 'file3')
42 env.Zip(target = 'bbb', source = 'sub1')
43 env.Zip(target = 'bbb', source = 'file4')
46 test
.write('file1', "file1\n")
47 test
.write('file2', "file2\n")
48 test
.write('file3', "file3\n")
49 test
.write('file4', "file4\n")
51 test
.write(['sub1', 'file5'], "sub1/file5\n")
52 test
.write(['sub1', 'file6'], "sub1/file6\n")
54 test
.run(arguments
= 'aaa.zip', stderr
= None)
56 test
.must_exist('aaa.zip')
57 test
.fail_test(not test
.zipfile_contains('aaa.zip', ['file1', 'file2', 'file3']))
59 test
.run(arguments
= 'bbb.zip', stderr
= None)
61 test
.must_exist('bbb.zip')
62 test
.fail_test(not test
.zipfile_contains('bbb.zip', ['sub1/file5', 'sub1/file6', 'file4']))
66 marker_out
= test
.workpath('marker.out').replace('\\', '\\\\')
68 test
.write('SConstruct', """\
69 def marker(target, source, env):
70 open(r'%s', 'wb').write(b"marker\\n")
72 zipcom = f1.Dictionary('ZIPCOM')
73 if not isinstance(zipcom, list):
75 f2 = Environment(ZIPCOM = [Action(marker)] + zipcom)
76 f3 = Environment(ZIPSUFFIX = '.xyzzy')
77 f1.Zip(target = 'f1.zip', source = ['file10', 'file11'])
78 f1.Zip(target = 'f1.zip', source = 'file12')
79 f2.Zip(target = 'f2.zip', source = ['file13', 'file14'])
80 f2.Zip(target = 'f2.zip', source = 'file15')
81 f3.Zip(target = 'f3', source = 'file16')
82 f3.Zip(target = 'f3', source = ['file17', 'file18'])
85 sources = ['file10', 'file11', 'file12', 'file13', 'file14', 'file15']
86 f1.Zip(target = 'f4.zip', source = sources)
87 f1.Zip(target = 'f4stored.zip', source = sources,
88 ZIPCOMPRESSION = zipfile.ZIP_STORED)
89 f1.Zip(target = 'f4deflated.zip', source = sources,
90 ZIPCOMPRESSION = zipfile.ZIP_DEFLATED)
93 for f
in ['file10', 'file11', 'file12',
94 'file13', 'file14', 'file15',
95 'file16', 'file17', 'file18']:
96 test
.write(f
, (f
+ "\n").encode())
98 test
.run(arguments
= 'f1.zip', stderr
= None)
100 test
.must_not_exist(test
.workpath('marker.out'))
102 test
.must_exist(test
.workpath('f1.zip'))
104 test
.run(arguments
= 'f2.zip', stderr
= None)
106 test
.must_match('marker.out', 'marker\n')
108 test
.must_exist(test
.workpath('f2.zip'))
110 test
.run(arguments
= '.', stderr
= None)
112 test
.must_not_exist(test
.workpath('f3.zip'))
113 test
.must_exist(test
.workpath('f3.xyzzy'))
115 test
.fail_test(test
.zipfile_files("f1.zip") != ['file10', 'file11', 'file12'])
117 test
.fail_test(test
.zipfile_files("f2.zip") != ['file13', 'file14', 'file15'])
119 test
.fail_test(test
.zipfile_files("f3.xyzzy") != ['file16', 'file17', 'file18'])
121 f4_size
= os
.stat('f4.zip')[stat
.ST_SIZE
]
122 f4stored_size
= os
.stat('f4stored.zip')[stat
.ST_SIZE
]
123 f4deflated_size
= os
.stat('f4deflated.zip')[stat
.ST_SIZE
]
125 test
.fail_test(f4_size
!= f4deflated_size
)
126 test
.fail_test(f4stored_size
== f4deflated_size
)
132 # indent-tabs-mode:nil
134 # vim: set expandtab tabstop=4 shiftwidth=4: