OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
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 | |
4 # found in the LICENSE file. | |
5 | |
6 """Tests for module file_utils.""" | |
7 | |
8 import os | |
9 import sys | |
10 import unittest | |
11 | |
12 BUILDBOT_PATH = os.path.realpath(os.path.join( | |
13 os.path.dirname(os.path.abspath(__file__)), os.pardir, os.pardir, os.pardir) | |
14 ) | |
15 | |
16 # Appending to PYTHONPATH to find common. | |
17 sys.path.append(os.path.join(BUILDBOT_PATH, 'third_party', 'chromium_buildbot', | |
18 'scripts')) | |
19 import file_utils | |
20 | |
21 from common import chromium_utils | |
22 | |
23 | |
24 class TestFileUtils(unittest.TestCase): | |
25 | |
26 def setUp(self): | |
27 self._path_exists_ret = True | |
28 self._path_exists_called = False | |
29 self._make_dirs_called = False | |
30 self._remove_dir_called = False | |
31 | |
32 def _MockPathExists(directory): | |
33 self._path_exists_called = True | |
34 return self._path_exists_ret | |
35 | |
36 def _MockMakeDirs(directory): | |
37 self._make_dirs_called = True | |
38 | |
39 def _MockRemoveDirectory(directory): | |
40 self._remove_dir_called = True | |
41 | |
42 self._original_exists = os.path.exists | |
43 os.path.exists = _MockPathExists | |
44 | |
45 self._original_makedirs = os.makedirs | |
46 os.makedirs = _MockMakeDirs | |
47 | |
48 self._original_remove_dir = chromium_utils.RemoveDirectory | |
49 chromium_utils.RemoveDirectory = _MockRemoveDirectory | |
50 | |
51 def tearDown(self): | |
52 os.path.exists = self._original_exists | |
53 os.makedirs = self._original_makedirs | |
54 chromium_utils.RemoveDirectory = self._original_remove_dir | |
55 | |
56 def test_create_clean_local_dir_PathExists(self): | |
57 file_utils.create_clean_local_dir('/tmp/test') | |
58 self.assertTrue(self._path_exists_called) | |
59 self.assertTrue(self._make_dirs_called) | |
60 self.assertTrue(self._remove_dir_called) | |
61 | |
62 def test_create_clean_local_dir_PathDoesNotExists(self): | |
63 self._path_exists_ret = False | |
64 file_utils.create_clean_local_dir('/tmp/test') | |
65 self.assertTrue(self._path_exists_called) | |
66 self.assertTrue(self._make_dirs_called) | |
67 self.assertFalse(self._remove_dir_called) | |
68 | |
69 | |
70 if __name__ == '__main__': | |
71 unittest.main() | |
OLD | NEW |