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__"
32 _python_ = TestSCons._python_
34 test = TestSCons.TestSCons()
39 zip = test.where_is('zip')
41 x = "Python version has no 'ziplib' module nor 'zip' utility; skipping tests.\n"
46 test.write('myzip.py', r"""\
50 def process(outfile, name):
51 if os.path.isdir(name):
52 list = os.listdir(name)
55 process(outfile, os.path.join(name, entry))
57 outfile.write(open(name, 'rb').read())
58 outfile = open(sys.argv[1], 'wb')
59 for infile in sys.argv[2:]:
60 process(outfile, infile)
65 test.write('SConstruct', """
66 env = Environment(tools = ['zip'],
67 ZIPCOM = r'%(_python_)s myzip.py $TARGET $SOURCES')
68 env.Zip(target = 'aaa.zip', source = ['file1', 'file2'])
69 env.Zip(target = 'aaa.zip', source = 'file3')
70 env.Zip(target = 'bbb', source = 'sub1')
71 env.Zip(target = 'bbb', source = 'file4')
74 test.write('file1', "file1\n")
75 test.write('file2', "file2\n")
76 test.write('file3', "file3\n")
77 test.write('file4', "file4\n")
79 test.write(['sub1', 'file5'], "sub1/file5\n")
80 test.write(['sub1', 'file6'], "sub1/file6\n")
82 test.run(arguments = 'aaa.zip', stderr = None)
84 test.fail_test(test.read('aaa.zip') != "file1\nfile2\nfile3\n")
86 test.run(arguments = 'bbb.zip', stderr = None)
88 test.fail_test(test.read('bbb.zip') != "sub1/file5\nsub1/file6\nfile4\n")
96 zf = zipfile.ZipFile(fname, 'r')
97 return [x.filename for x in zf.infolist()]
101 zip = test.detect('ZIP', 'zip')
102 unzip = test.where_is('unzip')
104 def files(fname, test=test, unzip=unzip):
105 test.run(program = unzip, arguments = "-l -qq %s" % fname)
106 lines = test.stdout().split("\n")[:-1]
108 return line.split()[-1]
109 return list(map(lastword, lines))
113 marker_out = test.workpath('marker.out').replace('\\', '\\\\')
115 test.write('SConstruct', """\
116 def marker(target, source, env):
117 open(r'%s', 'wb').write("marker\\n")
120 zipcom = f1.Dictionary('ZIPCOM')
121 if not type(zipcom) is types.ListType:
123 f2 = Environment(ZIPCOM = [Action(marker)] + zipcom)
124 f3 = Environment(ZIPSUFFIX = '.xyzzy')
125 f1.Zip(target = 'f1.zip', source = ['file10', 'file11'])
126 f1.Zip(target = 'f1.zip', source = 'file12')
127 f2.Zip(target = 'f2.zip', source = ['file13', 'file14'])
128 f2.Zip(target = 'f2.zip', source = 'file15')
129 f3.Zip(target = 'f3', source = 'file16')
130 f3.Zip(target = 'f3', source = ['file17', 'file18'])
133 sources = ['file10', 'file11', 'file12', 'file13', 'file14', 'file15']
134 f1.Zip(target = 'f4.zip', source = sources)
135 f1.Zip(target = 'f4stored.zip', source = sources,
136 ZIPCOMPRESSION = zipfile.ZIP_STORED)
137 f1.Zip(target = 'f4deflated.zip', source = sources,
138 ZIPCOMPRESSION = zipfile.ZIP_DEFLATED)
143 for f in ['file10', 'file11', 'file12',
144 'file13', 'file14', 'file15',
145 'file16', 'file17', 'file18']:
146 test.write(f, f + "\n")
148 test.run(arguments = 'f1.zip', stderr = None)
150 test.fail_test(os.path.exists(test.workpath('marker.out')))
152 test.fail_test(not os.path.exists(test.workpath('f1.zip')))
154 test.run(arguments = 'f2.zip', stderr = None)
156 test.fail_test(test.read('marker.out') != 'marker\n')
158 test.fail_test(not os.path.exists(test.workpath('f2.zip')))
160 test.run(arguments = '.', stderr = None)
162 test.fail_test(os.path.exists(test.workpath('f3.zip')))
163 test.fail_test(not os.path.exists(test.workpath('f3.xyzzy')))
165 test.fail_test(files("f1.zip") != ['file10', 'file11', 'file12'])
167 test.fail_test(files("f2.zip") != ['file13', 'file14', 'file15'])
169 test.fail_test(files("f3.xyzzy") != ['file16', 'file17', 'file18'])
172 f4_size = os.stat('f4.zip')[stat.ST_SIZE]
173 f4stored_size = os.stat('f4stored.zip')[stat.ST_SIZE]
174 f4deflated_size = os.stat('f4deflated.zip')[stat.ST_SIZE]
176 test.fail_test(f4_size != f4deflated_size)
177 test.fail_test(f4stored_size == f4deflated_size)
183 # indent-tabs-mode:nil
185 # vim: set expandtab tabstop=4 shiftwidth=4: