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

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

Issue 2918463002: [recipe_modules/file] add real file module to engine. (Closed)
Patch Set: fix rmtree Created 3 years, 6 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
(Empty)
1 # Copyright 2017 The LUCI Authors. All rights reserved.
2 # Use of this source code is governed under the Apache License, Version 2.0
3 # that can be found in the LICENSE file.
4
5 import os
6
7 from recipe_engine import recipe_test_api
8
9
10 class FileTestApi(recipe_test_api.RecipeTestApi):
11 def listdir(self, files=(), errno_name=0):
12 """Provides test mock for the `listdir` method.
13
14 Args:
15 files (iterable[str]) - The list of file names for this `listdir` step to
16 return.
17 errno_name (str|None) - The error name for this step to return, if any.
18
19 Example:
20 yield (api.test('my_test')
21 + api.file.listdir('list step name', ['some', 'file', 'names'])
22 )
23 """
24 return (self.m.raw_io.stream_output('\n'.join(files))
25 + self.errno(errno_name))
26
27 def read_text(self, text_content='', errno_name=0):
28 """Provides test mock for the `read_text` method.
29
30 Args:
31 text_content (str) - The text data for this read_text step to return.
32 errno_name (str|None) - The error name for this step to return, if any.
33
34 Example:
35 yield (api.test('my_test')
36 + api.file.read_text('read step name', 'some\nfile\ncontent')
37 )
38 """
39 return (self.m.raw_io.output_text(text_content)
40 + self.errno(errno_name))
41
42 def glob_paths(self, paths=(), errno_name=0):
dnj 2017/05/31 16:50:40 errno_name=0 .. why not None? I like None as a mor
43 """Provides test mock for the `glob_paths` method.
44
45 Args:
46 paths (iterable[str|Path]) - The paths for the glob_paths step to return.
47 errno_name (str|None) - The error name for this step to return, if any.
48
49 Example:
50 yield (api.test('my_test')
51 + api.file.glob_paths('glob step name', [
52 '[BASE_PATH]/some/path',
53 '[BASE_PATH]/some/other_thing',
54 ])
55 )
56 """
57 return (self.m.raw_io.stream_output('\n'.join(map(str, paths)))
58 + self.errno(errno_name))
59
60 def errno(self, errno_name=None):
61 """Provides test mock for any file module method, causing the step to raise
62 a file.Error exception.
63
64 Args:
65 errno_name (None|str) - The errno error name that the step should raise.
66 This must be e.g. 'EPERM', 'EEXIST', etc.
dnj 2017/05/31 16:50:40 'must be ... etc.' seems silly - either have some
67 """
68 data = {'ok': True}
69 if errno_name:
70 data['ok'] = False
71 data['errno_name'] = errno_name
72 # in real operation, this message will come from the underlying OS and
73 # will potentially have descriptive detail.
74 data['message'] = 'file command encountered system error '+errno_name
75 return self.m.json.output(data, name='main')
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698