| OLD | NEW |
| (Empty) | |
| 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 |
| 3 # found in the LICENSE file. |
| 4 |
| 5 from recipe_engine.types import freeze |
| 6 |
| 7 DEPS = [ |
| 8 'depot_tools/infra_paths', |
| 9 'file', |
| 10 'recipe_engine/path', |
| 11 'recipe_engine/raw_io', |
| 12 'recipe_engine/step', |
| 13 ] |
| 14 |
| 15 |
| 16 TEST_CONTENTS = freeze({ |
| 17 'simple': 'abcde', |
| 18 'spaces': 'abcde fgh', |
| 19 'symbols': '! ~&&', |
| 20 'multiline': '''ab |
| 21 cd |
| 22 efg |
| 23 ''', |
| 24 }) |
| 25 |
| 26 |
| 27 def RunSteps(api): |
| 28 # listdir demo. |
| 29 result = api.file.listdir('fake dir', '/fake/dir') |
| 30 for element in result: |
| 31 api.step('manipulate %s' % str(element), ['some', 'command']) |
| 32 |
| 33 result = api.file.listdir('other', '/faker/dir') |
| 34 for element in result: |
| 35 api.step('manipulate %s' % str(element), ['some', 'command']) |
| 36 |
| 37 # mkdtemp demo. |
| 38 for prefix in ('prefix_a', 'prefix_b'): |
| 39 # Create temp dir. |
| 40 temp_dir = api.path.mkdtemp(prefix) |
| 41 assert api.path.exists(temp_dir) |
| 42 # Make |temp_dir| surface in expectation files. |
| 43 api.step('print %s' % prefix, ['echo', temp_dir]) |
| 44 |
| 45 # move demo |
| 46 api.file.move( |
| 47 'move', |
| 48 api.path['start_dir'].join('source'), |
| 49 api.path['start_dir'].join('destination')) |
| 50 |
| 51 # remove demo |
| 52 api.file.remove('remove', api.path['start_dir'].join('some_file')) |
| 53 |
| 54 # rmcontents demo |
| 55 api.file.rmcontents('rmcontents', api.path['start_dir'].join('some_dir')) |
| 56 |
| 57 # rmwildcard demo |
| 58 api.file.rmwildcard('*.o', api.path['start_dir']) |
| 59 |
| 60 for name, content in TEST_CONTENTS.iteritems(): |
| 61 api.file.write('write_%s' % name, 'tmp_file.txt', content) |
| 62 actual_content = api.file.read( |
| 63 'read_%s' % name, 'tmp_file.txt', |
| 64 test_data=content |
| 65 ) |
| 66 msg = 'expected %s but got %s' % (content, actual_content) |
| 67 assert actual_content == content, msg |
| 68 |
| 69 try: |
| 70 # copytree |
| 71 content = 'some file content' |
| 72 tmp_dir = api.path['start_dir'].join('copytree_example_tmp') |
| 73 api.file.makedirs('makedirs', tmp_dir) |
| 74 path = tmp_dir.join('dummy_file') |
| 75 api.file.write('write %s' % path, path, content) |
| 76 new_tmp = api.path['start_dir'].join('copytree_example_tmp2') |
| 77 new_path = new_tmp.join('dummy_file') |
| 78 api.file.copytree('copytree', tmp_dir, new_tmp) |
| 79 actual_content = api.file.read('read %s' % new_path, new_path, |
| 80 test_data=content) |
| 81 assert actual_content == content |
| 82 |
| 83 # glob. |
| 84 files = api.file.glob( |
| 85 'glob', tmp_dir.join('*'), |
| 86 test_data=[tmp_dir.join('dummy_file')]) |
| 87 assert files == [tmp_dir.join('dummy_file')], files |
| 88 |
| 89 finally: |
| 90 api.file.rmtree('cleanup', tmp_dir) |
| 91 api.file.rmtree('cleanup2', new_tmp) |
| 92 |
| 93 |
| 94 def GenTests(api): |
| 95 yield api.test('file_io') + api.file.listdir('other', ['aaa']) |
| 96 |
| OLD | NEW |