| OLD | NEW |
| 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 Loading... |
| 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(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 Loading... |
| 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) |
| OLD | NEW |