Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Side by Side Diff: client/tests/zip_package_test.py

Issue 1390773002: Add an assert to ensure UTF-8 locale when handling file paths. (Closed) Base URL: git@github.com:luci/luci-py.git@master
Patch Set: More fixes Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « client/tests/trace_inputs_smoke_test.py ('k') | client/tools/run_on_bots.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2013 The Swarming Authors. All rights reserved. 2 # Copyright 2013 The Swarming Authors. All rights reserved.
3 # Use of this source code is governed under the Apache License, Version 2.0 that 3 # Use of this source code is governed under the Apache License, Version 2.0 that
4 # can be found in the LICENSE file. 4 # can be found in the LICENSE file.
5 5
6 import cStringIO as StringIO 6 import cStringIO as StringIO
7 import logging 7 import logging
8 import os 8 import os
9 import shutil
10 import subprocess 9 import subprocess
11 import sys 10 import sys
12 import tempfile 11 import tempfile
13 import unittest 12 import unittest
14 import zipfile 13 import zipfile
15 14
16 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 15 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17 sys.path.insert(0, ROOT_DIR) 16 sys.path.insert(0, ROOT_DIR)
18 17
18 from third_party.depot_tools import fix_encoding
19 from utils import file_path
19 from utils import zip_package 20 from utils import zip_package
20 21
21 22
22 def check_output(*args, **kwargs): 23 def check_output(*args, **kwargs):
23 return subprocess.check_output(*args, stderr=subprocess.STDOUT, **kwargs) 24 return subprocess.check_output(*args, stderr=subprocess.STDOUT, **kwargs)
24 25
25 26
26 class ZipPackageTest(unittest.TestCase): 27 class ZipPackageTest(unittest.TestCase):
27 def setUp(self): 28 def setUp(self):
28 super(ZipPackageTest, self).setUp() 29 super(ZipPackageTest, self).setUp()
29 self.temp_dir = tempfile.mkdtemp(prefix=u'zip_package_test') 30 self.temp_dir = tempfile.mkdtemp(prefix=u'zip_package_test')
30 31
31 def tearDown(self): 32 def tearDown(self):
32 shutil.rmtree(self.temp_dir) 33 try:
33 super(ZipPackageTest, self).tearDown() 34 file_path.rmtree(self.temp_dir)
35 finally:
36 super(ZipPackageTest, self).tearDown()
34 37
35 def stage_files(self, files): 38 def stage_files(self, files):
36 """Populates temp directory with given files specified as a list or dict.""" 39 """Populates temp directory with given files specified as a list or dict."""
37 if not isinstance(files, dict): 40 if not isinstance(files, dict):
38 files = dict((p, '') for p in files) 41 files = dict((p, '') for p in files)
39 for path, content in files.iteritems(): 42 for path, content in files.iteritems():
40 abs_path = os.path.join(self.temp_dir, path.replace('/', os.sep)) 43 abs_path = os.path.join(self.temp_dir, path.replace('/', os.sep))
41 dir_path = os.path.dirname(abs_path) 44 dir_path = os.path.dirname(abs_path)
42 if not os.path.exists(dir_path): 45 if not os.path.exists(dir_path):
43 os.makedirs(dir_path) 46 os.makedirs(dir_path)
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 zip_file = os.path.join(self.temp_dir, 'out.zip') 278 zip_file = os.path.join(self.temp_dir, 'out.zip')
276 pkg.zip_into_file(zip_file) 279 pkg.zip_into_file(zip_file)
277 actual = check_output([sys.executable, zip_file]).strip() 280 actual = check_output([sys.executable, zip_file]).strip()
278 expected = os.path.join( 281 expected = os.path.join(
279 self.temp_dir, 282 self.temp_dir,
280 '321690737f78d081937f88c3fd0e625dd48ae07d-cert.pem') 283 '321690737f78d081937f88c3fd0e625dd48ae07d-cert.pem')
281 self.assertEqual(expected, actual) 284 self.assertEqual(expected, actual)
282 285
283 286
284 if __name__ == '__main__': 287 if __name__ == '__main__':
288 fix_encoding.fix_encoding()
285 VERBOSE = '-v' in sys.argv 289 VERBOSE = '-v' in sys.argv
286 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR) 290 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR)
287 unittest.main() 291 unittest.main()
OLDNEW
« no previous file with comments | « client/tests/trace_inputs_smoke_test.py ('k') | client/tools/run_on_bots.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698