Skip to content

Commit 37c4305

Browse files
authored
Lint error cleanup following google#345 (google#390)
* Lint error cleanup following google#345 * Makes new serialize= test deterministic
1 parent 8bddeec commit 37c4305

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

fire/core.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ def Fire(component=None, command=None, name=None, serialize=None):
164164
raise FireExit(0, component_trace)
165165

166166
# The command succeeded normally; print the result.
167-
_PrintResult(component_trace, verbose=component_trace.verbose, serialize=serialize)
167+
_PrintResult(
168+
component_trace, verbose=component_trace.verbose, serialize=serialize)
168169
result = component_trace.GetResult()
169170
return result
170171

@@ -247,11 +248,12 @@ def _PrintResult(component_trace, verbose=False, serialize=None):
247248
# and move serialization to its own module.
248249
result = component_trace.GetResult()
249250

250-
# Allow users to modify the return value of the component and provide
251+
# Allow users to modify the return value of the component and provide
251252
# custom formatting.
252253
if serialize:
253254
if not callable(serialize):
254-
raise FireError("serialize argument {} must be empty or callable.".format(serialize))
255+
raise FireError(
256+
'The argument `serialize` must be empty or callable:', serialize)
255257
result = serialize(result)
256258

257259
if value_types.HasCustomStr(result):

fire/core_test.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -199,21 +199,22 @@ def serialize(x):
199199
if isinstance(x, list):
200200
return ', '.join(str(xi) for xi in x)
201201
if isinstance(x, dict):
202-
return ', '.join('{}={!r}'.format(k, v) for k, v in x.items())
202+
return ', '.join('{}={!r}'.format(k, v) for k, v in sorted(x.items()))
203203
if x == 'special':
204204
return ['SURPRISE!!', "I'm a list!"]
205205
return x
206206

207207
ident = lambda x: x
208-
208+
209209
with self.assertOutputMatches(stdout='a, b', stderr=None):
210-
result = core.Fire(ident, command=['[a,b]'], serialize=serialize)
210+
_ = core.Fire(ident, command=['[a,b]'], serialize=serialize)
211211
with self.assertOutputMatches(stdout='a=5, b=6', stderr=None):
212-
result = core.Fire(ident, command=['{a:5,b:6}'], serialize=serialize)
212+
_ = core.Fire(ident, command=['{a:5,b:6}'], serialize=serialize)
213213
with self.assertOutputMatches(stdout='asdf', stderr=None):
214-
result = core.Fire(ident, command=['asdf'], serialize=serialize)
215-
with self.assertOutputMatches(stdout="SURPRISE!!\nI'm a list!\n", stderr=None):
216-
result = core.Fire(ident, command=['special'], serialize=serialize)
214+
_ = core.Fire(ident, command=['asdf'], serialize=serialize)
215+
with self.assertOutputMatches(
216+
stdout="SURPRISE!!\nI'm a list!\n", stderr=None):
217+
_ = core.Fire(ident, command=['special'], serialize=serialize)
217218
with self.assertRaises(core.FireError):
218219
core.Fire(ident, command=['asdf'], serialize=55)
219220

0 commit comments

Comments
 (0)