Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: scripts/slave/recipe_modules/file/example.py

Issue 1917243002: Revert "build: roll infra_paths changes" (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/build.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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',
9 'file', 8 'file',
10 'recipe_engine/path', 9 'recipe_engine/path',
11 'recipe_engine/raw_io', 10 'recipe_engine/raw_io',
12 'recipe_engine/step', 11 'recipe_engine/step',
13 ] 12 ]
14 13
15 14
16 TEST_CONTENTS = freeze({ 15 TEST_CONTENTS = freeze({
17 'simple': 'abcde', 16 'simple': 'abcde',
18 'spaces': 'abcde fgh', 17 'spaces': 'abcde fgh',
(...skipping 13 matching lines...) Expand all
32 31
33 # mkdtemp demo. 32 # mkdtemp demo.
34 for prefix in ('prefix_a', 'prefix_b'): 33 for prefix in ('prefix_a', 'prefix_b'):
35 # Create temp dir. 34 # Create temp dir.
36 temp_dir = api.path.mkdtemp(prefix) 35 temp_dir = api.path.mkdtemp(prefix)
37 assert api.path.exists(temp_dir) 36 assert api.path.exists(temp_dir)
38 # Make |temp_dir| surface in expectation files. 37 # Make |temp_dir| surface in expectation files.
39 api.step('print %s' % prefix, ['echo', temp_dir]) 38 api.step('print %s' % prefix, ['echo', temp_dir])
40 39
41 # rmwildcard demo 40 # rmwildcard demo
42 api.file.rmwildcard('*.o', api.infra_paths['slave_build']) 41 api.file.rmwildcard('*.o', api.path['slave_build'])
43 42
44 for name, content in TEST_CONTENTS.iteritems(): 43 for name, content in TEST_CONTENTS.iteritems():
45 api.file.write('write_%s' % name, 'tmp_file.txt', content) 44 api.file.write('write_%s' % name, 'tmp_file.txt', content)
46 actual_content = api.file.read( 45 actual_content = api.file.read(
47 'read_%s' % name, 'tmp_file.txt', 46 'read_%s' % name, 'tmp_file.txt',
48 test_data=content 47 test_data=content
49 ) 48 )
50 msg = 'expected %s but got %s' % (content, actual_content) 49 msg = 'expected %s but got %s' % (content, actual_content)
51 assert actual_content == content, msg 50 assert actual_content == content, msg
52 51
53 try: 52 try:
54 # copytree 53 # copytree
55 content = 'some file content' 54 content = 'some file content'
56 tmp_dir = api.infra_paths['slave_build'].join('copytree_example_tmp') 55 tmp_dir = api.path['slave_build'].join('copytree_example_tmp')
57 api.file.makedirs('makedirs', tmp_dir) 56 api.file.makedirs('makedirs', tmp_dir)
58 path = tmp_dir.join('dummy_file') 57 path = tmp_dir.join('dummy_file')
59 api.file.write('write %s' % path, path, content) 58 api.file.write('write %s' % path, path, content)
60 new_tmp = api.infra_paths['slave_build'].join('copytree_example_tmp2') 59 new_tmp = api.path['slave_build'].join('copytree_example_tmp2')
61 new_path = new_tmp.join('dummy_file') 60 new_path = new_tmp.join('dummy_file')
62 api.file.copytree('copytree', tmp_dir, new_tmp) 61 api.file.copytree('copytree', tmp_dir, new_tmp)
63 actual_content = api.file.read('read %s' % new_path, new_path, 62 actual_content = api.file.read('read %s' % new_path, new_path,
64 test_data=content) 63 test_data=content)
65 assert actual_content == content 64 assert actual_content == content
66 65
67 # glob. 66 # glob.
68 files = api.file.glob( 67 files = api.file.glob(
69 'glob', tmp_dir.join('*'), 68 'glob', tmp_dir.join('*'),
70 test_data=[tmp_dir.join('dummy_file')]) 69 test_data=[tmp_dir.join('dummy_file')])
71 assert files == [str(tmp_dir.join('dummy_file'))], files 70 assert files == [str(tmp_dir.join('dummy_file'))], files
72 71
73 finally: 72 finally:
74 api.file.rmtree('cleanup', tmp_dir) 73 api.file.rmtree('cleanup', tmp_dir)
75 api.file.rmtree('cleanup2', new_tmp) 74 api.file.rmtree('cleanup2', new_tmp)
76 75
77 76
78 def GenTests(api): 77 def GenTests(api):
79 yield api.test('file_io') 78 yield api.test('file_io')
80 79
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698