python - How to unit test this lambda code? -
say, have following python code:
try: fabulous.color import fg256 format_info = lambda x: fg256(63, unicode(x, 'utf-8')).as_utf8 except importerror: format_info = lambda x: '\033[1;30m' + x + '\033[0m'
how can unit test this?
is worth testing?
there need mock import statement both branches excised. trivial -- example, mock fg256
have side effect of raise importerror
.
matching returned string has right control characters fine feels brittle.
what want test? seem have 2 unrelated cases here;
- importing fails
- lambda returns correct info
it's not responsibility check not using code fails; if want test nevertheless (perhaps because code has posted on popular forum) separate 2 distinct tests.
we don't know lambda supposed return, looks of it, should return string similar assign in except
branch?
Comments
Post a Comment