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 logging | 6 import logging |
7 import os | 7 import os |
8 import unittest | 8 import unittest |
9 import sys | 9 import sys |
10 | 10 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 self.assertEquals('$FOO/bar', actual.full_path) | 57 self.assertEquals('$FOO/bar', actual.full_path) |
58 self.assertEquals(True, actual.tainted) | 58 self.assertEquals(True, actual.tainted) |
59 | 59 |
60 def test_variable_rel(self): | 60 def test_variable_rel(self): |
61 value = trace_inputs.Results.File('/usr', 'foo/bar', False) | 61 value = trace_inputs.Results.File('/usr', 'foo/bar', False) |
62 actual = value.replace_variables({'$FOO': 'foo'}) | 62 actual = value.replace_variables({'$FOO': 'foo'}) |
63 self.assertEquals('$FOO/bar', actual.path) | 63 self.assertEquals('$FOO/bar', actual.path) |
64 self.assertEquals(os.path.join('/usr', '$FOO/bar'), actual.full_path) | 64 self.assertEquals(os.path.join('/usr', '$FOO/bar'), actual.full_path) |
65 self.assertEquals(True, actual.tainted) | 65 self.assertEquals(True, actual.tainted) |
66 | 66 |
67 if sys.platform == 'win32': | 67 def test_native_case_end_with_os_path_sep(self): |
68 def test_native_case_windows(self): | 68 # Make sure the trailing os.path.sep is kept. |
69 windows_path = os.environ['SystemRoot'] | 69 path = trace_inputs.get_native_path_case(ROOT_DIR) + os.path.sep |
| 70 self.assertEquals(trace_inputs.get_native_path_case(path), path) |
| 71 |
| 72 def test_native_case_non_existing(self): |
| 73 # Make sure it doesn't throw on non-existing files. |
| 74 non_existing = 'trace_input_test_this_file_should_not_exist' |
| 75 path = os.path.expanduser('~/' + non_existing) |
| 76 self.assertFalse(os.path.exists(path)) |
| 77 path = trace_inputs.get_native_path_case(ROOT_DIR) + os.path.sep |
| 78 self.assertEquals(trace_inputs.get_native_path_case(path), path) |
| 79 |
| 80 if sys.platform in ('darwin', 'win32'): |
| 81 def test_native_case_not_sensitive(self): |
| 82 # The home directory is almost guaranteed to have mixed upper/lower case |
| 83 # letters on both Windows and OSX. |
| 84 # This test also ensures that the output is independent on the input |
| 85 # string case. |
| 86 path = os.path.expanduser('~') |
| 87 self.assertTrue(os.path.isdir(path)) |
| 88 # This test assumes the variable is in the native path case on disk, this |
| 89 # should be the case. Verify this assumption: |
| 90 self.assertEquals(path, trace_inputs.get_native_path_case(path)) |
70 self.assertEquals( | 91 self.assertEquals( |
71 trace_inputs.get_native_path_case(windows_path.lower()), | 92 trace_inputs.get_native_path_case(path.lower()), |
72 trace_inputs.get_native_path_case(windows_path.upper())) | 93 trace_inputs.get_native_path_case(path.upper())) |
| 94 |
| 95 def test_native_case_not_sensitive_non_existent(self): |
| 96 # This test also ensures that the output is independent on the input |
| 97 # string case. |
| 98 non_existing = os.path.join( |
| 99 'trace_input_test_this_dir_should_not_exist', 'really not', '') |
| 100 path = os.path.expanduser(os.path.join('~', non_existing)) |
| 101 self.assertFalse(os.path.exists(path)) |
| 102 lower = trace_inputs.get_native_path_case(path.lower()) |
| 103 upper = trace_inputs.get_native_path_case(path.upper()) |
| 104 # Make sure non-existing element is not modified: |
| 105 self.assertTrue(lower.endswith(non_existing.lower())) |
| 106 self.assertTrue(upper.endswith(non_existing.upper())) |
| 107 self.assertEquals(lower[:-len(non_existing)], upper[:-len(non_existing)]) |
73 | 108 |
74 if sys.platform != 'win32': | 109 if sys.platform != 'win32': |
75 def test_symlink(self): | 110 def test_symlink(self): |
76 # This test will fail if the checkout is in a symlink. | 111 # This test will fail if the checkout is in a symlink. |
77 actual = trace_inputs.split_at_symlink(None, ROOT_DIR) | 112 actual = trace_inputs.split_at_symlink(None, ROOT_DIR) |
78 expected = (ROOT_DIR, None, None) | 113 expected = (ROOT_DIR, None, None) |
79 self.assertEquals(expected, actual) | 114 self.assertEquals(expected, actual) |
80 | 115 |
81 actual = trace_inputs.split_at_symlink( | 116 actual = trace_inputs.split_at_symlink( |
82 None, os.path.join(ROOT_DIR, 'data', 'trace_inputs')) | 117 None, os.path.join(ROOT_DIR, 'data', 'trace_inputs')) |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 'size': -1, | 417 'size': -1, |
383 }, | 418 }, |
384 ] | 419 ] |
385 self._test_lines(lines, '/home/foo_bar_user/src', files) | 420 self._test_lines(lines, '/home/foo_bar_user/src', files) |
386 | 421 |
387 | 422 |
388 if __name__ == '__main__': | 423 if __name__ == '__main__': |
389 VERBOSE = '-v' in sys.argv | 424 VERBOSE = '-v' in sys.argv |
390 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR) | 425 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR) |
391 unittest.main() | 426 unittest.main() |
OLD | NEW |