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

Side by Side Diff: recipe_modules/file/test_api.py

Issue 2993713003: Add file.filesizes to recipe engine core modules. (Closed)
Patch Set: -kwargs. Created 3 years, 4 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
« no previous file with comments | « recipe_modules/file/resources/fileutil.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2017 The LUCI Authors. All rights reserved. 1 # Copyright 2017 The LUCI Authors. All rights reserved.
2 # Use of this source code is governed under the Apache License, Version 2.0 2 # Use of this source code is governed under the Apache License, Version 2.0
3 # that can be found in the LICENSE file. 3 # that can be found in the LICENSE file.
4 4
5 import os 5 import os
6 6
7 from recipe_engine import recipe_test_api 7 from recipe_engine import recipe_test_api
8 8
9 9
10 class FileTestApi(recipe_test_api.RecipeTestApi): 10 class FileTestApi(recipe_test_api.RecipeTestApi):
(...skipping 10 matching lines...) Expand all
21 + api.step_data('listdir step name', api.file.listdir(['a', 'b', 'c'])) 21 + api.step_data('listdir step name', api.file.listdir(['a', 'b', 'c']))
22 """ 22 """
23 def _check(name): 23 def _check(name):
24 name = str(name) 24 name = str(name)
25 if '/' in name or '\\' in name: # pragma: no cover 25 if '/' in name or '\\' in name: # pragma: no cover
26 raise ValueError('file name contains slash: %r' % name) 26 raise ValueError('file name contains slash: %r' % name)
27 return name 27 return name
28 return (self.m.raw_io.stream_output('\n'.join(sorted(map(_check, names)))) 28 return (self.m.raw_io.stream_output('\n'.join(sorted(map(_check, names))))
29 + self.errno(errno_name)) 29 + self.errno(errno_name))
30 30
31 def filesizes(self, sizes=(), errno_name=0):
32 """Provides test mock for the `filesizes` method.
33
34 Args:
35 sizes (iterable[int]) - The list of sizes to return.
36 errno_name (str|None) - The error name for this step to return, if any.
37
38 Example:
39 yield (api.test('my_test')
40 + api.step_data('filesize step name', api.file.filesizes([1674, 5714]))
41 """
42 return (self.m.raw_io.stream_output('\n'.join(map(str, sizes)))
43 + self.errno(errno_name))
44
31 def read_text(self, text_content='', errno_name=0): 45 def read_text(self, text_content='', errno_name=0):
32 """Provides test mock for the `read_text` method. 46 """Provides test mock for the `read_text` method.
33 47
34 Args: 48 Args:
35 text_content (str) - The text data for this read_text step to return. 49 text_content (str) - The text data for this read_text step to return.
36 errno_name (str|None) - The error name for this step to return, if any. 50 errno_name (str|None) - The error name for this step to return, if any.
37 51
38 Example: 52 Example:
39 yield (api.test('my_test') 53 yield (api.test('my_test')
40 + api.step_data('read step name', 54 + api.step_data('read step name',
(...skipping 28 matching lines...) Expand all
69 This must be e.g. 'EPERM', 'EEXIST', etc. 83 This must be e.g. 'EPERM', 'EEXIST', etc.
70 """ 84 """
71 data = {'ok': True} 85 data = {'ok': True}
72 if errno_name: 86 if errno_name:
73 data['ok'] = False 87 data['ok'] = False
74 data['errno_name'] = errno_name 88 data['errno_name'] = errno_name
75 # in real operation, this message will come from the underlying OS and 89 # in real operation, this message will come from the underlying OS and
76 # will potentially have descriptive detail. 90 # will potentially have descriptive detail.
77 data['message'] = 'file command encountered system error '+errno_name 91 data['message'] = 'file command encountered system error '+errno_name
78 return self.m.json.output(data) 92 return self.m.json.output(data)
OLDNEW
« no previous file with comments | « recipe_modules/file/resources/fileutil.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698