| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import os | 6 import os |
| 7 import oshelpers | |
| 8 import shutil | 7 import shutil |
| 9 import subprocess | 8 import subprocess |
| 10 import sys | 9 import sys |
| 11 import tempfile | 10 import tempfile |
| 12 import unittest | 11 import unittest |
| 13 import zipfile | 12 import zipfile |
| 14 | 13 |
| 14 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 15 PARENT_DIR = os.path.dirname(SCRIPT_DIR) |
| 16 |
| 17 sys.path.append(PARENT_DIR) |
| 18 |
| 19 import oshelpers |
| 15 | 20 |
| 16 class RunZipError(subprocess.CalledProcessError): | 21 class RunZipError(subprocess.CalledProcessError): |
| 17 def __init__(self, retcode, command, output, error_output): | 22 def __init__(self, retcode, command, output, error_output): |
| 18 subprocess.CalledProcessError.__init__(self, retcode, command) | 23 subprocess.CalledProcessError.__init__(self, retcode, command) |
| 19 self.output = output | 24 self.output = output |
| 20 self.error_output = error_output | 25 self.error_output = error_output |
| 21 | 26 |
| 22 def __str__(self): | 27 def __str__(self): |
| 23 msg = subprocess.CalledProcessError.__str__(self) | 28 msg = subprocess.CalledProcessError.__str__(self) |
| 24 msg += '.\nstdout: """%s"""' % (self.output,) | 29 msg += '.\nstdout: """%s"""' % (self.output,) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 39 raise RunZipError(retcode, command, output, error_output) | 44 raise RunZipError(retcode, command, output, error_output) |
| 40 return output, error_output | 45 return output, error_output |
| 41 | 46 |
| 42 | 47 |
| 43 class TestZip(unittest.TestCase): | 48 class TestZip(unittest.TestCase): |
| 44 def setUp(self): | 49 def setUp(self): |
| 45 # make zipname -> "testFooBar.zip" | 50 # make zipname -> "testFooBar.zip" |
| 46 self.zipname = self.id().split('.')[-1] + '.zip' | 51 self.zipname = self.id().split('.')[-1] + '.zip' |
| 47 self.zipfile = None | 52 self.zipfile = None |
| 48 self.tempdir = tempfile.mkdtemp() | 53 self.tempdir = tempfile.mkdtemp() |
| 49 shutil.copy(os.path.join(os.path.dirname(__file__), 'oshelpers.py'), | 54 shutil.copy(os.path.join(PARENT_DIR, 'oshelpers.py'), |
| 50 self.tempdir) | 55 self.tempdir) |
| 51 | 56 |
| 52 def tearDown(self): | 57 def tearDown(self): |
| 53 if self.zipfile: | 58 if self.zipfile: |
| 54 self.zipfile.close() | 59 self.zipfile.close() |
| 55 shutil.rmtree(self.tempdir) | 60 shutil.rmtree(self.tempdir) |
| 56 | 61 |
| 57 def GetTempPath(self, basename): | 62 def GetTempPath(self, basename): |
| 58 return os.path.join(self.tempdir, basename) | 63 return os.path.join(self.tempdir, basename) |
| 59 | 64 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 self.CloseZipFile() | 182 self.CloseZipFile() |
| 178 | 183 |
| 179 file3 = self.MakeFile('file3', 768) | 184 file3 = self.MakeFile('file3', 768) |
| 180 self.RunZip([self.zipname, file3]) | 185 self.RunZip([self.zipname, file3]) |
| 181 self.OpenZipFile() | 186 self.OpenZipFile() |
| 182 self.assertEqual(len(self.zipfile.namelist()), 3) | 187 self.assertEqual(len(self.zipfile.namelist()), 3) |
| 183 | 188 |
| 184 | 189 |
| 185 if __name__ == '__main__': | 190 if __name__ == '__main__': |
| 186 unittest.main() | 191 unittest.main() |
| OLD | NEW |