OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 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 unittest | 6 import unittest |
7 | 7 |
8 from test_file_system import TestFileSystem | 8 from test_file_system import TestFileSystem |
9 | 9 |
10 file_system = TestFileSystem({ | 10 file_system = TestFileSystem({ |
| 11 'file.txt': '', |
11 'templates': { | 12 'templates': { |
| 13 'README': '', |
12 'public': { | 14 'public': { |
13 'apps': { | 15 'apps': { |
14 '404.html': '', | 16 '404.html': '', |
15 'a11y.html': '' | 17 'a11y.html': '' |
16 }, | 18 }, |
17 'extensions': { | 19 'extensions': { |
18 '404.html': '', | 20 '404.html': '', |
19 'cookies.html': '' | 21 'cookies.html': '' |
20 }, | 22 }, |
21 'redirects.json': 'redirect' | 23 'redirects.json': 'redirect' |
22 }, | 24 }, |
23 'json': { | 25 'json': { |
24 'manifest.json': 'manifest' | 26 'manifest.json': 'manifest' |
25 } | 27 } |
26 } | 28 } |
27 }) | 29 }) |
28 | 30 |
29 class FileSystemTest(unittest.TestCase): | 31 class FileSystemTest(unittest.TestCase): |
30 def testWalk(self): | 32 def testWalk(self): |
31 expected_files = set([ | 33 expected_files = [ |
| 34 '^/file.txt', |
| 35 'templates/README', |
32 'templates/public/apps/404.html', | 36 'templates/public/apps/404.html', |
33 'templates/public/apps/a11y.html', | 37 'templates/public/apps/a11y.html', |
34 'templates/public/extensions/404.html', | 38 'templates/public/extensions/404.html', |
35 'templates/public/extensions/cookies.html', | 39 'templates/public/extensions/cookies.html', |
36 'templates/public/redirects.json', | 40 'templates/public/redirects.json', |
37 'templates/json/manifest.json' | 41 'templates/json/manifest.json' |
38 ]) | 42 ] |
39 | 43 |
40 expected_dirs = set([ | 44 expected_dirs = [ |
41 '/templates/', | 45 '^/templates/', |
42 'templates/public/', | 46 'templates/public/', |
43 'templates/public/apps/', | 47 'templates/public/apps/', |
44 'templates/public/extensions/', | 48 'templates/public/extensions/', |
45 'templates/json/' | 49 'templates/json/' |
46 ]) | 50 ] |
47 | 51 |
48 all_files = set() | 52 all_files = [] |
49 all_dirs = set() | 53 all_dirs = [] |
50 for root, dirs, files in file_system.Walk(''): | 54 for root, dirs, files in file_system.Walk(''): |
51 all_files.update(root + '/' + name for name in files) | 55 if not root: root = '^' |
52 all_dirs.update(root + '/' + name for name in dirs) | 56 all_files += [root + '/' + name for name in files] |
| 57 all_dirs += [root + '/' + name for name in dirs] |
53 | 58 |
54 self.assertEqual(expected_files, all_files) | 59 self.assertEqual(sorted(expected_files), sorted(all_files)) |
55 self.assertEqual(expected_dirs, all_dirs) | 60 self.assertEqual(sorted(expected_dirs), sorted(all_dirs)) |
56 | 61 |
57 def testSubWalk(self): | 62 def testSubWalk(self): |
58 expected_files = set([ | 63 expected_files = set([ |
59 '/redirects.json', | 64 '/redirects.json', |
60 'apps/404.html', | 65 'apps/404.html', |
61 'apps/a11y.html', | 66 'apps/a11y.html', |
62 'extensions/404.html', | 67 'extensions/404.html', |
63 'extensions/cookies.html' | 68 'extensions/cookies.html' |
64 ]) | 69 ]) |
65 | 70 |
66 all_files = set() | 71 all_files = set() |
67 for root, dirs, files in file_system.Walk('templates/public'): | 72 for root, dirs, files in file_system.Walk('templates/public/'): |
68 all_files.update(root + '/' + name for name in files) | 73 all_files.update(root + '/' + name for name in files) |
69 | 74 |
70 self.assertEqual(expected_files, all_files) | 75 self.assertEqual(expected_files, all_files) |
71 | 76 |
| 77 def testExists(self): |
| 78 def exists(path): |
| 79 return file_system.Exists(path).Get() |
| 80 |
| 81 # Root directory. |
| 82 self.assertTrue(exists('')) |
| 83 |
| 84 # Directories (are not files). |
| 85 self.assertFalse(exists('templates')) |
| 86 self.assertTrue(exists('templates/')) |
| 87 self.assertFalse(exists('templates/public')) |
| 88 self.assertTrue(exists('templates/public/')) |
| 89 self.assertFalse(exists('templates/public/apps')) |
| 90 self.assertTrue(exists('templates/public/apps/')) |
| 91 |
| 92 # Files (are not directories). |
| 93 self.assertTrue(exists('file.txt')) |
| 94 self.assertFalse(exists('file.txt/')) |
| 95 self.assertTrue(exists('templates/README')) |
| 96 self.assertFalse(exists('templates/README/')) |
| 97 self.assertTrue(exists('templates/public/redirects.json')) |
| 98 self.assertFalse(exists('templates/public/redirects.json/')) |
| 99 self.assertTrue(exists('templates/public/apps/a11y.html')) |
| 100 self.assertFalse(exists('templates/public/apps/a11y.html/')) |
| 101 |
| 102 |
72 if __name__ == '__main__': | 103 if __name__ == '__main__': |
73 unittest.main() | 104 unittest.main() |
OLD | NEW |