OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 from recipe_engine.types import freeze | 5 from recipe_engine.types import freeze |
6 | 6 |
7 DEPS = [ | 7 DEPS = [ |
| 8 'depot_tools/infra_paths', |
8 'file', | 9 'file', |
9 'recipe_engine/path', | 10 'recipe_engine/path', |
10 'recipe_engine/raw_io', | 11 'recipe_engine/raw_io', |
11 'recipe_engine/step', | 12 'recipe_engine/step', |
12 ] | 13 ] |
13 | 14 |
14 | 15 |
15 TEST_CONTENTS = freeze({ | 16 TEST_CONTENTS = freeze({ |
16 'simple': 'abcde', | 17 'simple': 'abcde', |
17 'spaces': 'abcde fgh', | 18 'spaces': 'abcde fgh', |
(...skipping 13 matching lines...) Expand all Loading... |
31 | 32 |
32 # mkdtemp demo. | 33 # mkdtemp demo. |
33 for prefix in ('prefix_a', 'prefix_b'): | 34 for prefix in ('prefix_a', 'prefix_b'): |
34 # Create temp dir. | 35 # Create temp dir. |
35 temp_dir = api.path.mkdtemp(prefix) | 36 temp_dir = api.path.mkdtemp(prefix) |
36 assert api.path.exists(temp_dir) | 37 assert api.path.exists(temp_dir) |
37 # Make |temp_dir| surface in expectation files. | 38 # Make |temp_dir| surface in expectation files. |
38 api.step('print %s' % prefix, ['echo', temp_dir]) | 39 api.step('print %s' % prefix, ['echo', temp_dir]) |
39 | 40 |
40 # rmwildcard demo | 41 # rmwildcard demo |
41 api.file.rmwildcard('*.o', api.path['slave_build']) | 42 api.file.rmwildcard('*.o', api.infra_paths['slave_build']) |
42 | 43 |
43 for name, content in TEST_CONTENTS.iteritems(): | 44 for name, content in TEST_CONTENTS.iteritems(): |
44 api.file.write('write_%s' % name, 'tmp_file.txt', content) | 45 api.file.write('write_%s' % name, 'tmp_file.txt', content) |
45 actual_content = api.file.read( | 46 actual_content = api.file.read( |
46 'read_%s' % name, 'tmp_file.txt', | 47 'read_%s' % name, 'tmp_file.txt', |
47 test_data=content | 48 test_data=content |
48 ) | 49 ) |
49 msg = 'expected %s but got %s' % (content, actual_content) | 50 msg = 'expected %s but got %s' % (content, actual_content) |
50 assert actual_content == content, msg | 51 assert actual_content == content, msg |
51 | 52 |
52 try: | 53 try: |
53 # copytree | 54 # copytree |
54 content = 'some file content' | 55 content = 'some file content' |
55 tmp_dir = api.path['slave_build'].join('copytree_example_tmp') | 56 tmp_dir = api.infra_paths['slave_build'].join('copytree_example_tmp') |
56 api.file.makedirs('makedirs', tmp_dir) | 57 api.file.makedirs('makedirs', tmp_dir) |
57 path = tmp_dir.join('dummy_file') | 58 path = tmp_dir.join('dummy_file') |
58 api.file.write('write %s' % path, path, content) | 59 api.file.write('write %s' % path, path, content) |
59 new_tmp = api.path['slave_build'].join('copytree_example_tmp2') | 60 new_tmp = api.infra_paths['slave_build'].join('copytree_example_tmp2') |
60 new_path = new_tmp.join('dummy_file') | 61 new_path = new_tmp.join('dummy_file') |
61 api.file.copytree('copytree', tmp_dir, new_tmp) | 62 api.file.copytree('copytree', tmp_dir, new_tmp) |
62 actual_content = api.file.read('read %s' % new_path, new_path, | 63 actual_content = api.file.read('read %s' % new_path, new_path, |
63 test_data=content) | 64 test_data=content) |
64 assert actual_content == content | 65 assert actual_content == content |
65 | 66 |
66 # glob. | 67 # glob. |
67 files = api.file.glob( | 68 files = api.file.glob( |
68 'glob', tmp_dir.join('*'), | 69 'glob', tmp_dir.join('*'), |
69 test_data=[tmp_dir.join('dummy_file')]) | 70 test_data=[tmp_dir.join('dummy_file')]) |
70 assert files == [str(tmp_dir.join('dummy_file'))], files | 71 assert files == [str(tmp_dir.join('dummy_file'))], files |
71 | 72 |
72 finally: | 73 finally: |
73 api.file.rmtree('cleanup', tmp_dir) | 74 api.file.rmtree('cleanup', tmp_dir) |
74 api.file.rmtree('cleanup2', new_tmp) | 75 api.file.rmtree('cleanup2', new_tmp) |
75 | 76 |
76 | 77 |
77 def GenTests(api): | 78 def GenTests(api): |
78 yield api.test('file_io') | 79 yield api.test('file_io') |
79 | 80 |
OLD | NEW |