File: test_dump.py

package info (click to toggle)
python-ijson 3.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 668 kB
  • sloc: python: 2,687; ansic: 1,776; sh: 4; makefile: 3
file content (30 lines) | stat: -rw-r--r-- 1,049 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import os
import subprocess
import sys

import pytest

from tests.test_base import JSON


@pytest.mark.parametrize("multiple_values", (True, False))
@pytest.mark.parametrize("method", ("basic_parse", "parse", "kvitems", "items"))
def test_dump(method, multiple_values):
    # Use python backend to ensure multiple_values works
    env = dict(os.environ)
    env['IJSON_BACKEND'] = 'python'
    # Ensure printing works on the subprocess in Windows
    # by using utf-8 on its stdout
    if sys.platform == 'win32':
        env = dict(os.environ)
        env['PYTHONIOENCODING'] = 'utf-8'
    cmd = [sys.executable, '-m', 'ijson.dump', '-m', method, '-p', '']
    if multiple_values:
        cmd.append('-M')
    proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env)
    input_data = JSON
    if multiple_values:
        input_data += JSON
    out, err = proc.communicate(input_data)
    status = proc.wait()
    assert 0 == status, "out:\n%s\nerr:%s" % (out.decode('utf-8'), err.decode('utf-8'))