defl/tests/test_jq.py

37 lines
1.1 KiB
Python
Raw Normal View History

2025-03-09 09:17:53 -04:00
#!/usr/bin/env python
2025-04-28 14:44:03 -04:00
from collections import Counter
import sys, re, os, enum, itertools, shlex, io
2025-03-09 09:17:53 -04:00
from functools import partial, partialmethod
from time import sleep
2025-04-28 14:44:03 -04:00
from dataclasses import dataclass, field
2025-03-09 09:17:53 -04:00
from operator import itemgetter
2025-04-28 14:44:03 -04:00
from defl import log, cl, Dath, Time, Run, sp, ShQu
2025-03-09 09:17:53 -04:00
from defl._typing_ import *
2025-04-28 14:44:03 -04:00
from defl._typing_ import T, F, N, U
from defl._rich_ import *
2025-03-09 09:17:53 -04:00
from defl._pydantic_ import *
import defl
2025-04-28 14:44:03 -04:00
from pathlib import Path as PLPath
from defl._path._temp_ import TempPath
2025-03-09 09:17:53 -04:00
2025-04-28 14:44:03 -04:00
import pytest
2025-03-09 09:17:53 -04:00
2025-04-28 14:44:03 -04:00
def test_jqDump1():
tmpPath = defl.sp.tmp.makeTemp([], autoRemove=T, create=T, direct=F, ext=N)
with defl.JqDump(tmpPath, append=T) as jq:
for i in range(3):
jq.dump({'a': i})
res = tmpPath.readText()
assert res == '{"a":0}\n{"a":1}\n{"a":2}\n'
2025-03-09 09:17:53 -04:00
2025-04-28 14:44:03 -04:00
def test_jqDump2():
tmpPath = defl.sp.tmp.makeTemp([], autoRemove=T, create=T, direct=F, ext=N)
with defl.JqDump(tmpPath, append=T) as jq:
jq.dump({'a': 'a'})
sleep(0.2) # | flushing to file is async
res = tmpPath.readText()
assert res == '{"a":"a"}\n'