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

Side by Side Diff: client/tests/isolated_format_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/isolate_test.py ('k') | client/tests/isolateserver_test.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 2014 The Swarming Authors. All rights reserved. 2 # Copyright 2014 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 hashlib 6 import hashlib
7 import json 7 import json
8 import logging 8 import logging
9 import os 9 import os
10 import shutil
11 import sys 10 import sys
12 import tempfile 11 import tempfile
13 import unittest 12 import unittest
14 13
15 # net_utils adjusts sys.path. 14 # net_utils adjusts sys.path.
16 import net_utils 15 import net_utils
17 16
18 import isolated_format 17 import isolated_format
19 from depot_tools import auto_stub 18 from depot_tools import auto_stub
19 from depot_tools import fix_encoding
20 from utils import file_path
20 from utils import tools 21 from utils import tools
21 22
22 import isolateserver_mock 23 import isolateserver_mock
23 24
24 25
25 ALGO = hashlib.sha1 26 ALGO = hashlib.sha1
26 27
27 28
28 class TestCase(net_utils.TestCase): 29 class TestCase(net_utils.TestCase):
29 def test_get_hash_algo(self): 30 def test_get_hash_algo(self):
30 # Tests here assume ALGO is used for default namespaces, check this 31 # Tests here assume ALGO is used for default namespaces, check this
31 # assumption. 32 # assumption.
32 self.assertIs(isolated_format.get_hash_algo('default'), ALGO) 33 self.assertIs(isolated_format.get_hash_algo('default'), ALGO)
33 self.assertIs(isolated_format.get_hash_algo('default-gzip'), ALGO) 34 self.assertIs(isolated_format.get_hash_algo('default-gzip'), ALGO)
34 35
35 36
36 class SymlinkTest(unittest.TestCase): 37 class SymlinkTest(unittest.TestCase):
37 def setUp(self): 38 def setUp(self):
38 super(SymlinkTest, self).setUp() 39 super(SymlinkTest, self).setUp()
39 self.old_cwd = os.getcwd() 40 self.old_cwd = os.getcwd()
40 self.cwd = tempfile.mkdtemp(prefix=u'isolate_') 41 self.cwd = tempfile.mkdtemp(prefix=u'isolate_')
41 # Everything should work even from another directory. 42 # Everything should work even from another directory.
42 os.chdir(self.cwd) 43 os.chdir(self.cwd)
43 44
44 def tearDown(self): 45 def tearDown(self):
45 try: 46 try:
46 os.chdir(self.old_cwd) 47 os.chdir(self.old_cwd)
47 shutil.rmtree(self.cwd) 48 file_path.rmtree(self.cwd)
48 finally: 49 finally:
49 super(SymlinkTest, self).tearDown() 50 super(SymlinkTest, self).tearDown()
50 51
51 if sys.platform == 'darwin': 52 if sys.platform == 'darwin':
52 def test_expand_symlinks_path_case(self): 53 def test_expand_symlinks_path_case(self):
53 # Ensures that the resulting path case is fixed on case insensitive file 54 # Ensures that the resulting path case is fixed on case insensitive file
54 # system. 55 # system.
55 os.symlink('dest', os.path.join(self.cwd, 'link')) 56 os.symlink('dest', os.path.join(self.cwd, 'link'))
56 os.mkdir(os.path.join(self.cwd, 'Dest')) 57 os.mkdir(os.path.join(self.cwd, 'Dest'))
57 open(os.path.join(self.cwd, 'Dest', 'file.txt'), 'w').close() 58 open(os.path.join(self.cwd, 'Dest', 'file.txt'), 'w').close()
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 u's': 2181582786L, 234 u's': 2181582786L,
234 } 235 }
235 }, 236 },
236 } 237 }
237 m = isolated_format.save_isolated('foo', data) 238 m = isolated_format.save_isolated('foo', data)
238 self.assertEqual([], m) 239 self.assertEqual([], m)
239 self.assertEqual([('foo', data, True)], calls) 240 self.assertEqual([('foo', data, True)], calls)
240 241
241 242
242 if __name__ == '__main__': 243 if __name__ == '__main__':
244 fix_encoding.fix_encoding()
243 if '-v' in sys.argv: 245 if '-v' in sys.argv:
244 unittest.TestCase.maxDiff = None 246 unittest.TestCase.maxDiff = None
245 logging.basicConfig( 247 logging.basicConfig(
246 level=(logging.DEBUG if '-v' in sys.argv else logging.ERROR)) 248 level=(logging.DEBUG if '-v' in sys.argv else logging.ERROR))
247 unittest.main() 249 unittest.main()
OLDNEW
« no previous file with comments | « client/tests/isolate_test.py ('k') | client/tests/isolateserver_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698