예제 #1
0
파일: __init__.py 프로젝트: kkrbalam/pyjq
 def run(self, stream):
     jq = JQ()
     jq.compile(self.text)
     for item in stream:
         jq.write(item)
         for result in jq:
             yield result
예제 #2
0
def test_can_pass_data_through():
    jq = JQ()
    jq.compile(".")
    jq.write(1)
    assert list(jq) == [1]
    jq.write(2)
    assert list(jq) == [2]
    assert list(jq) == []
예제 #3
0
def test_can_resume_iteration():
    jq = JQ()
    jq.compile(".[]")
    jq.write([1, 2, 3, 4])
    for i in jq:
        assert i == 1
        break
    jq.write([5, 6])
    assert list(jq) == [2, 3, 4, 5, 6]
예제 #4
0
def test_multiple_jq_are_independent():
    jq1 = JQ()
    jq2 = JQ()
    with pytest.raises(JQParseError):
        jq1.compile(".}")
    jq3 = JQ()

    jq2.compile(".")
    jq3.compile(".foo")
    jq2.write("foo")
    jq2.write(1)
    jq3.write({"foo": 10})
    assert list(jq2) == ["foo", 1]
    assert list(jq3) == [10]
예제 #5
0
def test_errors_on_incompatible_data_type():
    jq = JQ()
    jq.compile(".foo")
    with pytest.raises(JQError) as excinfo:
        jq.write(1)
    assert "Cannot index number with string" in excinfo.exconly()
예제 #6
0
def test_raises_on_bad_json():
    jq = JQ()
    jq.compile(".")
    with pytest.raises(JQError):
        jq.write_string("{11., ]")
예제 #7
0
def test_can_select_fields():
    jq = JQ()
    jq.compile(".foo")
    r = range(10) + ["foo", "bar"]
    for v in r:
        jq.write({"foo": v})
예제 #8
0
def test_can_pass_multiple_values_through():
    jq = JQ()
    jq.compile(".")
    jq.write(1)
    jq.write(1)
    assert list(jq) == [1, 1]