diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/ZIP/ZIP.py | 41 | ||||
-rw-r--r-- | test/ZIP/ZIPROOT.py | 46 | ||||
-rw-r--r-- | test/ZIP/ZIP_OVERRIDE_TIMESTAMP.py | 68 |
3 files changed, 89 insertions, 66 deletions
diff --git a/test/ZIP/ZIP.py b/test/ZIP/ZIP.py index f842caf..b79173c 100644 --- a/test/ZIP/ZIP.py +++ b/test/ZIP/ZIP.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,9 +22,6 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os import stat @@ -33,30 +32,6 @@ _python_ = TestSCons._python_ test = TestSCons.TestSCons() -try: - import zipfile -except ImportError: - x = "Python version has no 'ziplib' module; skipping tests.\n" - test.skip_test(x) - -def zipfile_contains(zipfilename, names): - """Returns True if zipfilename contains all the names, False otherwise.""" - zf=zipfile.ZipFile(zipfilename, 'r') - if type(names)==type(''): - names=[names] - for name in names: - try: - info=zf.getinfo(name) - except KeyError as e: # name not found - zf.close() - return False - return True - -def zipfile_files(fname): - """Returns all the filenames in zip file fname.""" - zf = zipfile.ZipFile(fname, 'r') - return [x.filename for x in zf.infolist()] - test.subdir('sub1') test.write('SConstruct', """ @@ -78,12 +53,12 @@ test.write(['sub1', 'file6'], "sub1/file6\n") test.run(arguments = 'aaa.zip', stderr = None) test.must_exist('aaa.zip') -test.fail_test(not zipfile_contains('aaa.zip', ['file1', 'file2', 'file3'])) +test.fail_test(not test.zipfile_contains('aaa.zip', ['file1', 'file2', 'file3'])) test.run(arguments = 'bbb.zip', stderr = None) test.must_exist('bbb.zip') -test.fail_test(not zipfile_contains('bbb.zip', ['sub1/file5', 'sub1/file6', 'file4'])) +test.fail_test(not test.zipfile_contains('bbb.zip', ['sub1/file5', 'sub1/file6', 'file4'])) ###### @@ -136,11 +111,11 @@ test.run(arguments = '.', stderr = None) test.must_not_exist(test.workpath('f3.zip')) test.must_exist(test.workpath('f3.xyzzy')) -test.fail_test(zipfile_files("f1.zip") != ['file10', 'file11', 'file12']) +test.fail_test(test.zipfile_files("f1.zip") != ['file10', 'file11', 'file12']) -test.fail_test(zipfile_files("f2.zip") != ['file13', 'file14', 'file15']) +test.fail_test(test.zipfile_files("f2.zip") != ['file13', 'file14', 'file15']) -test.fail_test(zipfile_files("f3.xyzzy") != ['file16', 'file17', 'file18']) +test.fail_test(test.zipfile_files("f3.xyzzy") != ['file16', 'file17', 'file18']) f4_size = os.stat('f4.zip')[stat.ST_SIZE] f4stored_size = os.stat('f4stored.zip')[stat.ST_SIZE] diff --git a/test/ZIP/ZIPROOT.py b/test/ZIP/ZIPROOT.py index 24e82eb..10e01d9 100644 --- a/test/ZIP/ZIPROOT.py +++ b/test/ZIP/ZIPROOT.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,9 +22,6 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import TestSCons @@ -33,23 +32,6 @@ test = TestSCons.TestSCons() import zipfile -def zipfile_contains(zipfilename, names): - """Returns True if zipfilename contains all the names, False otherwise.""" - zf=zipfile.ZipFile(zipfilename, 'r') - if type(names)==type(''): - names=[names] - for name in names: - try: - info=zf.getinfo(name) - except KeyError as e: # name not found - zf.close() - return False - return True - -def zipfile_files(fname): - """Returns all the filenames in zip file fname.""" - zf = zipfile.ZipFile(fname, 'r') - return [x.filename for x in zf.infolist()] test.subdir('sub1') test.subdir(['sub1', 'sub2']) @@ -69,13 +51,12 @@ test.run(arguments = 'aaa.zip', stderr = None) test.must_exist('aaa.zip') # TEST: Zip file should contain 'file1', not 'sub1/file1', because of ZIPROOT. -zf=zipfile.ZipFile('aaa.zip', 'r') -test.fail_test(zf.testzip() is not None) -zf.close() +with zipfile.ZipFile('aaa.zip', 'r') as zf: + test.fail_test(zf.testzip() is not None) -files=zipfile_files('aaa.zip') -test.fail_test(zipfile_files('aaa.zip') != ['file1'], - message='Zip file aaa.zip has wrong files: %s'%repr(files)) +files = test.zipfile_files('aaa.zip') +test.fail_test(test.zipfile_files('aaa.zip') != ['file1'], + message='Zip file aaa.zip has wrong files: %s' % repr(files)) ### @@ -84,13 +65,12 @@ test.run(arguments = 'bbb.zip', stderr = None) test.must_exist('bbb.zip') # TEST: Zip file should contain 'sub2/file2', not 'sub1/sub2/file2', because of ZIPROOT. -zf=zipfile.ZipFile('bbb.zip', 'r') -test.fail_test(zf.testzip() is not None) -zf.close() +with zipfile.ZipFile('bbb.zip', 'r') as zf: + test.fail_test(zf.testzip() is not None) -files=zipfile_files('bbb.zip') -test.fail_test(zipfile_files('bbb.zip') != ['file2', 'sub2/file2'], - message='Zip file bbb.zip has wrong files: %s'%repr(files)) +files = test.zipfile_files('bbb.zip') +test.fail_test(test.zipfile_files('bbb.zip') != ['file2', 'sub2/file2'], + message='Zip file bbb.zip has wrong files: %s' % repr(files)) test.pass_test() diff --git a/test/ZIP/ZIP_OVERRIDE_TIMESTAMP.py b/test/ZIP/ZIP_OVERRIDE_TIMESTAMP.py new file mode 100644 index 0000000..8904944 --- /dev/null +++ b/test/ZIP/ZIP_OVERRIDE_TIMESTAMP.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python +# +# MIT License +# +# Copyright The SCons Foundation +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + +import zipfile + + +def zipfile_get_file_datetime(zipfilename, fname): + """Returns the date_time of the given file with the archive.""" + with zipfile.ZipFile(zipfilename, 'r') as zf: + for info in zf.infolist(): + if info.filename == fname: + return info.date_time + + raise Exception("Unable to find %s" % fname) + + +test.write('SConstruct', """ +env = Environment(tools = ['zip']) +env.Zip(target = 'aaa.zip', source = ['file1'], ZIP_OVERRIDE_TIMESTAMP=(1983,3,11,1,2,2)) +""" % locals()) + +test.write(['file1'], "file1\n") + +test.run(arguments = 'aaa.zip', stderr = None) + +test.must_exist('aaa.zip') + +with zipfile.ZipFile('aaa.zip', 'r') as zf: + test.fail_test(zf.testzip() is not None) + +files = test.zipfile_files('aaa.zip') +test.fail_test(files != ['file1'], + message='Zip file aaa.zip has wrong files: %s' % repr(files)) + +date_time = zipfile_get_file_datetime('aaa.zip', 'file1') +test.fail_test(date_time != (1983, 3, 11, 1, 2, 2), + message="Zip file aaa.zip#file1 has wrong date_time: %s" % repr(date_time)) + +test.pass_test() |