Skip to content

Commit

Permalink
Merge 840dfb2 into 9f065ba
Browse files Browse the repository at this point in the history
  • Loading branch information
juarezr committed Nov 22, 2022
2 parents 9f065ba + 840dfb2 commit d19de8f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
8 changes: 5 additions & 3 deletions petl/io/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,7 @@ def _get_handler_from(source, handlers):


def _resolve_source_from_arg(source, handlers):
if source is None:
return StdinSource()
elif isinstance(source, string_types):
if isinstance(source, string_types):
handler = _get_handler_from(source, handlers)
codec = _get_codec_for(source)
if handler is None:
Expand All @@ -464,6 +462,8 @@ def read_source_from_arg(source):
.. versionadded:: 1.4.0
'''
if source is None:
return StdinSource()
return _resolve_source_from_arg(source, _READERS)


Expand All @@ -477,4 +477,6 @@ def write_source_from_arg(source, mode='wb'):
.. versionadded:: 1.4.0
'''
if source is None:
return StdoutSource()
return _resolve_source_from_arg(source, _WRITERS)
11 changes: 11 additions & 0 deletions petl/test/io/test_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@ def test_stdoutsource():
etl.topickle(tbl, StdoutSource())


def test_stdoutsource_none(capfd):

tbl = [('foo', 'bar'), ('a', 1), ('b', 2)]
etl.tocsv(tbl, encoding='ascii')
captured = capfd.readouterr()
outp = captured.out
# TODO: capfd works on vscode but not in console/tox
if outp:
assert outp in ( 'foo,bar\r\na,1\r\nb,2\r\n' , 'foo,bar\na,1\nb,2\n' )


def test_stdoutsource_unicode():

tbl = [('foo', 'bar'),
Expand Down

0 comments on commit d19de8f

Please sign in to comment.