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

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

Issue 1101673005: Extract functions from path recipe module so that step can depend on it (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Created 5 years, 8 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 | Annotate | Revision Log
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 infra.libs.infra_types import freeze 5 from infra.libs.infra_types import freeze
6 6
7 DEPS = [ 7 DEPS = [
8 'file', 8 'file',
9 'path', 9 'path',
10 'raw_io', 10 'raw_io',
11 'step',
11 ] 12 ]
12 13
13 14
14 TEST_CONTENTS = freeze({ 15 TEST_CONTENTS = freeze({
15 'simple': 'abcde', 16 'simple': 'abcde',
16 'spaces': 'abcde fgh', 17 'spaces': 'abcde fgh',
17 'symbols': '! ~&&', 18 'symbols': '! ~&&',
18 'multiline': '''ab 19 'multiline': '''ab
19 cd 20 cd
20 efg 21 efg
21 ''', 22 ''',
22 }) 23 })
23 24
24 25
25 def GenSteps(api): 26 def GenSteps(api):
27 # listdir demo.
28 result = api.file.listdir('fake dir', '/fake/dir')
29 for element in result:
30 api.step('manipulate %s' % str(element), ['some', 'command'])
31
32 # mkdtemp demo.
33 for prefix in ('prefix_a', 'prefix_b'):
34 # Create temp dir.
35 temp_dir = api.path.mkdtemp(prefix)
36 assert api.path.exists(temp_dir)
37 # Make |temp_dir| surface in expectation files.
38 api.step('print %s' % prefix, ['echo', temp_dir])
39
40 # rmwildcard demo
41 api.file.rmwildcard('*.o', api.path['slave_build'])
42
26 for name, content in TEST_CONTENTS.iteritems(): 43 for name, content in TEST_CONTENTS.iteritems():
27 api.file.write('write_%s' % name, 'tmp_file.txt', content) 44 api.file.write('write_%s' % name, 'tmp_file.txt', content)
28 actual_content = api.file.read( 45 actual_content = api.file.read(
29 'read_%s' % name, 'tmp_file.txt', 46 'read_%s' % name, 'tmp_file.txt',
30 test_data=content 47 test_data=content
31 ) 48 )
32 msg = 'expected %s but got %s' % (content, actual_content) 49 msg = 'expected %s but got %s' % (content, actual_content)
33 assert actual_content == content, msg 50 assert actual_content == content, msg
34 51
35 try: 52 try:
36 # copytree 53 # copytree
37 content = 'some file content' 54 content = 'some file content'
38 tmp_dir = api.path['slave_build'].join('copytree_example_tmp') 55 tmp_dir = api.path['slave_build'].join('copytree_example_tmp')
39 api.path.makedirs('makedirs', tmp_dir) 56 api.file.makedirs('makedirs', tmp_dir)
40 path = tmp_dir.join('dummy_file') 57 path = tmp_dir.join('dummy_file')
41 api.file.write('write %s' % path, path, content) 58 api.file.write('write %s' % path, path, content)
42 new_tmp = api.path['slave_build'].join('copytree_example_tmp2') 59 new_tmp = api.path['slave_build'].join('copytree_example_tmp2')
43 new_path = new_tmp.join('dummy_file') 60 new_path = new_tmp.join('dummy_file')
44 api.file.copytree('copytree', tmp_dir, new_tmp) 61 api.file.copytree('copytree', tmp_dir, new_tmp)
45 actual_content = api.file.read('read %s' % new_path, new_path, 62 actual_content = api.file.read('read %s' % new_path, new_path,
46 test_data=content) 63 test_data=content)
47 assert actual_content == content 64 assert actual_content == content
48 65
49 # glob. 66 # glob.
50 files = api.file.glob( 67 files = api.file.glob(
51 'glob', tmp_dir.join('*'), 68 'glob', tmp_dir.join('*'),
52 test_data=[tmp_dir.join('dummy_file')]) 69 test_data=[tmp_dir.join('dummy_file')])
53 assert files == [str(tmp_dir.join('dummy_file'))], files 70 assert files == [str(tmp_dir.join('dummy_file'))], files
54 71
55 finally: 72 finally:
56 api.path.rmtree('cleanup', tmp_dir) 73 api.file.rmtree('cleanup', tmp_dir)
57 api.path.rmtree('cleanup2', new_tmp) 74 api.file.rmtree('cleanup2', new_tmp)
58 75
59 76
60 def GenTests(api): 77 def GenTests(api):
61 yield api.test('file_io') 78 yield api.test('file_io')
62 79
OLDNEW
« no previous file with comments | « scripts/slave/recipe_modules/file/api.py ('k') | scripts/slave/recipe_modules/file/example.expected/file_io.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698