| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The LUCI Authors. All rights reserved. | 2 # Copyright 2014 The LUCI Authors. All rights reserved. |
| 3 # Use of this source code is governed under the Apache License, Version 2.0 | 3 # Use of this source code is governed under the Apache License, Version 2.0 |
| 4 # that can be found in the LICENSE file. | 4 # that 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 sys | 10 import sys |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 os.mkdir(src) | 137 os.mkdir(src) |
| 138 os.mkdir(tmp) | 138 os.mkdir(tmp) |
| 139 os.mkdir(tmp_foo) | 139 os.mkdir(tmp_foo) |
| 140 # The problem was that it's an absolute path, so it must be considered a | 140 # The problem was that it's an absolute path, so it must be considered a |
| 141 # normal directory. | 141 # normal directory. |
| 142 os.symlink(tmp, src_out) | 142 os.symlink(tmp, src_out) |
| 143 open(os.path.join(tmp_foo, 'bar.txt'), 'w').close() | 143 open(os.path.join(tmp_foo, 'bar.txt'), 'w').close() |
| 144 actual = isolated_format.expand_symlinks(src, u'out/foo/bar.txt') | 144 actual = isolated_format.expand_symlinks(src, u'out/foo/bar.txt') |
| 145 self.assertEqual((u'out/foo/bar.txt', []), actual) | 145 self.assertEqual((u'out/foo/bar.txt', []), actual) |
| 146 | 146 |
| 147 def test_file_to_metadata_path_case_collapse(self): |
| 148 # Ensure setting the collapse_symlink option doesn't include the symlinks |
| 149 basedir = os.path.join(self.cwd, 'basedir') |
| 150 os.mkdir(basedir) |
| 151 subdir = os.path.join(basedir, 'subdir') |
| 152 os.mkdir(subdir) |
| 153 linkdir = os.path.join(basedir, 'linkdir') |
| 154 os.mkdir(linkdir) |
| 155 |
| 156 foo_file = os.path.join(subdir, 'Foo.txt') |
| 157 open(foo_file, 'w').close() |
| 158 sym_file = os.path.join(basedir, 'linkdir', 'Sym.txt') |
| 159 os.symlink('../subdir/Foo.txt', sym_file) |
| 160 |
| 161 actual = isolated_format.file_to_metadata(sym_file, {}, True, ALGO, True) |
| 162 |
| 163 expected = { |
| 164 # SHA-1 of empty string |
| 165 'h': 'da39a3ee5e6b4b0d3255bfef95601890afd80709', |
| 166 'm': 288, |
| 167 's': 0, |
| 168 't': int(round(os.stat(foo_file).st_mtime)), |
| 169 } |
| 170 self.assertEqual(expected, actual) |
| 171 |
| 147 | 172 |
| 148 class TestIsolated(auto_stub.TestCase): | 173 class TestIsolated(auto_stub.TestCase): |
| 149 def test_load_isolated_empty(self): | 174 def test_load_isolated_empty(self): |
| 150 m = isolated_format.load_isolated('{}', isolateserver_mock.ALGO) | 175 m = isolated_format.load_isolated('{}', isolateserver_mock.ALGO) |
| 151 self.assertEqual({}, m) | 176 self.assertEqual({}, m) |
| 152 | 177 |
| 153 def test_load_isolated_good(self): | 178 def test_load_isolated_good(self): |
| 154 data = { | 179 data = { |
| 155 u'command': [u'foo', u'bar'], | 180 u'command': [u'foo', u'bar'], |
| 156 u'files': { | 181 u'files': { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 self.assertEqual([('foo', data, True)], calls) | 274 self.assertEqual([('foo', data, True)], calls) |
| 250 | 275 |
| 251 | 276 |
| 252 if __name__ == '__main__': | 277 if __name__ == '__main__': |
| 253 fix_encoding.fix_encoding() | 278 fix_encoding.fix_encoding() |
| 254 if '-v' in sys.argv: | 279 if '-v' in sys.argv: |
| 255 unittest.TestCase.maxDiff = None | 280 unittest.TestCase.maxDiff = None |
| 256 logging.basicConfig( | 281 logging.basicConfig( |
| 257 level=(logging.DEBUG if '-v' in sys.argv else logging.ERROR)) | 282 level=(logging.DEBUG if '-v' in sys.argv else logging.ERROR)) |
| 258 unittest.main() | 283 unittest.main() |
| OLD | NEW |