Skip to content

Commit

Permalink
Merge 60818d5 into 1e77626
Browse files Browse the repository at this point in the history
  • Loading branch information
yaniv-aknin committed May 12, 2024
2 parents 1e77626 + 60818d5 commit dc63fbf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/test-changes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install --prefer-binary -r requirements-tests.txt
python -m pip install -e .
- name: Setup environment variables for remote filesystem testing
if: matrix.os == 'ubuntu-latest' && matrix.python == '3.8'
Expand Down
2 changes: 1 addition & 1 deletion petl/io/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from petl.util.base import data, Table, dicts as _dicts, iterpeek


def fromjson(source, *args, **kwargs):
def fromjson(source=None, *args, **kwargs):
"""
Extract data from a JSON file. The file must contain a JSON array as
the top level object, and each member of the array will be treated as a
Expand Down
22 changes: 22 additions & 0 deletions petl/test/test_executable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from __future__ import print_function, division, absolute_import

import subprocess

def test_executable():
result = subprocess.check_output("""
(echo foo,bar ; echo a,b; echo c,d) |
petl 'fromcsv().cut("foo").head(1).tocsv()'
""", shell=True)
assert result == b'foo\r\na\r\n'

def test_json_stdin():
result = subprocess.check_output("""
echo '[{"foo": "a", "bar": "b"}]' |
petl 'fromjson().tocsv()'
""", shell=True)
assert result == b'foo,bar\r\na,b\r\n'
result = subprocess.check_output("""
( echo '{"foo": "a", "bar": "b"}' ; echo '{"foo": "c", "bar": "d"}' ) |
petl 'fromjson(lines=True).tocsv()'
""", shell=True)
assert result == b'foo,bar\r\na,b\r\nc,d\r\n'

0 comments on commit dc63fbf

Please sign in to comment.